From 710c76192a2d7ab26b2d7dca58eb053674dbe1e4 Mon Sep 17 00:00:00 2001 From: ryanfleury Date: Tue, 9 Feb 2021 08:56:22 -0700 Subject: [PATCH] node comment bugfixes and tests --- source/md_impl.c | 3 --- tests/sanity_tests.c | 48 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 7 deletions(-) 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;