mirror of
https://github.com/neovim/neovim.git
synced 2025-12-04 21:52:41 +00:00
refactor: format test/*
This commit is contained in:
@@ -13,8 +13,12 @@ describe('Folds', function()
|
||||
local tempfname = 'Xtest-fold.txt'
|
||||
|
||||
setup(clear)
|
||||
before_each(function() command('bwipe! | new') end)
|
||||
after_each(function() os.remove(tempfname) end)
|
||||
before_each(function()
|
||||
command('bwipe! | new')
|
||||
end)
|
||||
after_each(function()
|
||||
os.remove(tempfname)
|
||||
end)
|
||||
|
||||
it('manual folding adjusts with filter', function()
|
||||
insert([[
|
||||
@@ -94,7 +98,8 @@ describe('Folds', function()
|
||||
end
|
||||
|
||||
it('neither closes nor corrupts folds', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
@@ -112,7 +117,9 @@ a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '7,12m0')
|
||||
a]],
|
||||
'7,12m0'
|
||||
)
|
||||
expect([[
|
||||
a
|
||||
a
|
||||
@@ -133,7 +140,7 @@ a
|
||||
a
|
||||
a]])
|
||||
-- lines are not closed, folds are correct
|
||||
for i = 1,funcs.line('$') do
|
||||
for i = 1, funcs.line('$') do
|
||||
eq(-1, funcs.foldclosed(i))
|
||||
if i == 1 or i == 7 or i == 13 then
|
||||
eq(0, funcs.foldlevel(i))
|
||||
@@ -151,7 +158,8 @@ a
|
||||
end)
|
||||
|
||||
it("doesn't split a fold when the move is within it", function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
@@ -161,24 +169,30 @@ a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '5m6')
|
||||
eq({0, 1, 1, 2, 2, 2, 2, 1, 1, 0}, get_folds())
|
||||
a]],
|
||||
'5m6'
|
||||
)
|
||||
eq({ 0, 1, 1, 2, 2, 2, 2, 1, 1, 0 }, get_folds())
|
||||
end)
|
||||
|
||||
it('truncates folds that end in the moved range', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '4,5m6')
|
||||
eq({0, 1, 2, 0, 0, 0, 0}, get_folds())
|
||||
a]],
|
||||
'4,5m6'
|
||||
)
|
||||
eq({ 0, 1, 2, 0, 0, 0, 0 }, get_folds())
|
||||
end)
|
||||
|
||||
it('moves folds that start between moved range and destination', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
@@ -191,12 +205,15 @@ a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '3,4m$')
|
||||
eq({0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0}, get_folds())
|
||||
a]],
|
||||
'3,4m$'
|
||||
)
|
||||
eq({ 0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0 }, get_folds())
|
||||
end)
|
||||
|
||||
it('does not affect folds outside changed lines', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
@@ -205,12 +222,15 @@ a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '4m5')
|
||||
eq({1, 1, 1, 0, 0, 0, 1, 1, 1}, get_folds())
|
||||
a]],
|
||||
'4m5'
|
||||
)
|
||||
eq({ 1, 1, 1, 0, 0, 0, 1, 1, 1 }, get_folds())
|
||||
end)
|
||||
|
||||
it('moves and truncates folds that start in moved range', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
@@ -220,34 +240,43 @@ a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '1,3m7')
|
||||
eq({0, 0, 0, 0, 0, 1, 2, 0, 0, 0}, get_folds())
|
||||
a]],
|
||||
'1,3m7'
|
||||
)
|
||||
eq({ 0, 0, 0, 0, 0, 1, 2, 0, 0, 0 }, get_folds())
|
||||
end)
|
||||
|
||||
it('breaks a fold when moving text into it', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '$m4')
|
||||
eq({0, 1, 2, 2, 0, 0, 0}, get_folds())
|
||||
a]],
|
||||
'$m4'
|
||||
)
|
||||
eq({ 0, 1, 2, 2, 0, 0, 0 }, get_folds())
|
||||
end)
|
||||
|
||||
it('adjusts correctly when moving a range backwards', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '2,3m0')
|
||||
eq({1, 2, 0, 0, 0}, get_folds())
|
||||
a]],
|
||||
'2,3m0'
|
||||
)
|
||||
eq({ 1, 2, 0, 0, 0 }, get_folds())
|
||||
end)
|
||||
|
||||
it('handles shifting all remaining folds', function()
|
||||
test_move_indent([[
|
||||
test_move_indent(
|
||||
[[
|
||||
a
|
||||
a
|
||||
a
|
||||
@@ -262,18 +291,23 @@ a]], '2,3m0')
|
||||
a
|
||||
a
|
||||
a
|
||||
a]], '13m7')
|
||||
eq({1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0}, get_folds())
|
||||
a]],
|
||||
'13m7'
|
||||
)
|
||||
eq({ 1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0 }, get_folds())
|
||||
end)
|
||||
end)
|
||||
|
||||
it('updates correctly on :read', function()
|
||||
-- luacheck: ignore 621
|
||||
helpers.write_file(tempfname, [[
|
||||
helpers.write_file(
|
||||
tempfname,
|
||||
[[
|
||||
a
|
||||
|
||||
|
||||
a]])
|
||||
a]]
|
||||
)
|
||||
insert([[
|
||||
a
|
||||
a
|
||||
@@ -295,13 +329,13 @@ a]], '13m7')
|
||||
a
|
||||
a
|
||||
]])
|
||||
for i = 1,2 do
|
||||
for i = 1, 2 do
|
||||
eq(1, funcs.foldlevel(i))
|
||||
end
|
||||
for i = 3,5 do
|
||||
for i = 3, 5 do
|
||||
eq(0, funcs.foldlevel(i))
|
||||
end
|
||||
for i = 6,8 do
|
||||
for i = 6, 8 do
|
||||
eq(1, funcs.foldlevel(i))
|
||||
end
|
||||
end)
|
||||
@@ -356,7 +390,9 @@ a]], '13m7')
|
||||
return 0
|
||||
endfunction
|
||||
]])
|
||||
helpers.write_file(tempfname, [[
|
||||
helpers.write_file(
|
||||
tempfname,
|
||||
[[
|
||||
b
|
||||
b
|
||||
a
|
||||
@@ -364,7 +400,8 @@ a]], '13m7')
|
||||
d
|
||||
a
|
||||
a
|
||||
c]])
|
||||
c]]
|
||||
)
|
||||
insert([[
|
||||
a
|
||||
a
|
||||
@@ -388,7 +425,7 @@ a]], '13m7')
|
||||
|
||||
it('no folds remain if :delete makes buffer empty #19671', function()
|
||||
command('setlocal foldmethod=manual')
|
||||
funcs.setline(1, {'foo', 'bar', 'baz'})
|
||||
funcs.setline(1, { 'foo', 'bar', 'baz' })
|
||||
command('2,3fold')
|
||||
command('%delete')
|
||||
eq(0, funcs.foldlevel(1))
|
||||
|
||||
Reference in New Issue
Block a user