From 63a88c873f3643aad9208488765dc53618edd40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Boczar?= Date: Thu, 22 Apr 2021 20:53:30 +0200 Subject: move all tests to top-level tests/ directory --- lua/tests/indent/c/array.c | 14 ------ lua/tests/indent/c/comment.c | 8 ---- lua/tests/indent/c/cond.c | 10 ---- lua/tests/indent/c/enum.c | 5 -- lua/tests/indent/c/expr.c | 12 ----- lua/tests/indent/c/func.c | 33 ------------- lua/tests/indent/c/label.c | 7 --- lua/tests/indent/c/loop.c | 16 ------- lua/tests/indent/c/no_braces.c | 12 ----- lua/tests/indent/c/preproc_cond.c | 10 ---- lua/tests/indent/c/preproc_func.c | 9 ---- lua/tests/indent/c/string.c | 5 -- lua/tests/indent/c/struct.c | 11 ----- lua/tests/indent/c/switch.c | 16 ------- lua/tests/indent/c/ternary.c | 6 --- lua/tests/indent/c_spec.lua | 49 -------------------- lua/tests/indent/cpp/access.cpp | 6 --- lua/tests/indent/cpp/class.cpp | 7 --- lua/tests/indent/cpp/stream.cpp | 7 --- lua/tests/indent/cpp_spec.lua | 62 ------------------------- lua/tests/indent/lua/comment.lua | 7 --- lua/tests/indent/lua/cond.lua | 12 ----- lua/tests/indent/lua/func.lua | 9 ---- lua/tests/indent/lua/loop.lua | 14 ------ lua/tests/indent/lua/string.lua | 5 -- lua/tests/indent/lua/table.lua | 10 ---- lua/tests/indent/lua_spec.lua | 48 ------------------- lua/tests/indent/python/aligned_indent.py | 11 ----- lua/tests/indent/python/basic_blocks.py | 14 ------ lua/tests/indent/python/basic_collections.py | 23 --------- lua/tests/indent/python/branches.py | 27 ----------- lua/tests/indent/python/comprehensions.py | 25 ---------- lua/tests/indent/python/control_flow.py | 22 --------- lua/tests/indent/python/hanging_indent.py | 6 --- lua/tests/indent/python/join_lines.py | 8 ---- lua/tests/indent/python/nested_collections.py | 41 ---------------- lua/tests/indent/python/strings.py | 17 ------- lua/tests/indent/python_spec.lua | 52 --------------------- lua/tests/indent/rust/array.rs | 11 ----- lua/tests/indent/rust/comment.rs | 7 --- lua/tests/indent/rust/cond.rs | 17 ------- lua/tests/indent/rust/enum.rs | 11 ----- lua/tests/indent/rust/func.rs | 10 ---- lua/tests/indent/rust/impl.rs | 7 --- lua/tests/indent/rust/loop.rs | 19 -------- lua/tests/indent/rust/macro.rs | 13 ------ lua/tests/indent/rust/match.rs | 11 ----- lua/tests/indent/rust/mod.rs | 8 ---- lua/tests/indent/rust/string.rs | 12 ----- lua/tests/indent/rust/struct.rs | 4 -- lua/tests/indent/rust/trait.rs | 11 ----- lua/tests/indent/rust/where.rs | 21 --------- lua/tests/indent/rust_spec.lua | 67 --------------------------- scripts/run_tests.sh | 2 +- scripts/style-check.sh | 2 +- tests/indent/c/array.c | 14 ++++++ tests/indent/c/comment.c | 8 ++++ tests/indent/c/cond.c | 10 ++++ tests/indent/c/enum.c | 5 ++ tests/indent/c/expr.c | 12 +++++ tests/indent/c/func.c | 33 +++++++++++++ tests/indent/c/label.c | 7 +++ tests/indent/c/loop.c | 16 +++++++ tests/indent/c/no_braces.c | 12 +++++ tests/indent/c/preproc_cond.c | 10 ++++ tests/indent/c/preproc_func.c | 9 ++++ tests/indent/c/string.c | 5 ++ tests/indent/c/struct.c | 11 +++++ tests/indent/c/switch.c | 16 +++++++ tests/indent/c/ternary.c | 6 +++ tests/indent/c_spec.lua | 49 ++++++++++++++++++++ tests/indent/cpp/access.cpp | 6 +++ tests/indent/cpp/class.cpp | 7 +++ tests/indent/cpp/stream.cpp | 7 +++ tests/indent/cpp_spec.lua | 62 +++++++++++++++++++++++++ tests/indent/lua/comment.lua | 7 +++ tests/indent/lua/cond.lua | 12 +++++ tests/indent/lua/func.lua | 9 ++++ tests/indent/lua/loop.lua | 14 ++++++ tests/indent/lua/string.lua | 5 ++ tests/indent/lua/table.lua | 10 ++++ tests/indent/lua_spec.lua | 48 +++++++++++++++++++ tests/indent/python/aligned_indent.py | 11 +++++ tests/indent/python/basic_blocks.py | 14 ++++++ tests/indent/python/basic_collections.py | 23 +++++++++ tests/indent/python/branches.py | 27 +++++++++++ tests/indent/python/comprehensions.py | 25 ++++++++++ tests/indent/python/control_flow.py | 22 +++++++++ tests/indent/python/hanging_indent.py | 6 +++ tests/indent/python/join_lines.py | 8 ++++ tests/indent/python/nested_collections.py | 41 ++++++++++++++++ tests/indent/python/strings.py | 17 +++++++ tests/indent/python_spec.lua | 52 +++++++++++++++++++++ tests/indent/rust/array.rs | 11 +++++ tests/indent/rust/comment.rs | 7 +++ tests/indent/rust/cond.rs | 17 +++++++ tests/indent/rust/enum.rs | 11 +++++ tests/indent/rust/func.rs | 10 ++++ tests/indent/rust/impl.rs | 7 +++ tests/indent/rust/loop.rs | 19 ++++++++ tests/indent/rust/macro.rs | 13 ++++++ tests/indent/rust/match.rs | 11 +++++ tests/indent/rust/mod.rs | 8 ++++ tests/indent/rust/string.rs | 12 +++++ tests/indent/rust/struct.rs | 4 ++ tests/indent/rust/trait.rs | 11 +++++ tests/indent/rust/where.rs | 21 +++++++++ tests/indent/rust_spec.lua | 67 +++++++++++++++++++++++++++ 108 files changed, 887 insertions(+), 887 deletions(-) delete mode 100644 lua/tests/indent/c/array.c delete mode 100644 lua/tests/indent/c/comment.c delete mode 100644 lua/tests/indent/c/cond.c delete mode 100644 lua/tests/indent/c/enum.c delete mode 100644 lua/tests/indent/c/expr.c delete mode 100644 lua/tests/indent/c/func.c delete mode 100644 lua/tests/indent/c/label.c delete mode 100644 lua/tests/indent/c/loop.c delete mode 100644 lua/tests/indent/c/no_braces.c delete mode 100644 lua/tests/indent/c/preproc_cond.c delete mode 100644 lua/tests/indent/c/preproc_func.c delete mode 100644 lua/tests/indent/c/string.c delete mode 100644 lua/tests/indent/c/struct.c delete mode 100644 lua/tests/indent/c/switch.c delete mode 100644 lua/tests/indent/c/ternary.c delete mode 100644 lua/tests/indent/c_spec.lua delete mode 100644 lua/tests/indent/cpp/access.cpp delete mode 100644 lua/tests/indent/cpp/class.cpp delete mode 100644 lua/tests/indent/cpp/stream.cpp delete mode 100644 lua/tests/indent/cpp_spec.lua delete mode 100644 lua/tests/indent/lua/comment.lua delete mode 100644 lua/tests/indent/lua/cond.lua delete mode 100644 lua/tests/indent/lua/func.lua delete mode 100644 lua/tests/indent/lua/loop.lua delete mode 100644 lua/tests/indent/lua/string.lua delete mode 100644 lua/tests/indent/lua/table.lua delete mode 100644 lua/tests/indent/lua_spec.lua delete mode 100644 lua/tests/indent/python/aligned_indent.py delete mode 100644 lua/tests/indent/python/basic_blocks.py delete mode 100644 lua/tests/indent/python/basic_collections.py delete mode 100644 lua/tests/indent/python/branches.py delete mode 100644 lua/tests/indent/python/comprehensions.py delete mode 100644 lua/tests/indent/python/control_flow.py delete mode 100644 lua/tests/indent/python/hanging_indent.py delete mode 100644 lua/tests/indent/python/join_lines.py delete mode 100644 lua/tests/indent/python/nested_collections.py delete mode 100644 lua/tests/indent/python/strings.py delete mode 100644 lua/tests/indent/python_spec.lua delete mode 100644 lua/tests/indent/rust/array.rs delete mode 100644 lua/tests/indent/rust/comment.rs delete mode 100644 lua/tests/indent/rust/cond.rs delete mode 100644 lua/tests/indent/rust/enum.rs delete mode 100644 lua/tests/indent/rust/func.rs delete mode 100644 lua/tests/indent/rust/impl.rs delete mode 100644 lua/tests/indent/rust/loop.rs delete mode 100644 lua/tests/indent/rust/macro.rs delete mode 100644 lua/tests/indent/rust/match.rs delete mode 100644 lua/tests/indent/rust/mod.rs delete mode 100644 lua/tests/indent/rust/string.rs delete mode 100644 lua/tests/indent/rust/struct.rs delete mode 100644 lua/tests/indent/rust/trait.rs delete mode 100644 lua/tests/indent/rust/where.rs delete mode 100644 lua/tests/indent/rust_spec.lua create mode 100644 tests/indent/c/array.c create mode 100644 tests/indent/c/comment.c create mode 100644 tests/indent/c/cond.c create mode 100644 tests/indent/c/enum.c create mode 100644 tests/indent/c/expr.c create mode 100644 tests/indent/c/func.c create mode 100644 tests/indent/c/label.c create mode 100644 tests/indent/c/loop.c create mode 100644 tests/indent/c/no_braces.c create mode 100644 tests/indent/c/preproc_cond.c create mode 100644 tests/indent/c/preproc_func.c create mode 100644 tests/indent/c/string.c create mode 100644 tests/indent/c/struct.c create mode 100644 tests/indent/c/switch.c create mode 100644 tests/indent/c/ternary.c create mode 100644 tests/indent/c_spec.lua create mode 100644 tests/indent/cpp/access.cpp create mode 100644 tests/indent/cpp/class.cpp create mode 100644 tests/indent/cpp/stream.cpp create mode 100644 tests/indent/cpp_spec.lua create mode 100644 tests/indent/lua/comment.lua create mode 100644 tests/indent/lua/cond.lua create mode 100644 tests/indent/lua/func.lua create mode 100644 tests/indent/lua/loop.lua create mode 100644 tests/indent/lua/string.lua create mode 100644 tests/indent/lua/table.lua create mode 100644 tests/indent/lua_spec.lua create mode 100644 tests/indent/python/aligned_indent.py create mode 100644 tests/indent/python/basic_blocks.py create mode 100644 tests/indent/python/basic_collections.py create mode 100644 tests/indent/python/branches.py create mode 100644 tests/indent/python/comprehensions.py create mode 100644 tests/indent/python/control_flow.py create mode 100644 tests/indent/python/hanging_indent.py create mode 100644 tests/indent/python/join_lines.py create mode 100644 tests/indent/python/nested_collections.py create mode 100644 tests/indent/python/strings.py create mode 100644 tests/indent/python_spec.lua create mode 100644 tests/indent/rust/array.rs create mode 100644 tests/indent/rust/comment.rs create mode 100644 tests/indent/rust/cond.rs create mode 100644 tests/indent/rust/enum.rs create mode 100644 tests/indent/rust/func.rs create mode 100644 tests/indent/rust/impl.rs create mode 100644 tests/indent/rust/loop.rs create mode 100644 tests/indent/rust/macro.rs create mode 100644 tests/indent/rust/match.rs create mode 100644 tests/indent/rust/mod.rs create mode 100644 tests/indent/rust/string.rs create mode 100644 tests/indent/rust/struct.rs create mode 100644 tests/indent/rust/trait.rs create mode 100644 tests/indent/rust/where.rs create mode 100644 tests/indent/rust_spec.lua diff --git a/lua/tests/indent/c/array.c b/lua/tests/indent/c/array.c deleted file mode 100644 index 5bb67c2c..00000000 --- a/lua/tests/indent/c/array.c +++ /dev/null @@ -1,14 +0,0 @@ -int x[] = { - 1, 2, 3, - 4, 5, - 6 -}; - -int y[][2] = { - {0, 1}, - {1, 2}, - { - 2, - 3 - }, -}; diff --git a/lua/tests/indent/c/comment.c b/lua/tests/indent/c/comment.c deleted file mode 100644 index b32de821..00000000 --- a/lua/tests/indent/c/comment.c +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Function foo - * @param[out] x output - * @param[in] x input - */ -void foo(int *x, int y) { - *x = y; -} diff --git a/lua/tests/indent/c/cond.c b/lua/tests/indent/c/cond.c deleted file mode 100644 index 1ecb22d9..00000000 --- a/lua/tests/indent/c/cond.c +++ /dev/null @@ -1,10 +0,0 @@ -void foo(int x) -{ - if (x > 10) { - return; - } else if (x < -10) { - x = -10; - } else { - x = -x; - } -} diff --git a/lua/tests/indent/c/enum.c b/lua/tests/indent/c/enum.c deleted file mode 100644 index bb6b0dc3..00000000 --- a/lua/tests/indent/c/enum.c +++ /dev/null @@ -1,5 +0,0 @@ -enum foo { - A = 1, - B, - C, -}; diff --git a/lua/tests/indent/c/expr.c b/lua/tests/indent/c/expr.c deleted file mode 100644 index cafb1112..00000000 --- a/lua/tests/indent/c/expr.c +++ /dev/null @@ -1,12 +0,0 @@ -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); -} diff --git a/lua/tests/indent/c/func.c b/lua/tests/indent/c/func.c deleted file mode 100644 index c188acc0..00000000 --- a/lua/tests/indent/c/func.c +++ /dev/null @@ -1,33 +0,0 @@ -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; -} diff --git a/lua/tests/indent/c/label.c b/lua/tests/indent/c/label.c deleted file mode 100644 index 36b40e23..00000000 --- a/lua/tests/indent/c/label.c +++ /dev/null @@ -1,7 +0,0 @@ -int foo(int x) -{ - goto error; - return 0; -error: - return 1; -} diff --git a/lua/tests/indent/c/loop.c b/lua/tests/indent/c/loop.c deleted file mode 100644 index facaebb6..00000000 --- a/lua/tests/indent/c/loop.c +++ /dev/null @@ -1,16 +0,0 @@ -void foo(int x) -{ - while (x > 0) { - x--; - continue; - } - - for (int i = 0; i < 5; ++i) { - x++; - break; - } - - do { - x++; - } while (x < 0); -} diff --git a/lua/tests/indent/c/no_braces.c b/lua/tests/indent/c/no_braces.c deleted file mode 100644 index 544ac01d..00000000 --- a/lua/tests/indent/c/no_braces.c +++ /dev/null @@ -1,12 +0,0 @@ -int foo(int x) { - if (x > 10) - return 10; - else - return x; - - while (1) - x++; - - for (int i = 0; i < 3; ++i) - x--; -} diff --git a/lua/tests/indent/c/preproc_cond.c b/lua/tests/indent/c/preproc_cond.c deleted file mode 100644 index b85440aa..00000000 --- a/lua/tests/indent/c/preproc_cond.c +++ /dev/null @@ -1,10 +0,0 @@ -void foo(int x) -{ - x = x + 1; -#if 1 - x = x + 2; -#else - x = x + 3; -#endif - x = x + 4; -} diff --git a/lua/tests/indent/c/preproc_func.c b/lua/tests/indent/c/preproc_func.c deleted file mode 100644 index f1f38feb..00000000 --- a/lua/tests/indent/c/preproc_func.c +++ /dev/null @@ -1,9 +0,0 @@ -#define FOO(x) do { \ - x = x + 1; \ - x = x / 2; \ - } while (x > 0); - -void foo(int x) -{ - FOO(x); -} diff --git a/lua/tests/indent/c/string.c b/lua/tests/indent/c/string.c deleted file mode 100644 index 2d5177e0..00000000 --- a/lua/tests/indent/c/string.c +++ /dev/null @@ -1,5 +0,0 @@ -const char *a = "hello \ -world"; - -const char *b = "hello " - "world"; diff --git a/lua/tests/indent/c/struct.c b/lua/tests/indent/c/struct.c deleted file mode 100644 index 8cc2b6b2..00000000 --- a/lua/tests/indent/c/struct.c +++ /dev/null @@ -1,11 +0,0 @@ -struct foo { - int a; - struct bar { - int x; - } b; -}; - -union baz { - struct foo; - int x; -}; diff --git a/lua/tests/indent/c/switch.c b/lua/tests/indent/c/switch.c deleted file mode 100644 index 4003bdb1..00000000 --- a/lua/tests/indent/c/switch.c +++ /dev/null @@ -1,16 +0,0 @@ -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; - } -} diff --git a/lua/tests/indent/c/ternary.c b/lua/tests/indent/c/ternary.c deleted file mode 100644 index 2e40b382..00000000 --- a/lua/tests/indent/c/ternary.c +++ /dev/null @@ -1,6 +0,0 @@ -void foo(int x) -{ - int y = (x > 10) ? 10 - : (x < -10) ? -10 - : x; -} diff --git a/lua/tests/indent/c_spec.lua b/lua/tests/indent/c_spec.lua deleted file mode 100644 index 2850023a..00000000 --- a/lua/tests/indent/c_spec.lua +++ /dev/null @@ -1,49 +0,0 @@ -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('lua/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('lua/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) diff --git a/lua/tests/indent/cpp/access.cpp b/lua/tests/indent/cpp/access.cpp deleted file mode 100644 index abdb846c..00000000 --- a/lua/tests/indent/cpp/access.cpp +++ /dev/null @@ -1,6 +0,0 @@ -class Foo { -public: - int x; -private: - int y; -}; diff --git a/lua/tests/indent/cpp/class.cpp b/lua/tests/indent/cpp/class.cpp deleted file mode 100644 index cd838219..00000000 --- a/lua/tests/indent/cpp/class.cpp +++ /dev/null @@ -1,7 +0,0 @@ -class Foo { - int x; - class Bar { - int y; - }; - Bar z; -}; diff --git a/lua/tests/indent/cpp/stream.cpp b/lua/tests/indent/cpp/stream.cpp deleted file mode 100644 index a619dfa6..00000000 --- a/lua/tests/indent/cpp/stream.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void foo(int x) { - std::cout << x - << x + 1 - << x + 2; -} diff --git a/lua/tests/indent/cpp_spec.lua b/lua/tests/indent/cpp_spec.lua deleted file mode 100644 index fd1f3579..00000000 --- a/lua/tests/indent/cpp_spec.lua +++ /dev/null @@ -1,62 +0,0 @@ -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('lua/tests/indent') -end - -describe('indent C++:', function() - describe('whole file:', function() - local files = scan_dir('lua/tests/indent/c'); - vim.list_extend(files, scan_dir('lua/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('lua/tests/indent/cpp/access.cpp', { on_line = 3, text = 'protected:', indent = 0 }) - run('lua/tests/indent/cpp/class.cpp', { on_line = 2, text = 'using T = int;', indent = 4 }) - run('lua/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('lua/tests/indent/c/array.c', { on_line = 2, text = '0,', indent = 4 }) - run('lua/tests/indent/c/cond.c', { on_line = 3, text = 'x++;', indent = 8 }) - run('lua/tests/indent/c/cond.c', { on_line = 8, text = 'x++;', indent = 8 }) - run('lua/tests/indent/c/expr.c', { on_line = 10, text = '2 *', indent = 8 }) - run('lua/tests/indent/c/func.c', { on_line = 17, text = 'int z,', indent = 4 }) - run('lua/tests/indent/c/label.c', { on_line = 3, text = 'normal:', indent = 0 }) - run('lua/tests/indent/c/loop.c', { on_line = 3, text = 'x++;', indent = 8 }) - run('lua/tests/indent/c/preproc_cond.c', { on_line = 5, text = 'x++;', indent = 4 }) - run('lua/tests/indent/c/preproc_func.c', { on_line = 3, text = 'x++; \\', indent = 8 }) - run('lua/tests/indent/c/string.c', { on_line = 1, text = 'brave new \\', indent = 0 }) - run('lua/tests/indent/c/string.c', { on_line = 4, text = '"brave new "', indent = 4 }) - run('lua/tests/indent/c/struct.c', { on_line = 4, text = 'int y;', indent = 8 }) - run('lua/tests/indent/c/switch.c', { on_line = 3, text = 'x++;', indent = 12 }) - run('lua/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('lua/tests/indent/c/no_braces.c', { on_line = 4, text = 'x++;', indent = 8 }) - run('lua/tests/indent/c/no_braces.c', { on_line = 7, text = 'x++;', indent = 8 }) - run('lua/tests/indent/c/no_braces.c', { on_line = 10, text = 'x++;', indent = 8 }) - end) -end) diff --git a/lua/tests/indent/lua/comment.lua b/lua/tests/indent/lua/comment.lua deleted file mode 100644 index 9f3624e1..00000000 --- a/lua/tests/indent/lua/comment.lua +++ /dev/null @@ -1,7 +0,0 @@ --- some --- comment - ---[[ - another - comment ---]] diff --git a/lua/tests/indent/lua/cond.lua b/lua/tests/indent/lua/cond.lua deleted file mode 100644 index dfae37f0..00000000 --- a/lua/tests/indent/lua/cond.lua +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/lua/tests/indent/lua/func.lua b/lua/tests/indent/lua/func.lua deleted file mode 100644 index 1f95ca97..00000000 --- a/lua/tests/indent/lua/func.lua +++ /dev/null @@ -1,9 +0,0 @@ -function foo(x) - local bar = function(a, b, c) - return a + b + c - end - return bar( - x, - 1, - 2) -end diff --git a/lua/tests/indent/lua/loop.lua b/lua/tests/indent/lua/loop.lua deleted file mode 100644 index 7f5402d1..00000000 --- a/lua/tests/indent/lua/loop.lua +++ /dev/null @@ -1,14 +0,0 @@ -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 diff --git a/lua/tests/indent/lua/string.lua b/lua/tests/indent/lua/string.lua deleted file mode 100644 index adfebf76..00000000 --- a/lua/tests/indent/lua/string.lua +++ /dev/null @@ -1,5 +0,0 @@ -local s = [[ -a - multiline - string -]] diff --git a/lua/tests/indent/lua/table.lua b/lua/tests/indent/lua/table.lua deleted file mode 100644 index d53504b4..00000000 --- a/lua/tests/indent/lua/table.lua +++ /dev/null @@ -1,10 +0,0 @@ -local a = { - x = 1, - y = 2, - z = { - 1, 2, 3, - }, - ['hello world'] = { - 1, 2, 3 - } -} diff --git a/lua/tests/indent/lua_spec.lua b/lua/tests/indent/lua_spec.lua deleted file mode 100644 index 3a2a7cb7..00000000 --- a/lua/tests/indent/lua_spec.lua +++ /dev/null @@ -1,48 +0,0 @@ -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('lua/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('lua/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) - diff --git a/lua/tests/indent/python/aligned_indent.py b/lua/tests/indent/python/aligned_indent.py deleted file mode 100644 index 2a4b827f..00000000 --- a/lua/tests/indent/python/aligned_indent.py +++ /dev/null @@ -1,11 +0,0 @@ -def aligned_indent(arg1, - arg2): - pass - -aligned_indent(1, - 2) - - -aligned_indent(1, - 2 - ) diff --git a/lua/tests/indent/python/basic_blocks.py b/lua/tests/indent/python/basic_blocks.py deleted file mode 100644 index 4f36359b..00000000 --- a/lua/tests/indent/python/basic_blocks.py +++ /dev/null @@ -1,14 +0,0 @@ -from os import ( - path, - name as OsName -) - -def foo(x): - pass - -class Foo: - def __init__(self): - pass - - def foo(self): - pass diff --git a/lua/tests/indent/python/basic_collections.py b/lua/tests/indent/python/basic_collections.py deleted file mode 100644 index 1582b905..00000000 --- a/lua/tests/indent/python/basic_collections.py +++ /dev/null @@ -1,23 +0,0 @@ -# list -a = [ - 1, 2, - 3 -] - -# set -b = { - 3, - 4, -} - -# dict -c = { - 'a': 'b', - 'c': 1, -} - -# tuple -d = ( - 1, - 2, -) diff --git a/lua/tests/indent/python/branches.py b/lua/tests/indent/python/branches.py deleted file mode 100644 index 7ce106bd..00000000 --- a/lua/tests/indent/python/branches.py +++ /dev/null @@ -1,27 +0,0 @@ -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 diff --git a/lua/tests/indent/python/comprehensions.py b/lua/tests/indent/python/comprehensions.py deleted file mode 100644 index 53c3961e..00000000 --- a/lua/tests/indent/python/comprehensions.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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) -] diff --git a/lua/tests/indent/python/control_flow.py b/lua/tests/indent/python/control_flow.py deleted file mode 100644 index c8cd2541..00000000 --- a/lua/tests/indent/python/control_flow.py +++ /dev/null @@ -1,22 +0,0 @@ -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 diff --git a/lua/tests/indent/python/hanging_indent.py b/lua/tests/indent/python/hanging_indent.py deleted file mode 100644 index 4d46ebed..00000000 --- a/lua/tests/indent/python/hanging_indent.py +++ /dev/null @@ -1,6 +0,0 @@ -def hanging_indent( - arg1, arg2): - pass - -hanging_indent( - 1, 2) diff --git a/lua/tests/indent/python/join_lines.py b/lua/tests/indent/python/join_lines.py deleted file mode 100644 index 491b2cc3..00000000 --- a/lua/tests/indent/python/join_lines.py +++ /dev/null @@ -1,8 +0,0 @@ -a = 2 \ - + 2 - -b = 'hello' \ - 'world' - -c = lambda x: \ - x + 3 diff --git a/lua/tests/indent/python/nested_collections.py b/lua/tests/indent/python/nested_collections.py deleted file mode 100644 index 292a65a0..00000000 --- a/lua/tests/indent/python/nested_collections.py +++ /dev/null @@ -1,41 +0,0 @@ -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 - ) diff --git a/lua/tests/indent/python/strings.py b/lua/tests/indent/python/strings.py deleted file mode 100644 index 0eb088fa..00000000 --- a/lua/tests/indent/python/strings.py +++ /dev/null @@ -1,17 +0,0 @@ -a = """ - String A -""" - -b = """ -String B -""" - -c = """ - String C - """ - -d = """ - String D -String D - String D - """ diff --git a/lua/tests/indent/python_spec.lua b/lua/tests/indent/python_spec.lua deleted file mode 100644 index 2927ad4e..00000000 --- a/lua/tests/indent/python_spec.lua +++ /dev/null @@ -1,52 +0,0 @@ -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('lua/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('lua/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) diff --git a/lua/tests/indent/rust/array.rs b/lua/tests/indent/rust/array.rs deleted file mode 100644 index 68344e0e..00000000 --- a/lua/tests/indent/rust/array.rs +++ /dev/null @@ -1,11 +0,0 @@ -const X: [i32; 2] = [ - 1, - 2, -]; - -fn foo() { - let _x = [ - 1, - 2, - ]; -} diff --git a/lua/tests/indent/rust/comment.rs b/lua/tests/indent/rust/comment.rs deleted file mode 100644 index 334793df..00000000 --- a/lua/tests/indent/rust/comment.rs +++ /dev/null @@ -1,7 +0,0 @@ -/// Function foo -/// -/// Description of -/// function foo. -fn foo(x: i32, y: i32) -> i32 { - x + y -} diff --git a/lua/tests/indent/rust/cond.rs b/lua/tests/indent/rust/cond.rs deleted file mode 100644 index eb96a48f..00000000 --- a/lua/tests/indent/rust/cond.rs +++ /dev/null @@ -1,17 +0,0 @@ -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 -} diff --git a/lua/tests/indent/rust/enum.rs b/lua/tests/indent/rust/enum.rs deleted file mode 100644 index 996f07d2..00000000 --- a/lua/tests/indent/rust/enum.rs +++ /dev/null @@ -1,11 +0,0 @@ -enum Foo { - X, - Y( - char, - char, - ), - Z { - x: u32, - y: u32, - }, -} diff --git a/lua/tests/indent/rust/func.rs b/lua/tests/indent/rust/func.rs deleted file mode 100644 index 4c9d40b2..00000000 --- a/lua/tests/indent/rust/func.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn foo() -> i32 { - 1 -} - -fn foo( - x: i32, - y: i32 -) -> i32 { - x + y -} diff --git a/lua/tests/indent/rust/impl.rs b/lua/tests/indent/rust/impl.rs deleted file mode 100644 index 2525c2e5..00000000 --- a/lua/tests/indent/rust/impl.rs +++ /dev/null @@ -1,7 +0,0 @@ -struct Foo; - -impl Foo { - fn foo() -> i32 { - 1 - } -} diff --git a/lua/tests/indent/rust/loop.rs b/lua/tests/indent/rust/loop.rs deleted file mode 100644 index eb845bc0..00000000 --- a/lua/tests/indent/rust/loop.rs +++ /dev/null @@ -1,19 +0,0 @@ -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; - } -} diff --git a/lua/tests/indent/rust/macro.rs b/lua/tests/indent/rust/macro.rs deleted file mode 100644 index 608e157f..00000000 --- a/lua/tests/indent/rust/macro.rs +++ /dev/null @@ -1,13 +0,0 @@ -macro_rules! foo { - ($a:ident, $b:ident, $c:ident) => { - struct $a; - struct $b; - }, - ($a:ident) => { - struct $a; - }, -} - -foo! { - A -} diff --git a/lua/tests/indent/rust/match.rs b/lua/tests/indent/rust/match.rs deleted file mode 100644 index 438ba6d5..00000000 --- a/lua/tests/indent/rust/match.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn foo(x: i32) -> i32 { - match x { - 0 => 1, - 1 => { - 2 - }, - 2 | 3 => { - 4 - } - } -} diff --git a/lua/tests/indent/rust/mod.rs b/lua/tests/indent/rust/mod.rs deleted file mode 100644 index cc7f2c8e..00000000 --- a/lua/tests/indent/rust/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -mod foo { - const X: i32 = 1; - - mod bar { - - const Y: i32 = 1; - } -} diff --git a/lua/tests/indent/rust/string.rs b/lua/tests/indent/rust/string.rs deleted file mode 100644 index 4d60663d..00000000 --- a/lua/tests/indent/rust/string.rs +++ /dev/null @@ -1,12 +0,0 @@ -fn foo() { - let a = "hello -world"; - - let b = "hello\ - world"; - - let c = r#" - hello - world - "#; -} diff --git a/lua/tests/indent/rust/struct.rs b/lua/tests/indent/rust/struct.rs deleted file mode 100644 index f3828977..00000000 --- a/lua/tests/indent/rust/struct.rs +++ /dev/null @@ -1,4 +0,0 @@ -struct Foo { - x: u32, - y: u32, -} diff --git a/lua/tests/indent/rust/trait.rs b/lua/tests/indent/rust/trait.rs deleted file mode 100644 index fb5fc7ea..00000000 --- a/lua/tests/indent/rust/trait.rs +++ /dev/null @@ -1,11 +0,0 @@ -struct Foo; - -trait Bar { - fn bar(); -} - -impl Bar for Foo { - fn bar() { - - } -} diff --git a/lua/tests/indent/rust/where.rs b/lua/tests/indent/rust/where.rs deleted file mode 100644 index 08c1b196..00000000 --- a/lua/tests/indent/rust/where.rs +++ /dev/null @@ -1,21 +0,0 @@ -fn foo(t: T) -> i32 -where - T: Debug, -{ - 1 -} - -fn foo(t: T) -> i32 where - T: Debug, -{ - 1 -} - -struct Foo(T); - -impl Write for Foo -where - T: Debug, -{ - -} diff --git a/lua/tests/indent/rust_spec.lua b/lua/tests/indent/rust_spec.lua deleted file mode 100644 index 120b6771..00000000 --- a/lua/tests/indent/rust_spec.lua +++ /dev/null @@ -1,67 +0,0 @@ -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('lua/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('lua/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) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 569a2d5e..c7800d50 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -5,7 +5,7 @@ cd $HERE/.. run() { nvim --headless --noplugin -u scripts/minimal_init.lua \ - -c "PlenaryBustedDirectory lua/tests/indent/ { minimal_init = './scripts/minimal_init.lua' }" + -c "PlenaryBustedDirectory tests/indent/ { minimal_init = './scripts/minimal_init.lua' }" } if [[ $1 = '--summary' ]]; then diff --git a/scripts/style-check.sh b/scripts/style-check.sh index bf3b906f..8dfb53aa 100755 --- a/scripts/style-check.sh +++ b/scripts/style-check.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # ignore indent test files -luacheck `find -name "*.lua" -not -path "./lua/tests/indent/lua/*"` --codes +luacheck `find -name "*.lua" -not -path "./tests/indent/lua/*"` --codes diff --git a/tests/indent/c/array.c b/tests/indent/c/array.c new file mode 100644 index 00000000..5bb67c2c --- /dev/null +++ b/tests/indent/c/array.c @@ -0,0 +1,14 @@ +int x[] = { + 1, 2, 3, + 4, 5, + 6 +}; + +int y[][2] = { + {0, 1}, + {1, 2}, + { + 2, + 3 + }, +}; diff --git a/tests/indent/c/comment.c b/tests/indent/c/comment.c new file mode 100644 index 00000000..b32de821 --- /dev/null +++ b/tests/indent/c/comment.c @@ -0,0 +1,8 @@ +/** + * Function foo + * @param[out] x output + * @param[in] x input + */ +void foo(int *x, int y) { + *x = y; +} diff --git a/tests/indent/c/cond.c b/tests/indent/c/cond.c new file mode 100644 index 00000000..1ecb22d9 --- /dev/null +++ b/tests/indent/c/cond.c @@ -0,0 +1,10 @@ +void foo(int x) +{ + if (x > 10) { + return; + } else if (x < -10) { + x = -10; + } else { + x = -x; + } +} diff --git a/tests/indent/c/enum.c b/tests/indent/c/enum.c new file mode 100644 index 00000000..bb6b0dc3 --- /dev/null +++ b/tests/indent/c/enum.c @@ -0,0 +1,5 @@ +enum foo { + A = 1, + B, + C, +}; diff --git a/tests/indent/c/expr.c b/tests/indent/c/expr.c new file mode 100644 index 00000000..cafb1112 --- /dev/null +++ b/tests/indent/c/expr.c @@ -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); +} diff --git a/tests/indent/c/func.c b/tests/indent/c/func.c new file mode 100644 index 00000000..c188acc0 --- /dev/null +++ b/tests/indent/c/func.c @@ -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; +} diff --git a/tests/indent/c/label.c b/tests/indent/c/label.c new file mode 100644 index 00000000..36b40e23 --- /dev/null +++ b/tests/indent/c/label.c @@ -0,0 +1,7 @@ +int foo(int x) +{ + goto error; + return 0; +error: + return 1; +} diff --git a/tests/indent/c/loop.c b/tests/indent/c/loop.c new file mode 100644 index 00000000..facaebb6 --- /dev/null +++ b/tests/indent/c/loop.c @@ -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); +} diff --git a/tests/indent/c/no_braces.c b/tests/indent/c/no_braces.c new file mode 100644 index 00000000..544ac01d --- /dev/null +++ b/tests/indent/c/no_braces.c @@ -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--; +} diff --git a/tests/indent/c/preproc_cond.c b/tests/indent/c/preproc_cond.c new file mode 100644 index 00000000..b85440aa --- /dev/null +++ b/tests/indent/c/preproc_cond.c @@ -0,0 +1,10 @@ +void foo(int x) +{ + x = x + 1; +#if 1 + x = x + 2; +#else + x = x + 3; +#endif + x = x + 4; +} diff --git a/tests/indent/c/preproc_func.c b/tests/indent/c/preproc_func.c new file mode 100644 index 00000000..f1f38feb --- /dev/null +++ b/tests/indent/c/preproc_func.c @@ -0,0 +1,9 @@ +#define FOO(x) do { \ + x = x + 1; \ + x = x / 2; \ + } while (x > 0); + +void foo(int x) +{ + FOO(x); +} diff --git a/tests/indent/c/string.c b/tests/indent/c/string.c new file mode 100644 index 00000000..2d5177e0 --- /dev/null +++ b/tests/indent/c/string.c @@ -0,0 +1,5 @@ +const char *a = "hello \ +world"; + +const char *b = "hello " + "world"; diff --git a/tests/indent/c/struct.c b/tests/indent/c/struct.c new file mode 100644 index 00000000..8cc2b6b2 --- /dev/null +++ b/tests/indent/c/struct.c @@ -0,0 +1,11 @@ +struct foo { + int a; + struct bar { + int x; + } b; +}; + +union baz { + struct foo; + int x; +}; diff --git a/tests/indent/c/switch.c b/tests/indent/c/switch.c new file mode 100644 index 00000000..4003bdb1 --- /dev/null +++ b/tests/indent/c/switch.c @@ -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; + } +} diff --git a/tests/indent/c/ternary.c b/tests/indent/c/ternary.c new file mode 100644 index 00000000..2e40b382 --- /dev/null +++ b/tests/indent/c/ternary.c @@ -0,0 +1,6 @@ +void foo(int x) +{ + int y = (x > 10) ? 10 + : (x < -10) ? -10 + : x; +} diff --git a/tests/indent/c_spec.lua b/tests/indent/c_spec.lua new file mode 100644 index 00000000..98311c77 --- /dev/null +++ b/tests/indent/c_spec.lua @@ -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) diff --git a/tests/indent/cpp/access.cpp b/tests/indent/cpp/access.cpp new file mode 100644 index 00000000..abdb846c --- /dev/null +++ b/tests/indent/cpp/access.cpp @@ -0,0 +1,6 @@ +class Foo { +public: + int x; +private: + int y; +}; diff --git a/tests/indent/cpp/class.cpp b/tests/indent/cpp/class.cpp new file mode 100644 index 00000000..cd838219 --- /dev/null +++ b/tests/indent/cpp/class.cpp @@ -0,0 +1,7 @@ +class Foo { + int x; + class Bar { + int y; + }; + Bar z; +}; diff --git a/tests/indent/cpp/stream.cpp b/tests/indent/cpp/stream.cpp new file mode 100644 index 00000000..a619dfa6 --- /dev/null +++ b/tests/indent/cpp/stream.cpp @@ -0,0 +1,7 @@ +#include + +void foo(int x) { + std::cout << x + << x + 1 + << x + 2; +} diff --git a/tests/indent/cpp_spec.lua b/tests/indent/cpp_spec.lua new file mode 100644 index 00000000..d3c98401 --- /dev/null +++ b/tests/indent/cpp_spec.lua @@ -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) diff --git a/tests/indent/lua/comment.lua b/tests/indent/lua/comment.lua new file mode 100644 index 00000000..9f3624e1 --- /dev/null +++ b/tests/indent/lua/comment.lua @@ -0,0 +1,7 @@ +-- some +-- comment + +--[[ + another + comment +--]] diff --git a/tests/indent/lua/cond.lua b/tests/indent/lua/cond.lua new file mode 100644 index 00000000..dfae37f0 --- /dev/null +++ b/tests/indent/lua/cond.lua @@ -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 diff --git a/tests/indent/lua/func.lua b/tests/indent/lua/func.lua new file mode 100644 index 00000000..1f95ca97 --- /dev/null +++ b/tests/indent/lua/func.lua @@ -0,0 +1,9 @@ +function foo(x) + local bar = function(a, b, c) + return a + b + c + end + return bar( + x, + 1, + 2) +end diff --git a/tests/indent/lua/loop.lua b/tests/indent/lua/loop.lua new file mode 100644 index 00000000..7f5402d1 --- /dev/null +++ b/tests/indent/lua/loop.lua @@ -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 diff --git a/tests/indent/lua/string.lua b/tests/indent/lua/string.lua new file mode 100644 index 00000000..adfebf76 --- /dev/null +++ b/tests/indent/lua/string.lua @@ -0,0 +1,5 @@ +local s = [[ +a + multiline + string +]] diff --git a/tests/indent/lua/table.lua b/tests/indent/lua/table.lua new file mode 100644 index 00000000..d53504b4 --- /dev/null +++ b/tests/indent/lua/table.lua @@ -0,0 +1,10 @@ +local a = { + x = 1, + y = 2, + z = { + 1, 2, 3, + }, + ['hello world'] = { + 1, 2, 3 + } +} diff --git a/tests/indent/lua_spec.lua b/tests/indent/lua_spec.lua new file mode 100644 index 00000000..473f584c --- /dev/null +++ b/tests/indent/lua_spec.lua @@ -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) + diff --git a/tests/indent/python/aligned_indent.py b/tests/indent/python/aligned_indent.py new file mode 100644 index 00000000..2a4b827f --- /dev/null +++ b/tests/indent/python/aligned_indent.py @@ -0,0 +1,11 @@ +def aligned_indent(arg1, + arg2): + pass + +aligned_indent(1, + 2) + + +aligned_indent(1, + 2 + ) diff --git a/tests/indent/python/basic_blocks.py b/tests/indent/python/basic_blocks.py new file mode 100644 index 00000000..4f36359b --- /dev/null +++ b/tests/indent/python/basic_blocks.py @@ -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 diff --git a/tests/indent/python/basic_collections.py b/tests/indent/python/basic_collections.py new file mode 100644 index 00000000..1582b905 --- /dev/null +++ b/tests/indent/python/basic_collections.py @@ -0,0 +1,23 @@ +# list +a = [ + 1, 2, + 3 +] + +# set +b = { + 3, + 4, +} + +# dict +c = { + 'a': 'b', + 'c': 1, +} + +# tuple +d = ( + 1, + 2, +) diff --git a/tests/indent/python/branches.py b/tests/indent/python/branches.py new file mode 100644 index 00000000..7ce106bd --- /dev/null +++ b/tests/indent/python/branches.py @@ -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 diff --git a/tests/indent/python/comprehensions.py b/tests/indent/python/comprehensions.py new file mode 100644 index 00000000..53c3961e --- /dev/null +++ b/tests/indent/python/comprehensions.py @@ -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) +] diff --git a/tests/indent/python/control_flow.py b/tests/indent/python/control_flow.py new file mode 100644 index 00000000..c8cd2541 --- /dev/null +++ b/tests/indent/python/control_flow.py @@ -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 diff --git a/tests/indent/python/hanging_indent.py b/tests/indent/python/hanging_indent.py new file mode 100644 index 00000000..4d46ebed --- /dev/null +++ b/tests/indent/python/hanging_indent.py @@ -0,0 +1,6 @@ +def hanging_indent( + arg1, arg2): + pass + +hanging_indent( + 1, 2) diff --git a/tests/indent/python/join_lines.py b/tests/indent/python/join_lines.py new file mode 100644 index 00000000..491b2cc3 --- /dev/null +++ b/tests/indent/python/join_lines.py @@ -0,0 +1,8 @@ +a = 2 \ + + 2 + +b = 'hello' \ + 'world' + +c = lambda x: \ + x + 3 diff --git a/tests/indent/python/nested_collections.py b/tests/indent/python/nested_collections.py new file mode 100644 index 00000000..292a65a0 --- /dev/null +++ b/tests/indent/python/nested_collections.py @@ -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 + ) diff --git a/tests/indent/python/strings.py b/tests/indent/python/strings.py new file mode 100644 index 00000000..0eb088fa --- /dev/null +++ b/tests/indent/python/strings.py @@ -0,0 +1,17 @@ +a = """ + String A +""" + +b = """ +String B +""" + +c = """ + String C + """ + +d = """ + String D +String D + String D + """ diff --git a/tests/indent/python_spec.lua b/tests/indent/python_spec.lua new file mode 100644 index 00000000..7a058af5 --- /dev/null +++ b/tests/indent/python_spec.lua @@ -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) diff --git a/tests/indent/rust/array.rs b/tests/indent/rust/array.rs new file mode 100644 index 00000000..68344e0e --- /dev/null +++ b/tests/indent/rust/array.rs @@ -0,0 +1,11 @@ +const X: [i32; 2] = [ + 1, + 2, +]; + +fn foo() { + let _x = [ + 1, + 2, + ]; +} diff --git a/tests/indent/rust/comment.rs b/tests/indent/rust/comment.rs new file mode 100644 index 00000000..334793df --- /dev/null +++ b/tests/indent/rust/comment.rs @@ -0,0 +1,7 @@ +/// Function foo +/// +/// Description of +/// function foo. +fn foo(x: i32, y: i32) -> i32 { + x + y +} diff --git a/tests/indent/rust/cond.rs b/tests/indent/rust/cond.rs new file mode 100644 index 00000000..eb96a48f --- /dev/null +++ b/tests/indent/rust/cond.rs @@ -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 +} diff --git a/tests/indent/rust/enum.rs b/tests/indent/rust/enum.rs new file mode 100644 index 00000000..996f07d2 --- /dev/null +++ b/tests/indent/rust/enum.rs @@ -0,0 +1,11 @@ +enum Foo { + X, + Y( + char, + char, + ), + Z { + x: u32, + y: u32, + }, +} diff --git a/tests/indent/rust/func.rs b/tests/indent/rust/func.rs new file mode 100644 index 00000000..4c9d40b2 --- /dev/null +++ b/tests/indent/rust/func.rs @@ -0,0 +1,10 @@ +fn foo() -> i32 { + 1 +} + +fn foo( + x: i32, + y: i32 +) -> i32 { + x + y +} diff --git a/tests/indent/rust/impl.rs b/tests/indent/rust/impl.rs new file mode 100644 index 00000000..2525c2e5 --- /dev/null +++ b/tests/indent/rust/impl.rs @@ -0,0 +1,7 @@ +struct Foo; + +impl Foo { + fn foo() -> i32 { + 1 + } +} diff --git a/tests/indent/rust/loop.rs b/tests/indent/rust/loop.rs new file mode 100644 index 00000000..eb845bc0 --- /dev/null +++ b/tests/indent/rust/loop.rs @@ -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; + } +} diff --git a/tests/indent/rust/macro.rs b/tests/indent/rust/macro.rs new file mode 100644 index 00000000..608e157f --- /dev/null +++ b/tests/indent/rust/macro.rs @@ -0,0 +1,13 @@ +macro_rules! foo { + ($a:ident, $b:ident, $c:ident) => { + struct $a; + struct $b; + }, + ($a:ident) => { + struct $a; + }, +} + +foo! { + A +} diff --git a/tests/indent/rust/match.rs b/tests/indent/rust/match.rs new file mode 100644 index 00000000..438ba6d5 --- /dev/null +++ b/tests/indent/rust/match.rs @@ -0,0 +1,11 @@ +fn foo(x: i32) -> i32 { + match x { + 0 => 1, + 1 => { + 2 + }, + 2 | 3 => { + 4 + } + } +} diff --git a/tests/indent/rust/mod.rs b/tests/indent/rust/mod.rs new file mode 100644 index 00000000..cc7f2c8e --- /dev/null +++ b/tests/indent/rust/mod.rs @@ -0,0 +1,8 @@ +mod foo { + const X: i32 = 1; + + mod bar { + + const Y: i32 = 1; + } +} diff --git a/tests/indent/rust/string.rs b/tests/indent/rust/string.rs new file mode 100644 index 00000000..4d60663d --- /dev/null +++ b/tests/indent/rust/string.rs @@ -0,0 +1,12 @@ +fn foo() { + let a = "hello +world"; + + let b = "hello\ + world"; + + let c = r#" + hello + world + "#; +} diff --git a/tests/indent/rust/struct.rs b/tests/indent/rust/struct.rs new file mode 100644 index 00000000..f3828977 --- /dev/null +++ b/tests/indent/rust/struct.rs @@ -0,0 +1,4 @@ +struct Foo { + x: u32, + y: u32, +} diff --git a/tests/indent/rust/trait.rs b/tests/indent/rust/trait.rs new file mode 100644 index 00000000..fb5fc7ea --- /dev/null +++ b/tests/indent/rust/trait.rs @@ -0,0 +1,11 @@ +struct Foo; + +trait Bar { + fn bar(); +} + +impl Bar for Foo { + fn bar() { + + } +} diff --git a/tests/indent/rust/where.rs b/tests/indent/rust/where.rs new file mode 100644 index 00000000..08c1b196 --- /dev/null +++ b/tests/indent/rust/where.rs @@ -0,0 +1,21 @@ +fn foo(t: T) -> i32 +where + T: Debug, +{ + 1 +} + +fn foo(t: T) -> i32 where + T: Debug, +{ + 1 +} + +struct Foo(T); + +impl Write for Foo +where + T: Debug, +{ + +} diff --git a/tests/indent/rust_spec.lua b/tests/indent/rust_spec.lua new file mode 100644 index 00000000..c3ffe3fd --- /dev/null +++ b/tests/indent/rust_spec.lua @@ -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) -- cgit v1.2.3