diff options
author | c | 2024-01-28 20:15:35 -0500 |
---|---|---|
committer | c | 2024-01-28 20:15:35 -0500 |
commit | 422606d8b3cc6fba74f97af46f0378fc274d60ad (patch) | |
tree | 34314628de5e3132cffc661901bd1e4c9b2aa0de /test | |
parent | 87e0d4b3d23a7eb38f0e196eac333c318fef27ea (diff) |
Fixed things.
- Fixed `parser_nxt_token()` assuming the existance of a parser's token.
- Fixed block parsing.
Diffstat (limited to 'test')
-rw-r--r-- | test/include/test.h | 4 | ||||
-rw-r--r-- | test/parser.c | 70 | ||||
-rw-r--r-- | test/tree.c | 4 |
3 files changed, 72 insertions, 6 deletions
diff --git a/test/include/test.h b/test/include/test.h index 3193c52..8cde34d 100644 --- a/test/include/test.h +++ b/test/include/test.h @@ -12,6 +12,10 @@ extern unsigned int TESTS_PASSED; #define TEST_INIT unsigned int TESTS_RUN = 0, TESTS_PASSED = 0; +#ifndef __func__ +#define __func__ "" +#endif + #define ASSERT(EXPR) \ TESTS_RUN++; \ (EXPR && ++TESTS_PASSED) ? \ diff --git a/test/parser.c b/test/parser.c index feb9c70..f2fe908 100644 --- a/test/parser.c +++ b/test/parser.c @@ -249,7 +249,7 @@ void single_block() { lexer_t* lexer; parser_t* parser; - char src[] = "{}"; + char src[] = "{1}"; /* @@ -257,7 +257,9 @@ void single_block() { val: [block] val: - NULL + [lint] + val: + 1 nxt: NULL nxt: @@ -267,7 +269,8 @@ void single_block() { tree = tree_init(TREE_TYPE_BLOCK); tree_t* tree0block = tree->data.block.val = tree_init(TREE_TYPE_BLOCK); - tree0block->data.block.val = NULL; + tree_t* tree0lint = tree0block->data.block.val = tree_init(TREE_TYPE_LINT); + tree0lint->data.lint.val = 1; tree0block->data.block.nxt = NULL; tree->data.block.nxt = NULL; @@ -290,13 +293,72 @@ void single_block() { parser_destroy(parser); } -int main(int argc, char** argv) { +void lint_and_block() { + tree_t* tree; + pp_t* pp; + lexer_t* lexer; + parser_t* parser; + + char src[] = "1;{1}"; + + /* + + [block] + val: + [lint] + val: + 1 + nxt: + [block] + val: + [block] + val: + [lint] + val: + 1 + nxt: + NULL + nxt: + NULL + + */ + + tree = tree_init(TREE_TYPE_BLOCK); + tree_t* tree0lint = tree->data.block.val = tree_init(TREE_TYPE_LINT); + tree0lint->data.lint.val = 1; + tree_t* tree0block = tree->data.block.nxt = tree_init(TREE_TYPE_BLOCK); + tree_t* tree1block = tree0block->data.block.val = tree_init(TREE_TYPE_BLOCK); + tree_t* tree1lint = tree1block->data.block.val = tree_init(TREE_TYPE_LINT); + tree1lint->data.lint.val = 1; + tree1block->data.block.nxt = NULL; + tree0block->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); +} + +int main() { empty(); single_lint(); double_lint(); single_lstr(); double_lstr(); single_block(); + lint_and_block(); TEST_REPORT; diff --git a/test/tree.c b/test/tree.c index b9ef210..567daae 100644 --- a/test/tree.c +++ b/test/tree.c @@ -20,8 +20,6 @@ void test_things() { tree_t* tree_lstr_1; tree_t* tree_tag_0; tree_t* tree_tag_1; - tree_t* tree_def_0; - tree_t* tree_def_1; tree_t* tree_carg_0; tree_t* tree_carg_1; tree_t* tree_call_0; @@ -245,6 +243,8 @@ void test_things() { ASSERT(tree_cmp(tree_block_0, tree_block_0) == 1); ASSERT(tree_cmp(tree_block_0, tree_block_1) == 0); + + /* *Definitely* not cleaning up fully here. Oh, well. */ } int main() { |