aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorc2024-01-22 13:30:47 -0500
committerc2024-01-22 13:30:47 -0500
commit0ff1d40842390da36908c7ffce62f2cf33b173b9 (patch)
tree4536d78f68fe295b7b3dd1dee1609292b083ab18 /test
parentd3ed2864afd3d470a39c7ef2ec1a53deaae18d14 (diff)
Not sure.
Diffstat (limited to 'test')
-rw-r--r--test/include/test.h2
-rw-r--r--test/parser.c219
2 files changed, 76 insertions, 145 deletions
diff --git a/test/include/test.h b/test/include/test.h
index 9a2aa5a..c5fd97e 100644
--- a/test/include/test.h
+++ b/test/include/test.h
@@ -6,6 +6,8 @@
extern unsigned int TESTS_RUN;
extern unsigned int TESTS_PASSED;
+#define TEST_INIT unsigned int TESTS_RUN = 0, TESTS_PASSED = 0;
+
#define ASSERT(EXPR) \
TESTS_RUN++; \
(EXPR && ++TESTS_PASSED) ? \
diff --git a/test/parser.c b/test/parser.c
index 78e4066..db296e6 100644
--- a/test/parser.c
+++ b/test/parser.c
@@ -4,163 +4,92 @@
#include "../src/include/tree.h"
#include "../src/include/parser.h"
-unsigned int TESTS_RUN = 0, TESTS_PASSED = 0;
-
-#define PARSER_SETUP(SRC) \
- pp = pp_init(SRC); \
- pp_run(pp); \
- lexer = lexer_init(pp->psrc); \
- lexer_run(lexer); \
- parser = parser_init(lexer->tokenl); \
+TEST_INIT
+
+void test_simple_empty() {
+ tree_t* tree;
+ pp_t* pp;
+ lexer_t* lexer;
+ parser_t* parser;
+
+ char src[] = " ";
+
+ /*
+
+ [block]
+ val:
+ NULL
+ nxt:
+ NULL
+
+ */
+
+ tree = tree_init(TREE_TYPE_BLOCK);
+ tree->data.block.val = NULL;
+ tree->data.block.nxt = NULL;
+
+ pp = pp_init(src);
+ pp_run(pp);
+
+ lexer = lexer_init(pp->psrc);
+ lexer_run(lexer);
+
+ parser = parser_init(lexer->tokenl);
parser_run(parser);
-int main(int argc, char** argv) {
- tree_t* tree_0;
+ ASSERT(tree_cmp(parser->tree, tree) == 1);
+
+ pp_destroy(pp);
+ parser_destroy(parser);
+ lexer_destroy(lexer);
+}
+
+void test_single_lint() {
+ tree_t* tree;
pp_t* pp;
lexer_t* lexer;
parser_t* parser;
- /* Simple empty block. */
- char src_0[] = "";
+ char src[] = "1";
- /*
+ /*
- [block]
+ [block]
+ val:
+ [lint]
val:
- NULL
- nxt:
- NULL
-
- */
-
- tree_0 = tree_init(TREE_TYPE_BLOCK);
- tree_0->data.block.val = NULL;
- tree_0->data.block.nxt = NULL;
-
- PARSER_SETUP(src_0);
-
- tree_print(tree_0, 0);
- tree_print(parser->tree, 0);
-
- ASSERT(tree_cmp(parser->tree, tree_0) == 1);
-
- /* More complicated tree. */
- char src_1[] = "" \
- ":int:f = {" \
- "a.b;" \
- "c.d"
- "}";
- /*
-
- [block]
- val:
- [expression]
- val:
- [def]
- tag:
- [tag]
- val:
- "int"
- nxt:
- [tag]
- val:
- "f"
- nxt:
- NULL
- arg:
- NULL
- val:
- [expression]
- val:
- [block]
- val:
- [expression]
- val:
- [call]
- target:
- "a"
- arg:
- [carg]
- val:
- [call]
- target:
- "b"
- arg:
- NULL
- nxt:
- NULL
- nxt:
- [block]
- val:
- [expression]
- val:
- [call]
- target:
- "c"
- arg:
- [carg]
- val:
- [call]
- target:
- "d"
- nxt:
- NULL
- nxt:
- NULL
- nxt:
- NULL
- nxt:
- NULL
-
- */
-
- tree_0 = tree_init(TREE_TYPE_BLOCK);
- tree_t* treep_00 = tree_0->data.block.val = tree_init(TREE_TYPE_EXPR);
- tree_t* treep_01 = treep_00->data.expr.val = tree_init(TREE_TYPE_DEF);
- tree_t* treep_02 = treep_01->data.def.tag = tree_init(TREE_TYPE_TAG);
- treep_02->data.tag.val = "int";
- tree_t* treep_03 = treep_02->data.tag.nxt = tree_init(TREE_TYPE_TAG);
- treep_03->data.tag.val = "f";
- treep_03->data.tag.nxt = NULL;
- treep_01->data.def.arg = NULL;
- tree_t* treep_04 = treep_01->data.def.val = tree_init(TREE_TYPE_EXPR);
- tree_t* treep_05 = treep_04->data.expr.val = tree_init(TREE_TYPE_BLOCK);
- tree_t* treep_06 = treep_05->data.block.val = tree_init(TREE_TYPE_EXPR);
- tree_t* treep_07 = treep_06->data.expr.val = tree_init(TREE_TYPE_CALL);
- treep_07->data.call.target = "a";
- tree_t* treep_08 = treep_07->data.call.arg = tree_init(TREE_TYPE_CARG);
- tree_t* treep_09 = treep_08->data.carg.val = tree_init(TREE_TYPE_EXPR);
- tree_t* treep_10 = treep_09->data.expr.val = tree_init(TREE_TYPE_CALL);
- treep_10->data.call.target = "b";
- treep_10->data.call.arg = NULL;
- treep_08->data.carg.nxt = NULL;
- tree_t* treep_11 = treep_05->data.block.nxt = tree_init(TREE_TYPE_BLOCK);
- tree_t* treep_12 = treep_11->data.block.val = tree_init(TREE_TYPE_EXPR);
- tree_t* treep_13 = treep_12->data.expr.val = tree_init(TREE_TYPE_CALL);
- treep_13->data.call.target = "c";
- tree_t* treep_14 = treep_13->data.call.arg = tree_init(TREE_TYPE_CARG);
- tree_t* treep_15 = treep_14->data.carg.val = tree_init(TREE_TYPE_EXPR);
- tree_t* treep_16 = treep_15->data.expr.val = tree_init(TREE_TYPE_CALL);
- treep_16->data.call.target = "d";
- treep_16->data.call.arg = NULL;
- treep_14->data.carg.nxt = NULL;
- treep_11->data.block.nxt = NULL;
- tree_0->data.block.nxt = NULL;
-
- pp = pp_init(src_0);
- pp_run(pp);
-
- lexer = lexer_init(pp->psrc);
- lexer_run(lexer);
-
- parser = parser_init(lexer->tokenl);
- parser_run(parser);
-
- ASSERT(tree_cmp(tree_0, parser->tree));
+ 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;
+
+ 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);
- lexer_destroy(lexer);
+}
+
+int main(int argc, char** argv) {
+ test_simple_empty();
+ test_single_lint();
TEST_REPORT;