#include "test.h" #include "mrk/lexer.h" #define LEXER_INIT() \ mrk_lexer *lxr; \ TEST_CHECK(mrk_lexer_init(&lxr) == mrk_err_ok) void test_lexer_header() { LEXER_INIT(); const char *buf = "#### hallo hallo"; 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_header_start); 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); } void test_lexer_line_break() { LEXER_INIT(); const char *buf = " \n"; 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_line_break); TEST_CHECK(mrk_lexer_done(lxr)); const char *buf2 = " "; mrk_lexer_open(lxr, buf2, 0); TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok); TEST_CHECK(t.type == mrk_token_type_text); TEST_CHECK(mrk_lexer_done(lxr)); mrk_lexer_free(lxr); } void test_lexer_simple1() { LEXER_INIT(); const char *buf = "### hello world\n\nthis is a paragraph"; 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_header_start); 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_blank_line); TEST_CHECK(mrk_lexer_next(&t, lxr) == mrk_lexer_err_ok); 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 } };