-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_Parser.c
50 lines (44 loc) · 1.23 KB
/
test_Parser.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "mocc.h"
static void
check_parser(const char *test_name, const char *text, const char *expected) {
assert(test_name);
assert(text);
assert(expected);
Vec(Token) *tokens = Preprocessor_read(Vec_new(String)(), test_name, text);
Parser *p = Parser_new(tokens);
if (p == NULL) {
ERROR("%s: Parser_new() == NULL\n", test_name);
}
TranslationUnitNode *node = Parser_parse(p);
if (node == NULL) {
ERROR("%s: Parser_parse() == NULL\n", test_name);
}
check_Node_dump(test_name, TranslationUnitNode_cbase_node(node), expected);
}
void test_Parser(void) {
check_parser(
"parser_minimum",
"int main(void) {\n"
" return 0;\n"
"}\n",
"(TranslationUnit\n"
" (FunctionDecl\n"
" (DeclSpec\n"
" (StorageClass none)\n"
" )\n"
" (FunctionDeclarator\n"
" (DirectDeclarator\n"
" (symbol main)\n"
" )\n"
" (bool false)\n"
" )\n"
" (CompoundStmt\n"
" (ReturnStmt\n"
" (IntegerExpr\n"
" (int 0)\n"
" )\n"
" )\n"
" )\n"
" )\n"
")\n");
}