Decaf Compiler
testsuite.h
Go to the documentation of this file.
1 
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdint.h>
10 #include <assert.h>
11 #include <time.h>
12 
13 #include <check.h>
14 
15 #include "p1-lexer.h"
16 #include "p2-parser.h"
17 
21 #define TEST_VALID(NAME,TEXT) START_TEST (NAME) \
22 { ck_assert (valid_program(TEXT)); } \
23 END_TEST
24 
28 #define TEST_INVALID(NAME,TEXT) START_TEST (NAME) \
29 { ck_assert (invalid_program(TEXT)); } \
30 END_TEST
31 
35 #define TEST_VALID_MAIN(NAME,TEXT) START_TEST (NAME) \
36 { ck_assert (valid_program("def int main () { " TEXT " }")); } \
37 END_TEST
38 
42 #define TEST_INVALID_MAIN(NAME,TEXT) START_TEST (NAME) \
43 { ck_assert (invalid_program("def int main () { " TEXT " }")); } \
44 END_TEST
45 
49 #define TEST_VALID_EXPR(NAME,TEXT) START_TEST (NAME) \
50 { ck_assert (valid_program("def int main () { return " TEXT " ; }")); } \
51 END_TEST
52 
56 #define TEST_INVALID_EXPR(NAME,TEXT) START_TEST (NAME) \
57 { ck_assert (invalid_program("def int main () { return " TEXT " ; }")); } \
58 END_TEST
59 
63 #define TEST_INT_LITERAL(NAME,TEXT,VALUE) START_TEST (NAME) \
64 { ASTNode* p = run_parser("def int main() { return " TEXT " ; }"); \
65  int value = p->program.functions->head->funcdecl.body->block.statements->head->funcreturn.value->literal.integer; \
66  ck_assert_int_eq(value, VALUE); } \
67 END_TEST
68 
72 #define TEST_STR_LITERAL(NAME,TEXT,VALUE) START_TEST (NAME) \
73 { ASTNode* p = run_parser("def int main() { return " TEXT " ; }"); \
74  char* value = p->program.functions->head->funcdecl.body->block.statements->head->funcreturn.value->literal.string; \
75  ck_assert_str_eq(value, VALUE); } \
76 END_TEST
77 
81 #define TEST(NAME) tcase_add_test (tc, NAME)
82 
92 ASTNode* run_parser (char* text);
93 
100 bool invalid_program (char* text);
101 
109 bool valid_program (char* text);
ASTNode
Main AST node structure.
Definition: ast.h:465
p2-parser.h
Interface for Project 2 (Parser)
valid_program
bool valid_program(char *text)
Run lexer and parser on given text and verify that it returns an AST and does not throw an exception.
Definition: testsuite.c:21
p1-lexer.h
Interface for Project 1 (Lexer)
run_parser
ASTNode * run_parser(char *text)
Run lexer and parser on given text.
Definition: testsuite.c:10
invalid_program
bool invalid_program(char *text)
Run lexer and parser on given text and verify that it throws an exception.
Definition: testsuite.c:26