mirror of
https://github.com/neovim/neovim.git
synced 2025-11-10 04:25:22 +00:00
test: Refactor fold tests (#5993)
This commit is contained in:
committed by
Justin M. Keyes
parent
e0705021c1
commit
5ed753044d
@@ -435,6 +435,11 @@ local function expect(contents)
|
|||||||
return eq(dedent(contents), curbuf_contents())
|
return eq(dedent(contents), curbuf_contents())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function expect_any(contents)
|
||||||
|
contents = dedent(contents)
|
||||||
|
return ok(nil ~= string.find(curbuf_contents(), contents, 1, true))
|
||||||
|
end
|
||||||
|
|
||||||
local function do_rmdir(path)
|
local function do_rmdir(path)
|
||||||
if lfs.attributes(path, 'mode') ~= 'directory' then
|
if lfs.attributes(path, 'mode') ~= 'directory' then
|
||||||
return nil
|
return nil
|
||||||
@@ -585,6 +590,7 @@ local M = {
|
|||||||
eq = eq,
|
eq = eq,
|
||||||
neq = neq,
|
neq = neq,
|
||||||
expect = expect,
|
expect = expect,
|
||||||
|
expect_any = expect_any,
|
||||||
ok = ok,
|
ok = ok,
|
||||||
map = map,
|
map = map,
|
||||||
filter = filter,
|
filter = filter,
|
||||||
|
|||||||
@@ -1,13 +1,111 @@
|
|||||||
-- Tests for folding.
|
-- Tests for folding.
|
||||||
|
local Screen = require('test.functional.ui.screen')
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local feed, insert, clear, execute, expect =
|
local feed, insert, execute, expect_any =
|
||||||
helpers.feed, helpers.insert, helpers.clear, helpers.execute, helpers.expect
|
helpers.feed, helpers.insert, helpers.execute, helpers.expect_any
|
||||||
|
|
||||||
describe('folding', function()
|
describe('folding', function()
|
||||||
before_each(clear)
|
local screen
|
||||||
|
|
||||||
it('is working', function()
|
before_each(function()
|
||||||
|
helpers.clear()
|
||||||
|
|
||||||
|
screen = Screen.new(20, 8)
|
||||||
|
screen:attach()
|
||||||
|
end)
|
||||||
|
after_each(function()
|
||||||
|
screen:detach()
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('creation, opening, moving (to the end) and closing', function()
|
||||||
|
insert([[
|
||||||
|
1 aa
|
||||||
|
2 bb
|
||||||
|
3 cc
|
||||||
|
last
|
||||||
|
]])
|
||||||
|
|
||||||
|
-- Basic test if a fold can be created, opened, moving to the end and
|
||||||
|
-- closed.
|
||||||
|
execute('1')
|
||||||
|
feed('zf2j')
|
||||||
|
execute('call append("$", "manual " . getline(foldclosed(".")))')
|
||||||
|
feed('zo')
|
||||||
|
execute('call append("$", foldclosed("."))')
|
||||||
|
feed(']z')
|
||||||
|
execute('call append("$", getline("."))')
|
||||||
|
feed('zc')
|
||||||
|
execute('call append("$", getline(foldclosed(".")))')
|
||||||
|
|
||||||
|
expect_any([[
|
||||||
|
manual 1 aa
|
||||||
|
-1
|
||||||
|
3 cc
|
||||||
|
1 aa]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("foldmethod=marker", function()
|
||||||
|
screen:try_resize(20, 10)
|
||||||
|
insert([[
|
||||||
|
dd {{{
|
||||||
|
ee {{{ }}}
|
||||||
|
ff }}}
|
||||||
|
]])
|
||||||
|
execute('set fdm=marker fdl=1')
|
||||||
|
execute('2')
|
||||||
|
execute('call append("$", "line 2 foldlevel=" . foldlevel("."))')
|
||||||
|
feed('[z')
|
||||||
|
execute('call append("$", foldlevel("."))')
|
||||||
|
feed('jo{{ <esc>r{jj') -- writes '{{{' and moves 2 lines bot
|
||||||
|
execute('call append("$", foldlevel("."))')
|
||||||
|
feed('kYpj')
|
||||||
|
execute('call append("$", foldlevel("."))')
|
||||||
|
|
||||||
|
helpers.wait()
|
||||||
|
screen:expect([[
|
||||||
|
dd {{{ |
|
||||||
|
ee {{{ }}} |
|
||||||
|
{{{ |
|
||||||
|
ff }}} |
|
||||||
|
ff }}} |
|
||||||
|
^ |
|
||||||
|
line 2 foldlevel=2 |
|
||||||
|
1 |
|
||||||
|
1 |
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("foldmethod=indent", function()
|
||||||
|
screen:try_resize(20, 8)
|
||||||
|
execute('set fdm=indent sw=2')
|
||||||
|
insert([[
|
||||||
|
aa
|
||||||
|
bb
|
||||||
|
cc
|
||||||
|
last
|
||||||
|
]])
|
||||||
|
execute('call append("$", "foldlevel line3=" . foldlevel(3))')
|
||||||
|
execute('call append("$", foldlevel(2))')
|
||||||
|
feed('zR')
|
||||||
|
|
||||||
|
helpers.wait()
|
||||||
|
screen:expect([[
|
||||||
|
aa |
|
||||||
|
bb |
|
||||||
|
cc |
|
||||||
|
last |
|
||||||
|
^ |
|
||||||
|
foldlevel line3=2 |
|
||||||
|
1 |
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("foldmethod=syntax", function()
|
||||||
|
screen:try_resize(35, 15)
|
||||||
insert([[
|
insert([[
|
||||||
1 aa
|
1 aa
|
||||||
2 bb
|
2 bb
|
||||||
@@ -21,36 +119,6 @@ describe('folding', function()
|
|||||||
a jj
|
a jj
|
||||||
b kk
|
b kk
|
||||||
last]])
|
last]])
|
||||||
|
|
||||||
-- Basic test if a fold can be created, opened, moving to the end and
|
|
||||||
-- closed.
|
|
||||||
execute('/^1')
|
|
||||||
feed('zf2j')
|
|
||||||
execute('call append("$", "manual " . getline(foldclosed(".")))')
|
|
||||||
feed('zo')
|
|
||||||
execute('call append("$", foldclosed("."))')
|
|
||||||
feed(']z')
|
|
||||||
execute('call append("$", getline("."))')
|
|
||||||
feed('zc')
|
|
||||||
execute('call append("$", getline(foldclosed(".")))')
|
|
||||||
-- Test folding with markers.
|
|
||||||
execute('set fdm=marker fdl=1 fdc=3')
|
|
||||||
execute('/^5')
|
|
||||||
execute('call append("$", "marker " . foldlevel("."))')
|
|
||||||
feed('[z')
|
|
||||||
execute('call append("$", foldlevel("."))')
|
|
||||||
feed('jo{{ <esc>r{jj')
|
|
||||||
execute('call append("$", foldlevel("."))')
|
|
||||||
feed('kYpj')
|
|
||||||
execute('call append("$", foldlevel("."))')
|
|
||||||
-- Test folding with indent.
|
|
||||||
execute('set fdm=indent sw=2')
|
|
||||||
execute('/^2 b')
|
|
||||||
feed('i <esc>jI <esc>')
|
|
||||||
execute('call append("$", "indent " . foldlevel("."))')
|
|
||||||
feed('k')
|
|
||||||
execute('call append("$", foldlevel("."))')
|
|
||||||
-- Test syntax folding.
|
|
||||||
execute('set fdm=syntax fdl=0')
|
execute('set fdm=syntax fdl=0')
|
||||||
execute('syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3')
|
execute('syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3')
|
||||||
execute('syn region Fd1 start="ee" end="ff" fold contained')
|
execute('syn region Fd1 start="ee" end="ff" fold contained')
|
||||||
@@ -65,22 +133,46 @@ describe('folding', function()
|
|||||||
feed('3j')
|
feed('3j')
|
||||||
execute('call append("$", getline("."))')
|
execute('call append("$", getline("."))')
|
||||||
execute('set fdl=0')
|
execute('set fdl=0')
|
||||||
feed('zO<C-L>j')
|
feed('zO<C-L>j') -- <C-L> redraws screen
|
||||||
execute('call append("$", getline("."))')
|
execute('call append("$", getline("."))')
|
||||||
-- Test expression folding.
|
execute('set fdl=0')
|
||||||
execute('fun Flvl()')
|
expect_any([[
|
||||||
execute(' let l = getline(v:lnum)')
|
folding 9 ii
|
||||||
execute(' if l =~ "bb$"')
|
3 cc
|
||||||
execute(' return 2')
|
9 ii
|
||||||
execute(' elseif l =~ "gg$"')
|
a jj]])
|
||||||
execute(' return "s1"')
|
end)
|
||||||
execute(' elseif l =~ "ii$"')
|
|
||||||
execute(' return ">2"')
|
it("foldmethod=expression", function()
|
||||||
execute(' elseif l =~ "kk$"')
|
insert([[
|
||||||
execute(' return "0"')
|
1 aa
|
||||||
execute(' endif')
|
2 bb
|
||||||
execute(' return "="')
|
3 cc
|
||||||
execute('endfun')
|
4 dd {{{
|
||||||
|
5 ee {{{ }}}
|
||||||
|
6 ff }}}
|
||||||
|
7 gg
|
||||||
|
8 hh
|
||||||
|
9 ii
|
||||||
|
a jj
|
||||||
|
b kk
|
||||||
|
last ]])
|
||||||
|
|
||||||
|
execute([[
|
||||||
|
fun Flvl()
|
||||||
|
let l = getline(v:lnum)
|
||||||
|
if l =~ "bb$"
|
||||||
|
return 2
|
||||||
|
elseif l =~ "gg$"
|
||||||
|
return "s1"
|
||||||
|
elseif l =~ "ii$"
|
||||||
|
return ">2"
|
||||||
|
elseif l =~ "kk$"
|
||||||
|
return "0"
|
||||||
|
endif
|
||||||
|
return "="
|
||||||
|
endfun
|
||||||
|
]])
|
||||||
execute('set fdm=expr fde=Flvl()')
|
execute('set fdm=expr fde=Flvl()')
|
||||||
execute('/bb$')
|
execute('/bb$')
|
||||||
execute('call append("$", "expr " . foldlevel("."))')
|
execute('call append("$", "expr " . foldlevel("."))')
|
||||||
@@ -90,46 +182,31 @@ describe('folding', function()
|
|||||||
execute('call append("$", foldlevel("."))')
|
execute('call append("$", foldlevel("."))')
|
||||||
execute('/kk$')
|
execute('/kk$')
|
||||||
execute('call append("$", foldlevel("."))')
|
execute('call append("$", foldlevel("."))')
|
||||||
execute('0,/^last/delete')
|
|
||||||
execute('delfun Flvl')
|
|
||||||
|
|
||||||
-- Assert buffer contents.
|
expect_any([[
|
||||||
expect([[
|
|
||||||
manual 1 aa
|
|
||||||
-1
|
|
||||||
3 cc
|
|
||||||
1 aa
|
|
||||||
marker 2
|
|
||||||
1
|
|
||||||
1
|
|
||||||
0
|
|
||||||
indent 2
|
|
||||||
1
|
|
||||||
folding 9 ii
|
|
||||||
3 cc
|
|
||||||
7 gg
|
|
||||||
8 hh
|
|
||||||
expr 2
|
expr 2
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
0]])
|
0]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can open after :move', function()
|
it('can be opened after :move', function()
|
||||||
|
-- luacheck: ignore
|
||||||
|
screen:try_resize(35, 8)
|
||||||
insert([[
|
insert([[
|
||||||
Test fdm=indent and :move bug END
|
Test fdm=indent and :move bug END
|
||||||
line2
|
line2
|
||||||
Test fdm=indent START
|
Test fdm=indent START
|
||||||
line3
|
line3
|
||||||
line4]])
|
line4]])
|
||||||
|
|
||||||
execute('set noai nosta ')
|
execute('set noai nosta ')
|
||||||
execute('set fdm=indent')
|
execute('set fdm=indent')
|
||||||
execute('1m1')
|
execute('1m1')
|
||||||
feed('2jzc')
|
feed('2jzc')
|
||||||
execute('m0')
|
execute('m0')
|
||||||
|
feed('zR')
|
||||||
|
|
||||||
expect([[
|
expect_any([[
|
||||||
Test fdm=indent START
|
Test fdm=indent START
|
||||||
line3
|
line3
|
||||||
line4
|
line4
|
||||||
@@ -137,3 +214,4 @@ describe('folding', function()
|
|||||||
line2]])
|
line2]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user