test(parser): started some tests

This commit is contained in:
Jef Roosens 2024-03-12 20:51:48 +01:00
parent a4a41b287e
commit 184cc79a4c
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 66 additions and 7 deletions

View file

@ -9,7 +9,7 @@
void test_lexer_header() {
LEXER_INIT();
const char *buf = "#### hallo";
const char *buf = "#### hallo hallo";
mrk_lexer_open(lxr, buf, 0);
mrk_token t;
@ -18,6 +18,11 @@ void test_lexer_header() {
TEST_CHECK_(t.start == 0, "t.start == %lu", t.start);
TEST_CHECK(t.end == 4);
TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok);
TEST_CHECK(t.type == mrk_token_type_text);
TEST_CHECK_(t.start == 4, "t.start == %lu", t.start);
TEST_CHECK(t.end == 16);
mrk_lexer_free(lxr);
}
@ -56,9 +61,7 @@ void test_lexer_simple1() {
TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok);
TEST_CHECK(t.type == mrk_token_type_text);
TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok);
TEST_CHECK(t.type == mrk_token_type_newline);
TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok);
TEST_CHECK(t.type == mrk_token_type_newline);
TEST_CHECK(t.type == mrk_token_type_blank_line);
TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok);
TEST_CHECK(t.type == mrk_token_type_text);
}

38
test/parser/parser.c Normal file
View file

@ -0,0 +1,38 @@
#include "test.h"
#include "mrk/lexer.h"
#include "mrk/parser.h"
#define LEXER_INIT() \
mrk_lexer *lxr; \
TEST_CHECK(mrk_lexer_init(&lxr) == mrk_err_ok)
#define PARSER_INIT() \
mrk_parser *psr; \
TEST_CHECK(mrk_parser_init(&psr) == mrk_err_ok)
#define PARSER_OPEN(buf) \
mrk_lexer *lxr; \
TEST_CHECK(mrk_lexer_init(&lxr) == mrk_err_ok); \
mrk_parser *psr; \
TEST_CHECK(mrk_parser_init(&psr) == mrk_err_ok); \
mrk_lexer_open(lxr, buf, 0); \
mrk_parser_open(psr, lxr)
void test_parse_header() {
const char *buf = "### hello world";
PARSER_OPEN(buf);
mrk_ast_node *root;
TEST_CHECK(mrk_parser_parse(&root, psr) == mrk_err_ok);
mrk_ast_node *header = root->children.arr[0];
TEST_CHECK(header->type == mrk_ast_node_type_header);
TEST_CHECK(header->children.arr[0]->type == mrk_ast_node_type_text);
}
TEST_LIST = {
{ "parser header", test_parse_header },
{ NULL, NULL }
};