Reorganize tests into a real spec suite

This commit is contained in:
2024-08-04 19:18:43 -03:00
parent 57c160173c
commit e7c2053222
693 changed files with 136 additions and 116 deletions

View File

@ -0,0 +1,13 @@
---input---
__int128
_BitInt(2)
---tokens---
'__int128' Keyword.Type
'\n' Text.Whitespace
'_BitInt' Keyword.Type
'(' Punctuation
'2' Literal.Number.Integer
')' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,31 @@
In the past the "*/" was marked as an error to "helpfully"
indicate a wrong comment end.
---input---
int m21=((result_0*0+result_1*/*0<-----*/1)%mod+mod)%mod;
---tokens---
'int' Keyword.Type
' ' Text.Whitespace
'm21' Name
'=' Operator
'(' Punctuation
'(' Punctuation
'result_0' Name
'*' Operator
'0' Literal.Number.Integer
'+' Operator
'result_1' Name
'*' Operator
'/*0<-----*/' Comment.Multiline
'1' Literal.Number.Integer
')' Punctuation
'%' Operator
'mod' Name
'+' Operator
'mod' Name
')' Punctuation
'%' Operator
'mod' Name
';' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,409 @@
---input---
int func1(int x, int y)
/*@requires y >= 0*/
{
return x / y;
}
int func2(int x, int y) //@requires y >= 0;
{
return x / y;
}
void func3()
//#test{};
{
fun(2,3)//test1;
;
}
int func4(int x, int y)
/*@requires y >= 0;*/
{
return x / y;
}
int func5(int x, int y)
/*@requires y >= 0
{
return x / y;
}
*/
{
return 2;
}
//@requires y >= 0;
//@requires y >= 0
/*
calling(2,5)
*/
/*
calling(2,5);
*/
int func6(int x, int y)
//@requires y >= 0
//@requires y >= 0;
/*
hello(2,3);
*/
/*
hello(2,3)
*/
{
// haha(2,3);
return x / y;
/*
callblabla(x, y);
*/
}
//@requires y >= 0;
//@requires y >= 0
/*
calling(2,5)
*/
/*
calling(2,5);
*/
int * //@# a pointer to int
func7 /* @# why a comment here? */ (
int /* the index has to be an int */ a, // index into the array
int *b //the array @!
)
/*
The end of the func params @ (@ will result error if parsed incorrectly)
*/
{
// yet another comment
return b[a];
}
---tokens---
'int' Keyword.Type
' ' Text.Whitespace
'func1' Name.Function
'(' Punctuation
'int' Keyword.Type
' ' Text.Whitespace
'x' Name
',' Punctuation
' ' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'y' Name
')' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'/*@requires y >= 0*/' Comment.Multiline
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'return' Keyword
' ' Text.Whitespace
'x' Name
' ' Text.Whitespace
'/' Operator
' ' Text.Whitespace
'y' Name
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'\n' Text.Whitespace
'\n' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'func2' Name.Function
'(' Punctuation
'int' Keyword.Type
' ' Text.Whitespace
'x' Name
',' Punctuation
' ' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'y' Name
')' Punctuation
' ' Text.Whitespace
'//@requires y >= 0;\n' Comment.Single
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'return' Keyword
' ' Text.Whitespace
'x' Name
' ' Text.Whitespace
'/' Operator
' ' Text.Whitespace
'y' Name
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'\n' Text.Whitespace
'\n' Text.Whitespace
'void' Keyword.Type
' ' Text.Whitespace
'func3' Name.Function
'(' Punctuation
')' Punctuation
'\n' Text.Whitespace
'//#test{};\n' Comment.Single
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'fun' Name
'(' Punctuation
'2' Literal.Number.Integer
',' Punctuation
'3' Literal.Number.Integer
')' Punctuation
'//test1;\n' Comment.Single
' ' Text.Whitespace
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'\n' Text.Whitespace
'\n' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'func4' Name.Function
'(' Punctuation
'int' Keyword.Type
' ' Text.Whitespace
'x' Name
',' Punctuation
' ' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'y' Name
')' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'/*@requires y >= 0;*/' Comment.Multiline
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'return' Keyword
' ' Text.Whitespace
'x' Name
' ' Text.Whitespace
'/' Operator
' ' Text.Whitespace
'y' Name
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'\n' Text.Whitespace
'\n' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'func5' Name.Function
'(' Punctuation
'int' Keyword.Type
' ' Text.Whitespace
'x' Name
',' Punctuation
' ' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'y' Name
')' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'/*@requires y >= 0\n {\n return x / y;\n }\n */' Comment.Multiline
'\n' Text.Whitespace
' ' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'return' Keyword
' ' Text.Whitespace
'2' Literal.Number.Integer
';' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'\n' Text.Whitespace
'\n' Text.Whitespace
'//@requires y >= 0;\n' Comment.Single
'//@requires y >= 0\n' Comment.Single
'/*\ncalling(2,5)\n*/' Comment.Multiline
'\n' Text.Whitespace
'/*\ncalling(2,5);\n*/' Comment.Multiline
'\n' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'func6' Name.Function
'(' Punctuation
'int' Keyword.Type
' ' Text.Whitespace
'x' Name
',' Punctuation
' ' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'y' Name
')' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'//@requires y >= 0\n' Comment.Single
' ' Text.Whitespace
'//@requires y >= 0;\n' Comment.Single
' ' Text.Whitespace
'/*\n hello(2,3);\n */' Comment.Multiline
'\n' Text.Whitespace
' ' Text.Whitespace
'/*\n hello(2,3)\n */' Comment.Multiline
'\n' Text.Whitespace
' ' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'// haha(2,3);\n' Comment.Single
' ' Text.Whitespace
'return' Keyword
' ' Text.Whitespace
'x' Name
' ' Text.Whitespace
'/' Operator
' ' Text.Whitespace
'y' Name
';' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'/*\n callblabla(x, y);\n */' Comment.Multiline
'\n' Text.Whitespace
' ' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'//@requires y >= 0;\n' Comment.Single
'//@requires y >= 0\n' Comment.Single
'/*\ncalling(2,5)\n*/' Comment.Multiline
'\n' Text.Whitespace
'/*\ncalling(2,5);\n*/' Comment.Multiline
'\n' Text.Whitespace
'\n' Text.Whitespace
'\n' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'*' Operator
' ' Text.Whitespace
'//@# a pointer to int\n' Comment.Single
'func7' Name.Function
' ' Text.Whitespace
'/* @# why a comment here? */' Comment.Multiline
' ' Text.Whitespace
'(' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'/* the index has to be an int */' Comment.Multiline
' ' Text.Whitespace
'a' Name
',' Punctuation
' ' Text.Whitespace
'// index into the array\n' Comment.Single
' ' Text.Whitespace
'int' Keyword.Type
' ' Text.Whitespace
'*' Operator
'b' Name
' ' Text.Whitespace
'//the array @!\n' Comment.Single
')' Punctuation
'\n' Text.Whitespace
'/*\n The end of the func params @ (@ will result error if parsed incorrectly)\n*/' Comment.Multiline
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'// yet another comment\n' Comment.Single
' ' Text.Whitespace
'return' Keyword
' ' Text.Whitespace
'b' Name
'[' Punctuation
'a' Name
']' Punctuation
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,31 @@
---input---
int main()
{
foo:
goto foo;
}
---tokens---
'int' Keyword.Type
' ' Text.Whitespace
'main' Name.Function
'(' Punctuation
')' Punctuation
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
'foo' Name.Label
':' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'goto' Keyword
' ' Text.Whitespace
'foo' Name
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,35 @@
---input---
int main()
{
foo:return 0;
goto foo;
}
---tokens---
'int' Keyword.Type
' ' Text.Whitespace
'main' Name.Function
'(' Punctuation
')' Punctuation
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
'foo' Name.Label
':' Punctuation
'return' Keyword
' ' Text.Whitespace
'0' Literal.Number.Integer
';' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'goto' Keyword
' ' Text.Whitespace
'foo' Name
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,32 @@
---input---
int main()
{
foo :
goto foo;
}
---tokens---
'int' Keyword.Type
' ' Text.Whitespace
'main' Name.Function
'(' Punctuation
')' Punctuation
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
'foo' Name.Label
' ' Text.Whitespace
':' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'goto' Keyword
' ' Text.Whitespace
'foo' Name
';' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,20 @@
---input---
42 23.42 23. .42 023 0xdeadbeef 23e+42 42e-23
---tokens---
'42' Literal.Number.Integer
' ' Text.Whitespace
'23.42' Literal.Number.Float
' ' Text.Whitespace
'23.' Literal.Number.Float
' ' Text.Whitespace
'.42' Literal.Number.Float
' ' Text.Whitespace
'023' Literal.Number.Oct
' ' Text.Whitespace
'0xdeadbeef' Literal.Number.Hex
' ' Text.Whitespace
'23e+42' Literal.Number.Float
' ' Text.Whitespace
'42e-23' Literal.Number.Float
'\n' Text.Whitespace

