diff --git a/source/md_impl.c b/source/md_impl.c index 0a73831..11e1742 100644 --- a/source/md_impl.c +++ b/source/md_impl.c @@ -1129,9 +1129,6 @@ MD_Parse_LexNext(MD_ParseCtx *ctx) } } - // NOTE(rjf): Trim off newline always. - chop_n = 1; - at += 2; token.kind = MD_TokenKind_Comment; MD_TokenizerScan(*at != '\n'); diff --git a/tests/sanity_tests.c b/tests/sanity_tests.c index f21dce6..43d2af2 100644 --- a/tests/sanity_tests.c +++ b/tests/sanity_tests.c @@ -401,10 +401,50 @@ int main(void) Test("Node Comments") { - 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 && - MD_StringMatch(parse.node->comment_before, MD_S8Lit("foobar"), 0)); + + // NOTE(rjf): Pre-Comments: + { + { + MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("/*foobar*/ (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(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;