aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/include/test.h4
-rw-r--r--test/parser.c66
2 files changed, 59 insertions, 11 deletions
diff --git a/test/include/test.h b/test/include/test.h
index c5fd97e..02c3d18 100644
--- a/test/include/test.h
+++ b/test/include/test.h
@@ -11,8 +11,8 @@ extern unsigned int TESTS_PASSED;
#define ASSERT(EXPR) \
TESTS_RUN++; \
(EXPR && ++TESTS_PASSED) ? \
- log_inf("%s:%d: Assertion passed!", __FILE__, __LINE__) : \
- log_err("%s:%d: Assertion failed:\n\t%s", __FILE__, __LINE__, #EXPR);
+ log_inf("%s:%s:%d: Assertion passed!", __func__, __FILE__, __LINE__) : \
+ log_err("%s:%s:%d: Assertion failed:\n\t%s", __func__, __FILE__, __LINE__, #EXPR);
#define TEST_REPORT \
(TESTS_RUN == TESTS_PASSED) ? \
diff --git a/test/parser.c b/test/parser.c
index db296e6..2007e93 100644
--- a/test/parser.c
+++ b/test/parser.c
@@ -16,16 +16,52 @@ void test_simple_empty() {
/*
+ NULL
+
+ */
+
+ tree = NULL;
+ pp = pp_init(src);
+ pp_run(pp);
+
+ lexer = lexer_init(pp->psrc);
+ lexer_run(lexer);
+
+ parser = parser_init(lexer->tokenl);
+ parser_run(parser);
+
+ ASSERT(tree_cmp(parser->tree, tree) == 1);
+
+ token_destroy(lexer->tokenl);
+ lexer_destroy(lexer);
+ pp_destroy(pp);
+ tree_destroy(parser->tree);
+ parser_destroy(parser);
+}
+
+void test_single_lint() {
+ tree_t* tree;
+ pp_t* pp;
+ lexer_t* lexer;
+ parser_t* parser;
+
+ char src[] = "1";
+
+ /*
+
[block]
val:
- NULL
+ [lint]
+ val:
+ 1
nxt:
NULL
*/
tree = tree_init(TREE_TYPE_BLOCK);
- tree->data.block.val = NULL;
+ tree->data.block.val = tree_init(TREE_TYPE_LINT);
+ tree->data.block.val->data.lint.val = 1;
tree->data.block.nxt = NULL;
pp = pp_init(src);
@@ -39,18 +75,20 @@ void test_simple_empty() {
ASSERT(tree_cmp(parser->tree, tree) == 1);
+ token_destroy(lexer->tokenl);
+ lexer_destroy(lexer);
pp_destroy(pp);
+ tree_destroy(parser->tree);
parser_destroy(parser);
- lexer_destroy(lexer);
}
-void test_single_lint() {
+void test_double_lint() {
tree_t* tree;
pp_t* pp;
lexer_t* lexer;
parser_t* parser;
- char src[] = "1";
+ char src[] = "1;1";
/*
@@ -60,14 +98,23 @@ void test_single_lint() {
val:
1
nxt:
- NULL
+ [block]
+ val:
+ [lint]
+ val:
+ 1
+ nxt:
+ NULL
*/
tree = tree_init(TREE_TYPE_BLOCK);
- tree->data.block.val = tree_init(TREE_TYPE_LINT);
- tree->data.block.val->data.lint.val = 1;
- tree->data.block.nxt = NULL;
+ tree_t* tree0lint = tree->data.block.val = tree_init(TREE_TYPE_LINT);
+ tree0lint->data.lint.val = 1;
+ tree_t* tree1block = tree->data.block.nxt = tree_init(TREE_TYPE_BLOCK);
+ tree_t* tree2lint = tree1block->data.block.val = tree_init(TREE_TYPE_LINT);
+ tree2lint->data.lint.val = 1;
+ tree1block->data.block.nxt = NULL;
pp = pp_init(src);
pp_run(pp);
@@ -90,6 +137,7 @@ void test_single_lint() {
int main(int argc, char** argv) {
test_simple_empty();
test_single_lint();
+ test_double_lint();
TEST_REPORT;