View File

@ -0,0 +1,17 @@
---input---
#include <foo>
# include <foo>
---tokens---
'#' Comment.Preproc
'include' Comment.Preproc
' ' Text.Whitespace
'<foo>' Comment.PreprocFile
'\n' Comment.Preproc
'#' Comment.Preproc
' ' Text.Whitespace
'include' Comment.Preproc
' ' Text.Whitespace
'<foo>' Comment.PreprocFile
'\n' Comment.Preproc

View File

@ -0,0 +1,17 @@
---input---
#include "foo.h"
# include "foo.h"
---tokens---
'#' Comment.Preproc
'include' Comment.Preproc
' ' Text.Whitespace
'"foo.h"' Comment.PreprocFile
'\n' Comment.Preproc
'#' Comment.Preproc
' ' Text.Whitespace
'include' Comment.Preproc
' ' Text.Whitespace
'"foo.h"' Comment.PreprocFile
'\n' Comment.Preproc

View File

@ -0,0 +1,18 @@
Space around line break before macro is valid C, but failed to parse previously.
---input---
foo();
#define FOO 0
---tokens---
'foo' Name
'(' Punctuation
')' Punctuation
';' Punctuation
' ' Text.Whitespace
'\n' Text.Whitespace
' ' Text.Whitespace
'#' Comment.Preproc
'define FOO 0' Comment.Preproc
'\n' Comment.Preproc

