feat: lex and parse single-line code blocks

This commit is contained in:
Jef Roosens 2024-03-25 17:03:00 +01:00
parent 2387461e21
commit c653d437bd
Signed by: Jef Roosens
GPG key ID: 02D4C0997E74717B
8 changed files with 128 additions and 10 deletions

View file

@ -1,3 +1,4 @@
#include "mrk/ast.h"
#include "test.h"
#include "mrk/lexer.h"
@ -98,9 +99,30 @@ void test_parse_unordered_list() {
TEST_CHECK(subchild->children.arr[0]->d.text.end == 57);
}
void test_parse_code() {
const char *buf = "`world [hello](link)`";
PARSER_OPEN(buf);
mrk_ast_node *code;
mrk_ast_node_init(&code);
TEST_CHECK(mrk_parser_parse_code(code, parser) == mrk_err_ok);
TEST_CHECK(code->type == mrk_ast_node_type_code);
TEST_CHECK(code->children.len == 1);
mrk_ast_node *child = code->children.arr[0];
TEST_CHECK(child->type == mrk_ast_node_type_text);
TEST_CHECK(child->d.text.start == 1);
TEST_MSG("start: %lu", child->d.text.start);
TEST_CHECK(child->d.text.end == 20);
TEST_MSG("end: %lu", child->d.text.end);
}
TEST_LIST = {
{ "parser header", test_parse_header },
{ "parser link", test_parse_link },
{ "parser unordered list", test_parse_unordered_list },
{ "parser code", test_parse_code },
{ NULL, NULL }
};