aboutsummaryrefslogtreecommitdiff
path: root/src/tests/ast.c
blob: eb20e03422163a5c9f601bbe46d15b1309e90bef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
}