View File

@ -0,0 +1,13 @@
Comments can precede preprocessor macros
---input---
/* Comment */ /* Another */ #define FOO 0
---tokens---
'/* Comment */' Comment.Multiline
' ' Text.Whitespace
'/* Another */' Comment.Multiline
' ' Text.Whitespace
'#' Comment.Preproc
'define FOO 0' Comment.Preproc
'\n' Comment.Preproc

View File

@ -0,0 +1,19 @@
Preprocessor macros should appear only at the beginning of the line.
Otherwise we should produce an error token.
---input---
foo(); #define FOO 0
---tokens---
'foo' Name
'(' Punctuation
')' Punctuation
';' Punctuation
' ' Text.Whitespace
'#' Error
'define' Name
' ' Text.Whitespace
'FOO' Name
' ' Text.Whitespace
'0' Literal.Number.Integer
'\n' Text.Whitespace

View File

@ -0,0 +1,41 @@
---input---
// This should not be recognized as a function declaration followed by
// garbage.
string xyz(");");
// This should not be recognized as a function definition.
string xyz("){ }");
---tokens---
'// This should not be recognized as a function declaration followed by\n' Comment.Single
'// garbage.\n' Comment.Single
'string' Name
' ' Text.Whitespace
'xyz' Name
'(' Punctuation
'"' Literal.String
');' Literal.String
'"' Literal.String
')' Punctuation
';' Punctuation
'\n' Text.Whitespace
'\n' Text.Whitespace
'// This should not be recognized as a function definition.\n' Comment.Single
'\n' Text.Whitespace
'string' Name
' ' Text.Whitespace
'xyz' Name
'(' Punctuation
'"' Literal.String
'){ }' Literal.String
'"' Literal.String
')' Punctuation
';' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,56 @@
---input---
int main()
{
switch (0)
{
case 0:
default:
;
}
}
---tokens---
'int' Keyword.Type
' ' Text.Whitespace
'main' Name.Function
'(' Punctuation
')' Punctuation
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'switch' Keyword
' ' Text.Whitespace
'(' Punctuation
'0' Literal.Number.Integer
')' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'case' Keyword
' ' Text.Whitespace
'0' Literal.Number.Integer
':' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'default' Keyword
':' Operator
'\n' Text.Whitespace
' ' Text.Whitespace
';' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace

View File

@ -0,0 +1,58 @@
---input---
int main()
{
switch (0)
{
case 0 :
default :
;
}
}
---tokens---
'int' Keyword.Type
' ' Text.Whitespace
'main' Name.Function
'(' Punctuation
')' Punctuation
'\n' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'switch' Keyword
' ' Text.Whitespace
'(' Punctuation
'0' Literal.Number.Integer
')' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'case' Keyword
' ' Text.Whitespace
'0' Literal.Number.Integer
' ' Text.Whitespace
':' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'default' Keyword
' ' Text.Whitespace
':' Operator
'\n' Text.Whitespace
' ' Text.Whitespace
';' Punctuation
'\n' Text.Whitespace
' ' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace
'}' Punctuation
'\n' Text.Whitespace