feat: lex and parse single-line code blocks
This commit is contained in:
parent
2387461e21
commit
c653d437bd
8 changed files with 128 additions and 10 deletions
|
|
@ -66,9 +66,25 @@ void test_lexer_simple1() {
|
|||
TEST_CHECK(t.type == mrk_token_type_text);
|
||||
}
|
||||
|
||||
void test_lexer_code() {
|
||||
LEXER_INIT();
|
||||
|
||||
const char *buf = "`world [hello](link)`";
|
||||
mrk_lexer_open(lxr, buf, 0);
|
||||
|
||||
mrk_token t;
|
||||
|
||||
TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok);
|
||||
TEST_CHECK(t.type == mrk_token_type_backtick);
|
||||
TEST_CHECK(t.start == 0);
|
||||
TEST_CHECK(t.end == 1);
|
||||
|
||||
}
|
||||
|
||||
TEST_LIST = {
|
||||
{ "lexer header", test_lexer_header },
|
||||
{ "lexer line break", test_lexer_line_break},
|
||||
{ "lexer simple 1", test_lexer_simple1 },
|
||||
{ "lexer code", test_lexer_code },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue