aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJędrzej Boczar <yendreij@gmail.com>2021-04-22 20:53:30 +0200
committerKiyan <yazdani.kiyan@protonmail.com>2021-04-23 21:21:38 +0200
commit63a88c873f3643aad9208488765dc53618edd40e (patch)
treefb233a54b0dae8a6af1a12dfecb9cd85cbdb4f64 /tests
parentignore Lua indent test files when doing style-check (diff)
downloadnvim-treesitter-63a88c873f3643aad9208488765dc53618edd40e.tar
nvim-treesitter-63a88c873f3643aad9208488765dc53618edd40e.tar.gz
nvim-treesitter-63a88c873f3643aad9208488765dc53618edd40e.tar.bz2
nvim-treesitter-63a88c873f3643aad9208488765dc53618edd40e.tar.lz
nvim-treesitter-63a88c873f3643aad9208488765dc53618edd40e.tar.xz
nvim-treesitter-63a88c873f3643aad9208488765dc53618edd40e.tar.zst
nvim-treesitter-63a88c873f3643aad9208488765dc53618edd40e.zip
move all tests to top-level tests/ directory
Diffstat (limited to 'tests')
-rw-r--r--tests/indent/c/array.c14
-rw-r--r--tests/indent/c/comment.c8
-rw-r--r--tests/indent/c/cond.c10
-rw-r--r--tests/indent/c/enum.c5
-rw-r--r--tests/indent/c/expr.c12
-rw-r--r--tests/indent/c/func.c33
-rw-r--r--tests/indent/c/label.c7
-rw-r--r--tests/indent/c/loop.c16
-rw-r--r--tests/indent/c/no_braces.c12
-rw-r--r--tests/indent/c/preproc_cond.c10
-rw-r--r--tests/indent/c/preproc_func.c9
-rw-r--r--tests/indent/c/string.c5
-rw-r--r--tests/indent/c/struct.c11
-rw-r--r--tests/indent/c/switch.c16
-rw-r--r--tests/indent/c/ternary.c6
-rw-r--r--tests/indent/c_spec.lua49
-rw-r--r--tests/indent/cpp/access.cpp6
-rw-r--r--tests/indent/cpp/class.cpp7
-rw-r--r--tests/indent/cpp/stream.cpp7
-rw-r--r--tests/indent/cpp_spec.lua62
-rw-r--r--tests/indent/lua/comment.lua7
-rw-r--r--tests/indent/lua/cond.lua12
-rw-r--r--tests/indent/lua/func.lua9
-rw-r--r--tests/indent/lua/loop.lua14
-rw-r--r--tests/indent/lua/string.lua5
-rw-r--r--tests/indent/lua/table.lua10
-rw-r--r--tests/indent/lua_spec.lua48
-rw-r--r--tests/indent/python/aligned_indent.py11
-rw-r--r--tests/indent/python/basic_blocks.py14
-rw-r--r--tests/indent/python/basic_collections.py23
-rw-r--r--tests/indent/python/branches.py27
-rw-r--r--tests/indent/python/comprehensions.py25
-rw-r--r--tests/indent/python/control_flow.py22
-rw-r--r--tests/indent/python/hanging_indent.py6
-rw-r--r--tests/indent/python/join_lines.py8
-rw-r--r--tests/indent/python/nested_collections.py41
-rw-r--r--tests/indent/python/strings.py17
-rw-r--r--tests/indent/python_spec.lua52
-rw-r--r--tests/indent/rust/array.rs11
-rw-r--r--tests/indent/rust/comment.rs7
-rw-r--r--tests/indent/rust/cond.rs17
-rw-r--r--tests/indent/rust/enum.rs11
-rw-r--r--tests/indent/rust/func.rs10
-rw-r--r--tests/indent/rust/impl.rs7
-rw-r--r--tests/indent/rust/loop.rs19
-rw-r--r--tests/indent/rust/macro.rs13
-rw-r--r--tests/indent/rust/match.rs11
-rw-r--r--tests/indent/rust/mod.rs8
-rw-r--r--tests/indent/rust/string.rs12
-rw-r--r--tests/indent/rust/struct.rs4
-rw-r--r--tests/indent/rust/trait.rs11
-rw-r--r--tests/indent/rust/where.rs21
-rw-r--r--tests/indent/rust_spec.lua67
53 files changed, 885 insertions, 0 deletions
diff --git a/tests/indent/c/array.c b/tests/indent/c/array.c
new file mode 100644
index 000000000..5bb67c2c8
--- /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 000000000..b32de8218
--- /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 000000000..1ecb22d98
--- /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 000000000..bb6b0dc30
--- /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 000000000..cafb11120
--- /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 000000000..c188acc01
--- /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 000000000..36b40e23a
--- /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 000000000..facaebb6b
--- /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 000000000..544ac01d0
--- /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 000000000..b85440aa9
--- /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 000000000..f1f38feb9
--- /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 000000000..2d5177e00
--- /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 000000000..8cc2b6b21
--- /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 000000000..4003bdb1d
--- /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 000000000..2e40b382e
--- /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 000000000..98311c772
--- /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 000000000..abdb846ce
--- /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 000000000..cd8382190
--- /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 000000000..a619dfa69
--- /dev/null
+++ b/tests/indent/cpp/stream.cpp
@@ -0,0 +1,7 @@
+#include <iostream>
+
+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 000000000..d3c98401c
--- /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 000000000..9f3624e1e
--- /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 000000000..dfae37f05
--- /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 000000000..1f95ca97a
--- /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 000000000..7f5402d1e
--- /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 000000000..adfebf76a
--- /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 000000000..d53504b45
--- /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 000000000..473f584c4
--- /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 000000000..2a4b827f4
--- /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 000000000..4f36359bd
--- /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 000000000..1582b9059
--- /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 000000000..7ce106bd7
--- /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 000000000..53c3961e1
--- /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 000000000..c8cd2541b
--- /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 000000000..4d46ebed0
--- /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 000000000..491b2cc37
--- /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 000000000..292a65a00
--- /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 000000000..0eb088fa6
--- /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 000000000..7a058af55
--- /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 000000000..68344e0ee
--- /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 000000000..334793dfa
--- /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 000000000..eb96a48f7
--- /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 000000000..996f07d21
--- /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 000000000..4c9d40b26
--- /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 000000000..2525c2e5b
--- /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 000000000..eb845bc0f
--- /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 000000000..608e157fc
--- /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 000000000..438ba6d5f
--- /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 000000000..cc7f2c8e6
--- /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 000000000..4d60663dd
--- /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 000000000..f3828977f
--- /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 000000000..fb5fc7ea8
--- /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 000000000..08c1b196d
--- /dev/null
+++ b/tests/indent/rust/where.rs
@@ -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,
+{
+
+}
diff --git a/tests/indent/rust_spec.lua b/tests/indent/rust_spec.lua
new file mode 100644
index 000000000..c3ffe3fdf
--- /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)