#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); }