From c0cd4e5f199e8567ec3b5e216fbee27837d21bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Thu, 20 Jan 2022 02:34:32 +0300 Subject: init --- src/tests/ast.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/tests/ast.c (limited to 'src/tests/ast.c') 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 + +#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); +} -- cgit v1.2.3