tests/indent: add multiple C/C++ tests

This commit is contained in:
Jędrzej Boczar 2021-04-17 22:47:02 +02:00 committed by Kiyan
parent 77c97d0f8b
commit 15f0813b6e
20 changed files with 211 additions and 11 deletions

View file

@ -0,0 +1,14 @@
int x[] = {
1, 2, 3,
4, 5,
6
};
int y[][2] = {
{0, 1},
{1, 2},
{
2,
3
},
};

View file

@ -1,11 +0,0 @@
int foo(int x)
{
if (x > 10) {
return x;
} else {
while (x > 0) {
x--;
}
return 0;
}
}

View 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
View file

@ -0,0 +1,10 @@
void foo(int x)
{
if (x > 10) {
return;
} else if (x < -10) {
x = -10;
} else {
x = -x;
}
}

View file

@ -0,0 +1,5 @@
enum foo {
A = 1,
B,
C,
};

12
lua/tests/indent/c/expr.c Normal file
View 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
View 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;
}

View 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
View 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);
}

View file

@ -3,4 +3,10 @@ int foo(int x) {
return 10;
else
return x;
while (1)
x++;
for (int i = 0; i < 3; ++i)
x--;
}

View 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;
}

View file

@ -0,0 +1,9 @@
#define FOO(x) do { \
x = x + 1; \
x = x / 2; \
} while (x > 0);
void foo(int x)
{
FOO(x);
}

View file

@ -0,0 +1,5 @@
const char *a = "hello \
world";
const char *b = "hello "
"world";

View file

@ -0,0 +1,11 @@
struct foo {
int a;
struct bar {
int x;
} b;
};
union baz {
struct foo;
int x;
};

View 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;
}
}

View file

@ -0,0 +1,6 @@
void foo(int x)
{
int y = (x > 10) ? 10
: (x < -10) ? -10
: x;
}

View file

@ -0,0 +1,6 @@
class Foo {
public:
int x;
private:
int y;
};

View file

@ -0,0 +1,7 @@
class Foo {
int x;
class Bar {
int y;
};
Bar z;
};

View file

@ -0,0 +1,7 @@
#include <iostream>
void foo(int x) {
std::cout << x
<< x + 1
<< x + 2;
}

View 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)