aboutsummaryrefslogtreecommitdiffstats
path: root/lua/tests
diff options
context:
space:
mode:
authorJędrzej Boczar <yendreij@gmail.com>2021-04-17 22:47:02 +0200
committerKiyan <yazdani.kiyan@protonmail.com>2021-04-23 21:21:38 +0200
commit15f0813b6e0682e3f2c3b611610f6ef67cc87449 (patch)
tree80d795bb93249c432980164dda51f5a5267425cd /lua/tests
parenttests/indent: refactor indent test runner and auto-discover language test files (diff)
downloadnvim-treesitter-15f0813b6e0682e3f2c3b611610f6ef67cc87449.tar
nvim-treesitter-15f0813b6e0682e3f2c3b611610f6ef67cc87449.tar.gz
nvim-treesitter-15f0813b6e0682e3f2c3b611610f6ef67cc87449.tar.bz2
nvim-treesitter-15f0813b6e0682e3f2c3b611610f6ef67cc87449.tar.lz
nvim-treesitter-15f0813b6e0682e3f2c3b611610f6ef67cc87449.tar.xz
nvim-treesitter-15f0813b6e0682e3f2c3b611610f6ef67cc87449.tar.zst
nvim-treesitter-15f0813b6e0682e3f2c3b611610f6ef67cc87449.zip
tests/indent: add multiple C/C++ tests
Diffstat (limited to 'lua/tests')
-rw-r--r--lua/tests/indent/c/array.c14
-rw-r--r--lua/tests/indent/c/basic.c11
-rw-r--r--lua/tests/indent/c/comment.c8
-rw-r--r--lua/tests/indent/c/cond.c10
-rw-r--r--lua/tests/indent/c/enum.c5
-rw-r--r--lua/tests/indent/c/expr.c12
-rw-r--r--lua/tests/indent/c/func.c33
-rw-r--r--lua/tests/indent/c/label.c7
-rw-r--r--lua/tests/indent/c/loop.c16
-rw-r--r--lua/tests/indent/c/no_braces.c6
-rw-r--r--lua/tests/indent/c/preproc_cond.c10
-rw-r--r--lua/tests/indent/c/preproc_func.c9
-rw-r--r--lua/tests/indent/c/string.c5
-rw-r--r--lua/tests/indent/c/struct.c11
-rw-r--r--lua/tests/indent/c/switch.c16
-rw-r--r--lua/tests/indent/c/ternary.c6
-rw-r--r--lua/tests/indent/cpp/access.cpp6
-rw-r--r--lua/tests/indent/cpp/class.cpp7
-rw-r--r--lua/tests/indent/cpp/stream.cpp7
-rw-r--r--lua/tests/indent/cpp_spec.lua23
20 files changed, 211 insertions, 11 deletions
diff --git a/lua/tests/indent/c/array.c b/lua/tests/indent/c/array.c
new file mode 100644
index 000000000..5bb67c2c8
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/basic.c b/lua/tests/indent/c/basic.c
deleted file mode 100644
index b20b742d5..000000000
--- a/lua/tests/indent/c/basic.c
+++ /dev/null
@@ -1,11 +0,0 @@
-int foo(int x)
-{
- if (x > 10) {
- return x;
- } else {
- while (x > 0) {
- x--;
- }
- return 0;
- }
-}
diff --git a/lua/tests/indent/c/comment.c b/lua/tests/indent/c/comment.c
new file mode 100644
index 000000000..b32de8218
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/cond.c b/lua/tests/indent/c/cond.c
new file mode 100644
index 000000000..1ecb22d98
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/enum.c b/lua/tests/indent/c/enum.c
new file mode 100644
index 000000000..bb6b0dc30
--- /dev/null
+++ b/lua/tests/indent/c/enum.c
@@ -0,0 +1,5 @@
+enum foo {
+ A = 1,
+ B,
+ C,
+};
diff --git a/lua/tests/indent/c/expr.c b/lua/tests/indent/c/expr.c
new file mode 100644
index 000000000..cafb11120
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/func.c b/lua/tests/indent/c/func.c
new file mode 100644
index 000000000..c188acc01
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/label.c b/lua/tests/indent/c/label.c
new file mode 100644
index 000000000..36b40e23a
--- /dev/null
+++ b/lua/tests/indent/c/label.c
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 000000000..facaebb6b
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/no_braces.c b/lua/tests/indent/c/no_braces.c
index 4c14ab05f..544ac01d0 100644
--- a/lua/tests/indent/c/no_braces.c
+++ b/lua/tests/indent/c/no_braces.c
@@ -3,4 +3,10 @@ int foo(int x) {
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
new file mode 100644
index 000000000..b85440aa9
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/preproc_func.c b/lua/tests/indent/c/preproc_func.c
new file mode 100644
index 000000000..f1f38feb9
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/string.c b/lua/tests/indent/c/string.c
new file mode 100644
index 000000000..2d5177e00
--- /dev/null
+++ b/lua/tests/indent/c/string.c
@@ -0,0 +1,5 @@
+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
new file mode 100644
index 000000000..8cc2b6b21
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/switch.c b/lua/tests/indent/c/switch.c
new file mode 100644
index 000000000..4003bdb1d
--- /dev/null
+++ b/lua/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/lua/tests/indent/c/ternary.c b/lua/tests/indent/c/ternary.c
new file mode 100644
index 000000000..2e40b382e
--- /dev/null
+++ b/lua/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/lua/tests/indent/cpp/access.cpp b/lua/tests/indent/cpp/access.cpp
new file mode 100644
index 000000000..abdb846ce
--- /dev/null
+++ b/lua/tests/indent/cpp/access.cpp
@@ -0,0 +1,6 @@
+class Foo {
+public:
+ int x;
+private:
+ int y;
+};
diff --git a/lua/tests/indent/cpp/class.cpp b/lua/tests/indent/cpp/class.cpp
new file mode 100644
index 000000000..cd8382190
--- /dev/null
+++ b/lua/tests/indent/cpp/class.cpp
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 000000000..a619dfa69
--- /dev/null
+++ b/lua/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/lua/tests/indent/cpp_spec.lua b/lua/tests/indent/cpp_spec.lua
new file mode 100644
index 000000000..a785de5b5
--- /dev/null
+++ b/lua/tests/indent/cpp_spec.lua
@@ -0,0 +1,23 @@
+local whole_file = require('nvim-treesitter.test_utils').indent_whole_file
+local scan_dir = require('plenary.scandir').scan_dir
+local Path = require('plenary.path')
+
+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
+ local name = Path:new(file):make_relative('lua/tests/indent')
+ it(name, function()
+ whole_file(file, {
+ tabstop = 4,
+ shiftwidth = 4,
+ softtabstop = 0,
+ expandtab = true,
+ filetype = 'cpp',
+ })
+ end)
+ end
+ end)
+end)