node comment bugfixes and tests

This commit is contained in:
ryanfleury
2021-02-09 08:56:22 -07:00
parent ba6286f379
commit 710c76192a
2 changed files with 44 additions and 7 deletions
-3
View File
@@ -1129,9 +1129,6 @@ MD_Parse_LexNext(MD_ParseCtx *ctx)
} }
} }
// NOTE(rjf): Trim off newline always.
chop_n = 1;
at += 2; at += 2;
token.kind = MD_TokenKind_Comment; token.kind = MD_TokenKind_Comment;
MD_TokenizerScan(*at != '\n'); MD_TokenizerScan(*at != '\n');
+41 -1
View File
@@ -400,12 +400,52 @@ int main(void)
} }
Test("Node Comments") Test("Node Comments")
{
// NOTE(rjf): Pre-Comments:
{
{ {
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("/*foobar*/ (a b c)")); MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("/*foobar*/ (a b c)"));
fprintf(stderr, "\n\"%.*s\"\n", MD_StringExpand(parse.node->comment_before));
TestResult(parse.node->kind == MD_NodeKind_Label && TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_before, MD_S8Lit("foobar"), 0)); MD_StringMatch(parse.node->comment_before, MD_S8Lit("foobar"), 0));
} }
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("// foobar\n(a b c)"));
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_before, MD_S8Lit("foobar"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("// foobar\n\n(a b c)"));
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_before, MD_S8Lit(""), 0));
}
}
// NOTE(rjf): Post-Comments:
{
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("(a b c) /*foobar*/"));
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit("foobar"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("(a b c) // foobar"));
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit("foobar"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("(a b c)\n// foobar"));
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit(""), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("(a b c)\n\n// foobar"));
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit(""), 0));
}
}
}
return 0; return 0;
} }