tests/indent: move the run helper functions to top-level

This commit is contained in:
Jędrzej Boczar 2021-04-22 21:23:24 +02:00 committed by Kiyan
parent 63a88c873f
commit db97170e4e
5 changed files with 38 additions and 37 deletions

View file

@ -9,6 +9,13 @@ local opts = {
expandtab = true,
}
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/c/' .. file, spec, opts)
end)
end
describe('indent C:', function()
describe('whole file:', function()
local files = scan_dir('tests/indent/c');
@ -20,13 +27,6 @@ describe('indent C:', function()
end)
describe('new line:', function()
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/c/' .. file, spec, opts)
end)
end
run('array.c', { on_line = 2, text = '0,', indent = 4 })
run('cond.c', { on_line = 3, text = 'x++;', indent = 8 })
run('cond.c', { on_line = 8, text = 'x++;', indent = 8 })

View file

@ -15,10 +15,18 @@ local get_name = function(file)
return Path:new(file):make_relative('tests/indent')
end
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', get_name(file), title), function()
new_line(file, spec, opts)
end)
end
describe('indent C++:', function()
describe('whole file:', function()
local files = scan_dir('tests/indent/c');
vim.list_extend(files, scan_dir('tests/indent/cpp'))
local files = vim.tbl_flatten(vim.tbl_map(scan_dir, {
'tests/indent/c', 'tests/indent/cpp',
}))
for _, file in ipairs(files) do
it(get_name(file), function()
@ -28,13 +36,6 @@ describe('indent C++:', function()
end)
describe('new line:', function()
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', get_name(file), title), function()
new_line(file, spec, opts)
end)
end
run('tests/indent/cpp/access.cpp', { on_line = 3, text = 'protected:', indent = 0 })
run('tests/indent/cpp/class.cpp', { on_line = 2, text = 'using T = int;', indent = 4 })
run('tests/indent/cpp/stream.cpp', { on_line = 5, text = '<< x + 3', indent = 8 })

View file

@ -9,6 +9,13 @@ local opts = {
expandtab = true,
}
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/lua/' .. file, spec, opts)
end)
end
describe('indent Lua:', function()
describe('whole file:', function()
local files = scan_dir('tests/indent/lua');
@ -20,13 +27,6 @@ describe('indent Lua:', function()
end)
describe('new line:', function()
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/lua/' .. file, spec, opts)
end)
end
run('comment.lua', { on_line = 1, text = 'line', indent = '-- ' })
run('comment.lua', { on_line = 5, text = 'multiline', indent = ' ' })
run('func.lua', { on_line = 1, text = 'x = x + 1', indent = 2 })

View file

@ -9,6 +9,13 @@ local opts = {
expandtab = true,
}
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/python/' .. file, spec, opts)
end)
end
describe('indent Python:', function()
describe('whole file:', function()
local files = scan_dir('tests/indent/python');
@ -20,13 +27,6 @@ describe('indent Python:', function()
end)
describe('new line:', function()
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/python/' .. file, spec, opts)
end)
end
run('aligned_indent.py', { on_line = 1, text = 'arg3,', indent = 19 })
run('basic_blocks.py', { on_line = 1, text = 'wait,', indent = 4 })
run('basic_blocks.py', { on_line = 6, text = 'x += 1', indent = 4 })

View file

@ -9,6 +9,13 @@ local opts = {
expandtab = true,
}
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/rust/' .. file, spec, opts)
end)
end
describe('indent Rust:', function()
describe('whole file:', function()
local files = scan_dir('tests/indent/rust');
@ -20,13 +27,6 @@ describe('indent Rust:', function()
end)
describe('new line:', function()
local run = function(file, spec, title)
title = title and title or tostring(spec.on_line)
it(string.format('%s[%s]', file, title), function()
new_line('tests/indent/rust/' .. file, spec, opts)
end)
end
run('array.rs', { on_line = 2, text = '0,', indent = 4 })
run('array.rs', { on_line = 8, text = '0,', indent = 8 })
run('comment.rs', { on_line = 3, text = 'a', indent = '/// ' })