mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
tests/indent: add multiple C/C++ tests
This commit is contained in:
parent
77c97d0f8b
commit
15f0813b6e
20 changed files with 211 additions and 11 deletions
14
lua/tests/indent/c/array.c
Normal file
14
lua/tests/indent/c/array.c
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
int x[] = {
|
||||||
|
1, 2, 3,
|
||||||
|
4, 5,
|
||||||
|
6
|
||||||
|
};
|
||||||
|
|
||||||
|
int y[][2] = {
|
||||||
|
{0, 1},
|
||||||
|
{1, 2},
|
||||||
|
{
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
int foo(int x)
|
|
||||||
{
|
|
||||||
if (x > 10) {
|
|
||||||
return x;
|
|
||||||
} else {
|
|
||||||
while (x > 0) {
|
|
||||||
x--;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8
lua/tests/indent/c/comment.c
Normal file
8
lua/tests/indent/c/comment.c
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Function foo
|
||||||
|
* @param[out] x output
|
||||||
|
* @param[in] x input
|
||||||
|
*/
|
||||||
|
void foo(int *x, int y) {
|
||||||
|
*x = y;
|
||||||
|
}
|
||||||
10
lua/tests/indent/c/cond.c
Normal file
10
lua/tests/indent/c/cond.c
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
void foo(int x)
|
||||||
|
{
|
||||||
|
if (x > 10) {
|
||||||
|
return;
|
||||||
|
} else if (x < -10) {
|
||||||
|
x = -10;
|
||||||
|
} else {
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
}
|
||||||
5
lua/tests/indent/c/enum.c
Normal file
5
lua/tests/indent/c/enum.c
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
enum foo {
|
||||||
|
A = 1,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
};
|
||||||
12
lua/tests/indent/c/expr.c
Normal file
12
lua/tests/indent/c/expr.c
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
void foo(int x, int y)
|
||||||
|
{
|
||||||
|
if ((x*x - y*y > 0) ||
|
||||||
|
(x == 1 || y == 1) &&
|
||||||
|
(x != 2 && y != 2)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int z = (x + y) *
|
||||||
|
(x - y);
|
||||||
|
}
|
||||||
33
lua/tests/indent/c/func.c
Normal file
33
lua/tests/indent/c/func.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
int f1(int x) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int f2(int x)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int f3(
|
||||||
|
int x
|
||||||
|
) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int f4(
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int f5(int x,
|
||||||
|
int y)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
f6(int x, int y)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
7
lua/tests/indent/c/label.c
Normal file
7
lua/tests/indent/c/label.c
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
int foo(int x)
|
||||||
|
{
|
||||||
|
goto error;
|
||||||
|
return 0;
|
||||||
|
error:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
16
lua/tests/indent/c/loop.c
Normal file
16
lua/tests/indent/c/loop.c
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
void foo(int x)
|
||||||
|
{
|
||||||
|
while (x > 0) {
|
||||||
|
x--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
x++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
x++;
|
||||||
|
} while (x < 0);
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,10 @@ int foo(int x) {
|
||||||
return 10;
|
return 10;
|
||||||
else
|
else
|
||||||
return x;
|
return x;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
x++;
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
x--;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
lua/tests/indent/c/preproc_cond.c
Normal file
10
lua/tests/indent/c/preproc_cond.c
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
void foo(int x)
|
||||||
|
{
|
||||||
|
x = x + 1;
|
||||||
|
#if 1
|
||||||
|
x = x + 2;
|
||||||
|
#else
|
||||||
|
x = x + 3;
|
||||||
|
#endif
|
||||||
|
x = x + 4;
|
||||||
|
}
|
||||||
9
lua/tests/indent/c/preproc_func.c
Normal file
9
lua/tests/indent/c/preproc_func.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#define FOO(x) do { \
|
||||||
|
x = x + 1; \
|
||||||
|
x = x / 2; \
|
||||||
|
} while (x > 0);
|
||||||
|
|
||||||
|
void foo(int x)
|
||||||
|
{
|
||||||
|
FOO(x);
|
||||||
|
}
|
||||||
5
lua/tests/indent/c/string.c
Normal file
5
lua/tests/indent/c/string.c
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
const char *a = "hello \
|
||||||
|
world";
|
||||||
|
|
||||||
|
const char *b = "hello "
|
||||||
|
"world";
|
||||||
11
lua/tests/indent/c/struct.c
Normal file
11
lua/tests/indent/c/struct.c
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
struct foo {
|
||||||
|
int a;
|
||||||
|
struct bar {
|
||||||
|
int x;
|
||||||
|
} b;
|
||||||
|
};
|
||||||
|
|
||||||
|
union baz {
|
||||||
|
struct foo;
|
||||||
|
int x;
|
||||||
|
};
|
||||||
16
lua/tests/indent/c/switch.c
Normal file
16
lua/tests/indent/c/switch.c
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
void foo(int x) {
|
||||||
|
switch (x) {
|
||||||
|
case 1:
|
||||||
|
x += 1;
|
||||||
|
break;
|
||||||
|
case 2: x += 2;
|
||||||
|
break;
|
||||||
|
case 3: x += 3; break;
|
||||||
|
case 4: {
|
||||||
|
x += 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
}
|
||||||
6
lua/tests/indent/c/ternary.c
Normal file
6
lua/tests/indent/c/ternary.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
void foo(int x)
|
||||||
|
{
|
||||||
|
int y = (x > 10) ? 10
|
||||||
|
: (x < -10) ? -10
|
||||||
|
: x;
|
||||||
|
}
|
||||||
6
lua/tests/indent/cpp/access.cpp
Normal file
6
lua/tests/indent/cpp/access.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
int x;
|
||||||
|
private:
|
||||||
|
int y;
|
||||||
|
};
|
||||||
7
lua/tests/indent/cpp/class.cpp
Normal file
7
lua/tests/indent/cpp/class.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
class Foo {
|
||||||
|
int x;
|
||||||
|
class Bar {
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
Bar z;
|
||||||
|
};
|
||||||
7
lua/tests/indent/cpp/stream.cpp
Normal file
7
lua/tests/indent/cpp/stream.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void foo(int x) {
|
||||||
|
std::cout << x
|
||||||
|
<< x + 1
|
||||||
|
<< x + 2;
|
||||||
|
}
|
||||||
23
lua/tests/indent/cpp_spec.lua
Normal file
23
lua/tests/indent/cpp_spec.lua
Normal file
|
|
@ -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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue