mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
move all tests to top-level tests/ directory
This commit is contained in:
parent
d4e8d3e659
commit
63a88c873f
56 changed files with 72 additions and 72 deletions
14
tests/indent/c/array.c
Normal file
14
tests/indent/c/array.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
int x[] = {
|
||||
1, 2, 3,
|
||||
4, 5,
|
||||
6
|
||||
};
|
||||
|
||||
int y[][2] = {
|
||||
{0, 1},
|
||||
{1, 2},
|
||||
{
|
||||
2,
|
||||
3
|
||||
},
|
||||
};
|
||||
8
tests/indent/c/comment.c
Normal file
8
tests/indent/c/comment.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/**
|
||||
* Function foo
|
||||
* @param[out] x output
|
||||
* @param[in] x input
|
||||
*/
|
||||
void foo(int *x, int y) {
|
||||
*x = y;
|
||||
}
|
||||
10
tests/indent/c/cond.c
Normal file
10
tests/indent/c/cond.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
void foo(int x)
|
||||
{
|
||||
if (x > 10) {
|
||||
return;
|
||||
} else if (x < -10) {
|
||||
x = -10;
|
||||
} else {
|
||||
x = -x;
|
||||
}
|
||||
}
|
||||
5
tests/indent/c/enum.c
Normal file
5
tests/indent/c/enum.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
enum foo {
|
||||
A = 1,
|
||||
B,
|
||||
C,
|
||||
};
|
||||
12
tests/indent/c/expr.c
Normal file
12
tests/indent/c/expr.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
void foo(int x, int y)
|
||||
{
|
||||
if ((x*x - y*y > 0) ||
|
||||
(x == 1 || y == 1) &&
|
||||
(x != 2 && y != 2)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
int z = (x + y) *
|
||||
(x - y);
|
||||
}
|
||||
33
tests/indent/c/func.c
Normal file
33
tests/indent/c/func.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
int f1(int x) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int f2(int x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int f3(
|
||||
int x
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int f4(
|
||||
int x,
|
||||
int y
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int f5(int x,
|
||||
int y)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
f6(int x, int y)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
7
tests/indent/c/label.c
Normal file
7
tests/indent/c/label.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
int foo(int x)
|
||||
{
|
||||
goto error;
|
||||
return 0;
|
||||
error:
|
||||
return 1;
|
||||
}
|
||||
16
tests/indent/c/loop.c
Normal file
16
tests/indent/c/loop.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
void foo(int x)
|
||||
{
|
||||
while (x > 0) {
|
||||
x--;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
x++;
|
||||
break;
|
||||
}
|
||||
|
||||
do {
|
||||
x++;
|
||||
} while (x < 0);
|
||||
}
|
||||
12
tests/indent/c/no_braces.c
Normal file
12
tests/indent/c/no_braces.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
int foo(int x) {
|
||||
if (x > 10)
|
||||
return 10;
|
||||
else
|
||||
return x;
|
||||
|
||||
while (1)
|
||||
x++;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
x--;
|
||||
}
|
||||
10
tests/indent/c/preproc_cond.c
Normal file
10
tests/indent/c/preproc_cond.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
void foo(int x)
|
||||
{
|
||||
x = x + 1;
|
||||
#if 1
|
||||
x = x + 2;
|
||||
#else
|
||||
x = x + 3;
|
||||
#endif
|
||||
x = x + 4;
|
||||
}
|
||||
9
tests/indent/c/preproc_func.c
Normal file
9
tests/indent/c/preproc_func.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#define FOO(x) do { \
|
||||
x = x + 1; \
|
||||
x = x / 2; \
|
||||
} while (x > 0);
|
||||
|
||||
void foo(int x)
|
||||
{
|
||||
FOO(x);
|
||||
}
|
||||
5
tests/indent/c/string.c
Normal file
5
tests/indent/c/string.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const char *a = "hello \
|
||||
world";
|
||||
|
||||
const char *b = "hello "
|
||||
"world";
|
||||
11
tests/indent/c/struct.c
Normal file
11
tests/indent/c/struct.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
struct foo {
|
||||
int a;
|
||||
struct bar {
|
||||
int x;
|
||||
} b;
|
||||
};
|
||||
|
||||
union baz {
|
||||
struct foo;
|
||||
int x;
|
||||
};
|
||||
16
tests/indent/c/switch.c
Normal file
16
tests/indent/c/switch.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
void foo(int x) {
|
||||
switch (x) {
|
||||
case 1:
|
||||
x += 1;
|
||||
break;
|
||||
case 2: x += 2;
|
||||
break;
|
||||
case 3: x += 3; break;
|
||||
case 4: {
|
||||
x += 4;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
x = -x;
|
||||
}
|
||||
}
|
||||
6
tests/indent/c/ternary.c
Normal file
6
tests/indent/c/ternary.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
void foo(int x)
|
||||
{
|
||||
int y = (x > 10) ? 10
|
||||
: (x < -10) ? -10
|
||||
: x;
|
||||
}
|
||||
49
tests/indent/c_spec.lua
Normal file
49
tests/indent/c_spec.lua
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
local whole_file = require('nvim-treesitter.test_utils').indent_whole_file
|
||||
local new_line = require('nvim-treesitter.test_utils').indent_new_line
|
||||
local scan_dir = require('plenary.scandir').scan_dir
|
||||
|
||||
local opts = {
|
||||
tabstop = 4,
|
||||
shiftwidth = 4,
|
||||
softtabstop = 0,
|
||||
expandtab = true,
|
||||
}
|
||||
|
||||
describe('indent C:', function()
|
||||
describe('whole file:', function()
|
||||
local files = scan_dir('tests/indent/c');
|
||||
for _, file in ipairs(files) do
|
||||
it(vim.fn.fnamemodify(file, ':t'), function()
|
||||
whole_file(file, opts)
|
||||
end)
|
||||
end
|
||||
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 })
|
||||
run('expr.c', { on_line = 10, text = '2 *', indent = 8 })
|
||||
run('func.c', { on_line = 17, text = 'int z,', indent = 4 })
|
||||
run('label.c', { on_line = 3, text = 'normal:', indent = 0 })
|
||||
run('loop.c', { on_line = 3, text = 'x++;', indent = 8 })
|
||||
run('preproc_cond.c', { on_line = 5, text = 'x++;', indent = 4 })
|
||||
run('preproc_func.c', { on_line = 3, text = 'x++; \\', indent = 8 })
|
||||
run('string.c', { on_line = 1, text = 'brave new \\', indent = 0 })
|
||||
run('string.c', { on_line = 4, text = '"brave new "', indent = 4 })
|
||||
run('struct.c', { on_line = 4, text = 'int y;', indent = 8 })
|
||||
run('switch.c', { on_line = 3, text = 'x++;', indent = 12 })
|
||||
run('ternary.c', { on_line = 4, text = ': (x == 0) : 0', indent = 8 })
|
||||
-- the line after inserted one will be left with wrong indent but we only care about the inserted one
|
||||
run('no_braces.c', { on_line = 4, text = 'x++;', indent = 8 })
|
||||
run('no_braces.c', { on_line = 7, text = 'x++;', indent = 8 })
|
||||
run('no_braces.c', { on_line = 10, text = 'x++;', indent = 8 })
|
||||
end)
|
||||
end)
|
||||
6
tests/indent/cpp/access.cpp
Normal file
6
tests/indent/cpp/access.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class Foo {
|
||||
public:
|
||||
int x;
|
||||
private:
|
||||
int y;
|
||||
};
|
||||
7
tests/indent/cpp/class.cpp
Normal file
7
tests/indent/cpp/class.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Foo {
|
||||
int x;
|
||||
class Bar {
|
||||
int y;
|
||||
};
|
||||
Bar z;
|
||||
};
|
||||
7
tests/indent/cpp/stream.cpp
Normal file
7
tests/indent/cpp/stream.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <iostream>
|
||||
|
||||
void foo(int x) {
|
||||
std::cout << x
|
||||
<< x + 1
|
||||
<< x + 2;
|
||||
}
|
||||
62
tests/indent/cpp_spec.lua
Normal file
62
tests/indent/cpp_spec.lua
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
local whole_file = require('nvim-treesitter.test_utils').indent_whole_file
|
||||
local new_line = require('nvim-treesitter.test_utils').indent_new_line
|
||||
local scan_dir = require('plenary.scandir').scan_dir
|
||||
local Path = require('plenary.path')
|
||||
|
||||
local opts = {
|
||||
tabstop = 4,
|
||||
shiftwidth = 4,
|
||||
softtabstop = 0,
|
||||
expandtab = true,
|
||||
filetype = 'cpp',
|
||||
}
|
||||
|
||||
local get_name = function(file)
|
||||
return Path:new(file):make_relative('tests/indent')
|
||||
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'))
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
it(get_name(file), function()
|
||||
whole_file(file, opts)
|
||||
end)
|
||||
end
|
||||
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 })
|
||||
|
||||
-- TODO: find a clean way to import these from c_spec.lua
|
||||
run('tests/indent/c/array.c', { on_line = 2, text = '0,', indent = 4 })
|
||||
run('tests/indent/c/cond.c', { on_line = 3, text = 'x++;', indent = 8 })
|
||||
run('tests/indent/c/cond.c', { on_line = 8, text = 'x++;', indent = 8 })
|
||||
run('tests/indent/c/expr.c', { on_line = 10, text = '2 *', indent = 8 })
|
||||
run('tests/indent/c/func.c', { on_line = 17, text = 'int z,', indent = 4 })
|
||||
run('tests/indent/c/label.c', { on_line = 3, text = 'normal:', indent = 0 })
|
||||
run('tests/indent/c/loop.c', { on_line = 3, text = 'x++;', indent = 8 })
|
||||
run('tests/indent/c/preproc_cond.c', { on_line = 5, text = 'x++;', indent = 4 })
|
||||
run('tests/indent/c/preproc_func.c', { on_line = 3, text = 'x++; \\', indent = 8 })
|
||||
run('tests/indent/c/string.c', { on_line = 1, text = 'brave new \\', indent = 0 })
|
||||
run('tests/indent/c/string.c', { on_line = 4, text = '"brave new "', indent = 4 })
|
||||
run('tests/indent/c/struct.c', { on_line = 4, text = 'int y;', indent = 8 })
|
||||
run('tests/indent/c/switch.c', { on_line = 3, text = 'x++;', indent = 12 })
|
||||
run('tests/indent/c/ternary.c', { on_line = 4, text = ': (x == 0) : 0', indent = 8 })
|
||||
-- the line after inserted one will be left with wrong indent but we only care about the inserted one
|
||||
run('tests/indent/c/no_braces.c', { on_line = 4, text = 'x++;', indent = 8 })
|
||||
run('tests/indent/c/no_braces.c', { on_line = 7, text = 'x++;', indent = 8 })
|
||||
run('tests/indent/c/no_braces.c', { on_line = 10, text = 'x++;', indent = 8 })
|
||||
end)
|
||||
end)
|
||||
7
tests/indent/lua/comment.lua
Normal file
7
tests/indent/lua/comment.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
-- some
|
||||
-- comment
|
||||
|
||||
--[[
|
||||
another
|
||||
comment
|
||||
--]]
|
||||
12
tests/indent/lua/cond.lua
Normal file
12
tests/indent/lua/cond.lua
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
local x = 10
|
||||
|
||||
if x > 3 then
|
||||
x = 3
|
||||
elseif x < 3 then
|
||||
x = -3
|
||||
else
|
||||
if x > 0 then
|
||||
x = 1
|
||||
end
|
||||
x = 0
|
||||
end
|
||||
9
tests/indent/lua/func.lua
Normal file
9
tests/indent/lua/func.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function foo(x)
|
||||
local bar = function(a, b, c)
|
||||
return a + b + c
|
||||
end
|
||||
return bar(
|
||||
x,
|
||||
1,
|
||||
2)
|
||||
end
|
||||
14
tests/indent/lua/loop.lua
Normal file
14
tests/indent/lua/loop.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
local x = 1
|
||||
|
||||
while x < 10 do
|
||||
x = x + 1
|
||||
break
|
||||
end
|
||||
|
||||
for i = 1,3 do
|
||||
x = x + i
|
||||
end
|
||||
|
||||
repeat
|
||||
x = x + 1
|
||||
until x > 100
|
||||
5
tests/indent/lua/string.lua
Normal file
5
tests/indent/lua/string.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
local s = [[
|
||||
a
|
||||
multiline
|
||||
string
|
||||
]]
|
||||
10
tests/indent/lua/table.lua
Normal file
10
tests/indent/lua/table.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
local a = {
|
||||
x = 1,
|
||||
y = 2,
|
||||
z = {
|
||||
1, 2, 3,
|
||||
},
|
||||
['hello world'] = {
|
||||
1, 2, 3
|
||||
}
|
||||
}
|
||||
48
tests/indent/lua_spec.lua
Normal file
48
tests/indent/lua_spec.lua
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
local whole_file = require('nvim-treesitter.test_utils').indent_whole_file
|
||||
local new_line = require('nvim-treesitter.test_utils').indent_new_line
|
||||
local scan_dir = require('plenary.scandir').scan_dir
|
||||
|
||||
local opts = {
|
||||
tabstop = 2,
|
||||
shiftwidth = 2,
|
||||
softtabstop = 0,
|
||||
expandtab = true,
|
||||
}
|
||||
|
||||
describe('indent Lua:', function()
|
||||
describe('whole file:', function()
|
||||
local files = scan_dir('tests/indent/lua');
|
||||
for _, file in ipairs(files) do
|
||||
it(vim.fn.fnamemodify(file, ':t'), function()
|
||||
whole_file(file, opts)
|
||||
end)
|
||||
end
|
||||
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 })
|
||||
run('func.lua', { on_line = 2, text = 'y = y + 1', indent = 4 })
|
||||
run('func.lua', { on_line = 5, text = '3,', indent = 4 })
|
||||
run('string.lua', { on_line = 1, text = 'x', indent = 0 })
|
||||
run('string.lua', { on_line = 2, text = 'x', indent = 0 })
|
||||
run('string.lua', { on_line = 3, text = 'x', indent = 2 })
|
||||
run('string.lua', { on_line = 4, text = 'x', indent = 4 })
|
||||
run('table.lua', { on_line = 1, text = 'b = 0,', indent = 2 })
|
||||
run('table.lua', { on_line = 5, text = '4,', indent = 4 })
|
||||
run('table.lua', { on_line = 7, text = '4,', indent = 4 })
|
||||
run('loop.lua', { on_line = 4, text = 'x = x + 1', indent = 2 })
|
||||
run('cond.lua', { on_line = 5, text = 'x = x + 1', indent = 2 })
|
||||
run('cond.lua', { on_line = 7, text = 'x = x + 1', indent = 2 })
|
||||
run('cond.lua', { on_line = 8, text = 'x = x + 1', indent = 4 })
|
||||
end)
|
||||
end)
|
||||
|
||||
11
tests/indent/python/aligned_indent.py
Normal file
11
tests/indent/python/aligned_indent.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def aligned_indent(arg1,
|
||||
arg2):
|
||||
pass
|
||||
|
||||
aligned_indent(1,
|
||||
2)
|
||||
|
||||
|
||||
aligned_indent(1,
|
||||
2
|
||||
)
|
||||
14
tests/indent/python/basic_blocks.py
Normal file
14
tests/indent/python/basic_blocks.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from os import (
|
||||
path,
|
||||
name as OsName
|
||||
)
|
||||
|
||||
def foo(x):
|
||||
pass
|
||||
|
||||
class Foo:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def foo(self):
|
||||
pass
|
||||
23
tests/indent/python/basic_collections.py
Normal file
23
tests/indent/python/basic_collections.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# list
|
||||
a = [
|
||||
1, 2,
|
||||
3
|
||||
]
|
||||
|
||||
# set
|
||||
b = {
|
||||
3,
|
||||
4,
|
||||
}
|
||||
|
||||
# dict
|
||||
c = {
|
||||
'a': 'b',
|
||||
'c': 1,
|
||||
}
|
||||
|
||||
# tuple
|
||||
d = (
|
||||
1,
|
||||
2,
|
||||
)
|
||||
27
tests/indent/python/branches.py
Normal file
27
tests/indent/python/branches.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
a = [
|
||||
1, 2, 3]
|
||||
|
||||
b = [
|
||||
x + 1
|
||||
for x in range(3)]
|
||||
|
||||
c = [[[
|
||||
1
|
||||
]]]
|
||||
|
||||
d = [[[
|
||||
4]]]
|
||||
|
||||
e = [[
|
||||
1], 2, 3]
|
||||
|
||||
def foo(x, y):
|
||||
pass
|
||||
|
||||
foo(
|
||||
a,
|
||||
b)
|
||||
|
||||
if (a and
|
||||
b):
|
||||
pass
|
||||
25
tests/indent/python/comprehensions.py
Normal file
25
tests/indent/python/comprehensions.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# list
|
||||
a = [
|
||||
x + 1 for x in range(3)
|
||||
]
|
||||
|
||||
# dict
|
||||
b = {
|
||||
x: x + 1 for x in range(3)
|
||||
}
|
||||
|
||||
# generator
|
||||
c = (
|
||||
x * x for x in range(3)
|
||||
)
|
||||
|
||||
# set
|
||||
d = {
|
||||
x + x for x in range(3)
|
||||
}
|
||||
|
||||
# other styles
|
||||
e = [
|
||||
x + 1 for x
|
||||
in range(3)
|
||||
]
|
||||
22
tests/indent/python/control_flow.py
Normal file
22
tests/indent/python/control_flow.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
if a == a:
|
||||
x = 1
|
||||
elif b:
|
||||
x = 2
|
||||
else:
|
||||
x = 3
|
||||
|
||||
while False:
|
||||
pass
|
||||
|
||||
for _ in range(3):
|
||||
pass
|
||||
|
||||
with open('/tmp/f', 'w') as f:
|
||||
pass
|
||||
|
||||
try:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
pass
|
||||
6
tests/indent/python/hanging_indent.py
Normal file
6
tests/indent/python/hanging_indent.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def hanging_indent(
|
||||
arg1, arg2):
|
||||
pass
|
||||
|
||||
hanging_indent(
|
||||
1, 2)
|
||||
8
tests/indent/python/join_lines.py
Normal file
8
tests/indent/python/join_lines.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
a = 2 \
|
||||
+ 2
|
||||
|
||||
b = 'hello' \
|
||||
'world'
|
||||
|
||||
c = lambda x: \
|
||||
x + 3
|
||||
41
tests/indent/python/nested_collections.py
Normal file
41
tests/indent/python/nested_collections.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
a = [
|
||||
1,
|
||||
[
|
||||
2,
|
||||
[
|
||||
3
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
b = [
|
||||
1, [[
|
||||
3
|
||||
],
|
||||
]
|
||||
]
|
||||
|
||||
c = [[[
|
||||
3
|
||||
]]]
|
||||
|
||||
d = {
|
||||
'a': [
|
||||
2, 3
|
||||
],
|
||||
'c': (
|
||||
[1, 2, 3],
|
||||
[
|
||||
2,
|
||||
4
|
||||
], {
|
||||
6,
|
||||
8
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
e = (1, 2,
|
||||
3, 4,
|
||||
5, 6
|
||||
)
|
||||
17
tests/indent/python/strings.py
Normal file
17
tests/indent/python/strings.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
a = """
|
||||
String A
|
||||
"""
|
||||
|
||||
b = """
|
||||
String B
|
||||
"""
|
||||
|
||||
c = """
|
||||
String C
|
||||
"""
|
||||
|
||||
d = """
|
||||
String D
|
||||
String D
|
||||
String D
|
||||
"""
|
||||
52
tests/indent/python_spec.lua
Normal file
52
tests/indent/python_spec.lua
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
local whole_file = require('nvim-treesitter.test_utils').indent_whole_file
|
||||
local new_line = require('nvim-treesitter.test_utils').indent_new_line
|
||||
local scan_dir = require('plenary.scandir').scan_dir
|
||||
|
||||
local opts = {
|
||||
tabstop = 4,
|
||||
shiftwidth = 4,
|
||||
softtabstop = 0,
|
||||
expandtab = true,
|
||||
}
|
||||
|
||||
describe('indent Python:', function()
|
||||
describe('whole file:', function()
|
||||
local files = scan_dir('tests/indent/python');
|
||||
for _, file in ipairs(files) do
|
||||
it(vim.fn.fnamemodify(file, ':t'), function()
|
||||
whole_file(file, opts)
|
||||
end)
|
||||
end
|
||||
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 })
|
||||
run('basic_blocks.py', { on_line = 10, text = 'x += 1', indent = 8 })
|
||||
run('basic_blocks.py', { on_line = 7, text = 'x += 1', indent = 4 }, '7, after last line of a block')
|
||||
run('basic_blocks.py', { on_line = 11, text = 'x += 1', indent = 8 }, '11, after last line of a block')
|
||||
run('basic_collections.py', { on_line = 3, text = '4,', indent = 4 })
|
||||
run('comprehensions.py', { on_line = 8, text = 'if x != 2', indent = 4 })
|
||||
run('control_flow.py', { on_line = 23, text = 'x = 4', indent = 4 })
|
||||
run('hanging_indent.py', { on_line = 1, text = 'arg0,', indent = 8 })
|
||||
run('hanging_indent.py', { on_line = 5, text = '0,', indent = 4 })
|
||||
run('join_lines.py', { on_line = 1, text = '+ 1 \\', indent = 4 })
|
||||
run('join_lines.py', { on_line = 4, text = '+ 1 \\', indent = 4 })
|
||||
run('join_lines.py', { on_line = 7, text = '+ 1 \\', indent = 4 })
|
||||
run('nested_collections.py', { on_line = 5, text = '0,', indent = 12 })
|
||||
run('nested_collections.py', { on_line = 6, text = ',0', indent = 12 })
|
||||
run('nested_collections.py', { on_line = 29, text = '[1, 2],', indent = 12 })
|
||||
run('nested_collections.py', { on_line = 39, text = '0,', indent = 5 })
|
||||
run('strings.py', { on_line = 14, text = 'x', indent = 4 })
|
||||
run('strings.py', { on_line = 15, text = 'x', indent = 0 })
|
||||
run('strings.py', { on_line = 16, text = 'x', indent = 8 })
|
||||
end)
|
||||
end)
|
||||
11
tests/indent/rust/array.rs
Normal file
11
tests/indent/rust/array.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
const X: [i32; 2] = [
|
||||
1,
|
||||
2,
|
||||
];
|
||||
|
||||
fn foo() {
|
||||
let _x = [
|
||||
1,
|
||||
2,
|
||||
];
|
||||
}
|
||||
7
tests/indent/rust/comment.rs
Normal file
7
tests/indent/rust/comment.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/// Function foo
|
||||
///
|
||||
/// Description of
|
||||
/// function foo.
|
||||
fn foo(x: i32, y: i32) -> i32 {
|
||||
x + y
|
||||
}
|
||||
17
tests/indent/rust/cond.rs
Normal file
17
tests/indent/rust/cond.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
fn foo(mut x: i32) -> i32 {
|
||||
if x > 10 {
|
||||
return 10;
|
||||
} else if x == 10 {
|
||||
return 9;
|
||||
} else {
|
||||
x += 10;
|
||||
}
|
||||
|
||||
if x < 0 {
|
||||
if x == -1 {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
11
tests/indent/rust/enum.rs
Normal file
11
tests/indent/rust/enum.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
enum Foo {
|
||||
X,
|
||||
Y(
|
||||
char,
|
||||
char,
|
||||
),
|
||||
Z {
|
||||
x: u32,
|
||||
y: u32,
|
||||
},
|
||||
}
|
||||
10
tests/indent/rust/func.rs
Normal file
10
tests/indent/rust/func.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fn foo() -> i32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn foo(
|
||||
x: i32,
|
||||
y: i32
|
||||
) -> i32 {
|
||||
x + y
|
||||
}
|
||||
7
tests/indent/rust/impl.rs
Normal file
7
tests/indent/rust/impl.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
fn foo() -> i32 {
|
||||
1
|
||||
}
|
||||
}
|
||||
19
tests/indent/rust/loop.rs
Normal file
19
tests/indent/rust/loop.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
fn foo(mut x: i32) {
|
||||
while x > 0 {
|
||||
x -= 1;
|
||||
}
|
||||
|
||||
for i in 0..3 {
|
||||
x += 1;
|
||||
}
|
||||
|
||||
loop {
|
||||
x += 1;
|
||||
|
||||
if x < 100 {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
13
tests/indent/rust/macro.rs
Normal file
13
tests/indent/rust/macro.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
macro_rules! foo {
|
||||
($a:ident, $b:ident, $c:ident) => {
|
||||
struct $a;
|
||||
struct $b;
|
||||
},
|
||||
($a:ident) => {
|
||||
struct $a;
|
||||
},
|
||||
}
|
||||
|
||||
foo! {
|
||||
A
|
||||
}
|
||||
11
tests/indent/rust/match.rs
Normal file
11
tests/indent/rust/match.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn foo(x: i32) -> i32 {
|
||||
match x {
|
||||
0 => 1,
|
||||
1 => {
|
||||
2
|
||||
},
|
||||
2 | 3 => {
|
||||
4
|
||||
}
|
||||
}
|
||||
}
|
||||
8
tests/indent/rust/mod.rs
Normal file
8
tests/indent/rust/mod.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
mod foo {
|
||||
const X: i32 = 1;
|
||||
|
||||
mod bar {
|
||||
|
||||
const Y: i32 = 1;
|
||||
}
|
||||
}
|
||||
12
tests/indent/rust/string.rs
Normal file
12
tests/indent/rust/string.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fn foo() {
|
||||
let a = "hello
|
||||
world";
|
||||
|
||||
let b = "hello\
|
||||
world";
|
||||
|
||||
let c = r#"
|
||||
hello
|
||||
world
|
||||
"#;
|
||||
}
|
||||
4
tests/indent/rust/struct.rs
Normal file
4
tests/indent/rust/struct.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
struct Foo {
|
||||
x: u32,
|
||||
y: u32,
|
||||
}
|
||||
11
tests/indent/rust/trait.rs
Normal file
11
tests/indent/rust/trait.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
struct Foo;
|
||||
|
||||
trait Bar {
|
||||
fn bar();
|
||||
}
|
||||
|
||||
impl Bar for Foo {
|
||||
fn bar() {
|
||||
|
||||
}
|
||||
}
|
||||
21
tests/indent/rust/where.rs
Normal file
21
tests/indent/rust/where.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
fn foo<T>(t: T) -> i32
|
||||
where
|
||||
T: Debug,
|
||||
{
|
||||
1
|
||||
}
|
||||
|
||||
fn foo<T>(t: T) -> i32 where
|
||||
T: Debug,
|
||||
{
|
||||
1
|
||||
}
|
||||
|
||||
struct Foo<T>(T);
|
||||
|
||||
impl<T> Write for Foo<T>
|
||||
where
|
||||
T: Debug,
|
||||
{
|
||||
|
||||
}
|
||||
67
tests/indent/rust_spec.lua
Normal file
67
tests/indent/rust_spec.lua
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
local whole_file = require('nvim-treesitter.test_utils').indent_whole_file
|
||||
local new_line = require('nvim-treesitter.test_utils').indent_new_line
|
||||
local scan_dir = require('plenary.scandir').scan_dir
|
||||
|
||||
local opts = {
|
||||
tabstop = 4,
|
||||
shiftwidth = 4,
|
||||
softtabstop = 0,
|
||||
expandtab = true,
|
||||
}
|
||||
|
||||
describe('indent Rust:', function()
|
||||
describe('whole file:', function()
|
||||
local files = scan_dir('tests/indent/rust');
|
||||
for _, file in ipairs(files) do
|
||||
it(vim.fn.fnamemodify(file, ':t'), function()
|
||||
whole_file(file, opts)
|
||||
end)
|
||||
end
|
||||
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 = '/// ' })
|
||||
run('cond.rs', { on_line = 11, text = 'x += 1;', indent = 12 })
|
||||
run('cond.rs', { on_line = 2, text = 'x += 1;', indent = 8 })
|
||||
run('cond.rs', { on_line = 4, text = 'x += 1;', indent = 8 })
|
||||
run('cond.rs', { on_line = 6, text = 'x += 1;', indent = 8 })
|
||||
run('enum.rs', { on_line = 2, text = 'Q,', indent = 4 })
|
||||
run('enum.rs', { on_line = 4, text = 'i32,', indent = 8 })
|
||||
run('enum.rs', { on_line = 8, text = 'z: u32,', indent = 8 })
|
||||
run('func.rs', { on_line = 1, text = 'let _x = 1;', indent = 4 })
|
||||
run('func.rs', { on_line = 6, text = 'z: i32,', indent = 4 })
|
||||
run('impl.rs', { on_line = 3, text = 'const FOO: u32 = 1;', indent = 4 })
|
||||
run('impl.rs', { on_line = 4, text = 'let _x = 1;', indent = 8 })
|
||||
run('loop.rs', { on_line = 10, text = 'x += 1;', indent = 8 })
|
||||
run('loop.rs', { on_line = 2, text = 'x += 1;', indent = 8 })
|
||||
run('loop.rs', { on_line = 6, text = 'x += 1;', indent = 8 })
|
||||
run('macro.rs', { on_line = 1, text = '() => {},', indent = 4 })
|
||||
run('macro.rs', { on_line = 12, text = 'B C', indent = 4 })
|
||||
run('macro.rs', { on_line = 2, text = 'struct $c;', indent = 8 })
|
||||
run('match.rs', { on_line = 2, text = '-1 => -1,', indent = 8 })
|
||||
run('match.rs', { on_line = 7, text = 'let y = 1;', indent = 12 })
|
||||
run('mod.rs', { on_line = 1, text = 'const Z: i32 = 1;', indent = 4 })
|
||||
run('mod.rs', { on_line = 2, text = 'const Z: i32 = 1;', indent = 4 })
|
||||
run('mod.rs', { on_line = 6, text = 'const Z: i32 = 1;', indent = 8 })
|
||||
run('string.rs', { on_line = 2, text = 'brave new', indent = 0 })
|
||||
run('string.rs', { on_line = 5, text = 'brave new \\', indent = 8 })
|
||||
run('string.rs', { on_line = 9, text = 'brave new \\', indent = 8 })
|
||||
run('struct.rs', { on_line = 1, text = 'z: i32,', indent = 4 })
|
||||
run('struct.rs', { on_line = 2, text = 'z: i32,', indent = 4 })
|
||||
run('trait.rs', { on_line = 4, text = 'fn baz();', indent = 4 })
|
||||
run('trait.rs', { on_line = 7, text = 'fn baz();', indent = 4 })
|
||||
run('trait.rs', { on_line = 8, text = '()', indent = 8 })
|
||||
run('where.rs', { on_line = 17, text = 'T: Debug,', indent = 4 })
|
||||
run('where.rs', { on_line = 2, text = 'T: Debug,', indent = 4 })
|
||||
run('where.rs', { on_line = 9, text = 'T: Debug,', indent = 4 })
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue