aboutsummaryrefslogtreecommitdiff
path: root/src/tests/ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/ast.c')
-rw-r--r--src/tests/ast.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/tests/ast.c b/src/tests/ast.c
new file mode 100644
index 0000000..eb20e03
--- /dev/null
+++ b/src/tests/ast.c
@@ -0,0 +1,42 @@
+#include "tests/tests.h"
+#include "ast.h"
+
+#include <string.h>
+
+#include "parser.h"
+
+static void
+check_parser_errors(struct parser *parser)
+{
+ if (parser->errors->len > 0) {
+ printf("\n");
+ size_t i;
+ char *val;
+ vector_foreach (parser->errors, i, val) {
+ printf("parser error %lu: %s\n", i, val);
+ }
+ FAIL_TEST("parser encountered errors\n");
+ }
+}
+
+static void
+test_string(void)
+{
+ char *input = "let var = anotherVar;";
+ struct parser *parser = parser_new(input);
+ struct program *prog = parser_parse_program(parser);
+ check_parser_errors(parser);
+ assertneq(prog, NULL);
+ char progbuf[1024];
+ node_sprint(prog, progbuf);
+ asserteq(strcmp(input, progbuf), 0);
+ node_destroy(prog);
+ parser_destroy(parser);
+}
+
+int
+main(void)
+{
+ INIT_TESTS();
+ RUN_TEST(test_string);
+}