#ifndef MK_TEST_LEXER_H #define MK_TEST_LEXER_H #include #include #include static void test_lexer(char const* source, int n, ...) { va_list lst; va_start(lst, n); struct status status; status_init(&status); struct lexer lex; lexer_init(&lex, source, &status); for (int i=0; ivalue); ck_assert_int_eq(kind, tok->kind); token_free(tok); free(tok); } status_free(&status); lexer_free(&lex); va_end(lst); } START_TEST(lexer_atom) { test_lexer(" 34 -2 0 ", 3, TOKEN_INT, "34", TOKEN_INT, "-2", TOKEN_INT, "0" ); test_lexer(" 3.4 -2.2 .6 7. ", 4, TOKEN_FLOAT, "3.4", TOKEN_FLOAT, "-2.2", TOKEN_FLOAT, ".6", TOKEN_FLOAT, "7." ); test_lexer(" true false ", 2, TOKEN_BOOL, "true", TOKEN_BOOL, "false" ); test_lexer(" \"\\\\hel\\rlo\" \"wo\\trld\\n\" \" \\\"bim\\\" \" ", 3, TOKEN_STRING, "\\hel\rlo", TOKEN_STRING, "wo\trld\n", TOKEN_STRING, " \"bim\" " ); test_lexer(" 'hello ", 1, TOKEN_SYMBOL, "hello" ); } END_TEST START_TEST(lexer_funcall) { test_lexer(" (_0pizza?!) ", 3, TOKEN_OPAR, "(", TOKEN_IDENT, "_0pizza?!", TOKEN_CPAR, ")" ); } END_TEST START_TEST(lexer_array) { test_lexer(" [] ", 2, TOKEN_OSQUARE, "[", TOKEN_CSQUARE, "]" ); } END_TEST void register_lexer(Suite* suite) { TCase* tcase = tcase_create("Lexer"); tcase_add_test(tcase, lexer_atom); tcase_add_test(tcase, lexer_funcall); tcase_add_test(tcase, lexer_array); suite_add_tcase(suite, tcase); } #endif