From 1bcd741eebf0730177385ec77986337c5ceb5ac2 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 30 Jun 2021 14:59:26 -0400 Subject: [PATCH] fill out tests for more corner cases --- source/md.h | 8 +++---- tests/sanity_tests.c | 56 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/source/md.h b/source/md.h index 5735f5c..fff5c81 100644 --- a/source/md.h +++ b/source/md.h @@ -3,12 +3,12 @@ // TODO List // -// [ ] unify string literal token kinds -// [ ] simplify string literal flags (triple as a single flag) +// [x] unify string literal token kinds +// [x] simplify string literal flags (triple as a single flag) // [ ] lexer detects broken comments // [ ] lexer detects broken strings -// [ ] tests for legal tag syntaxes -// [ ] tests that ensure we don't accept labels when expecting symbols e.g. foo ":" b; foo: "(" ) +// [x] tests for legal tag syntaxes +// [x] tests that ensure we don't accept labels when expecting symbols e.g. foo ":" b; foo: "(" ) // [ ] pass all tests // [ ] simplify error sorting and catastrophic error handling // [ ] integer -> string helpers diff --git a/tests/sanity_tests.c b/tests/sanity_tests.c index d30e013..f1014dd 100644 --- a/tests/sanity_tests.c +++ b/tests/sanity_tests.c @@ -745,6 +745,32 @@ int main(void) } } + Test("Tags") + { + MD_String8 file_name = MD_S8Lit("raw_text"); + + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("@foo bar")); + TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("foo"))); + } + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("@+ bar")); + TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("+"))); + } + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("@'a b c' bar")); + TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("a b c"))); + } + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("@100 bar")); + TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("100"))); + } + } + Test("Tagged & Unlabeled") { MD_String8 file_name = MD_S8Lit("raw_text"); @@ -858,7 +884,35 @@ int main(void) } } - MD_String8 str = MD_PushStringF("%i", "foobar"); + Test("Labels are Not Reserved") + { + MD_String8 file_name = MD_S8Lit("raw_text"); + + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("foo: '(' )")); + TestResult(result.errors.first != 0); + } + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("foo ':' ( )")); + TestResult(result.errors.first == 0); + TestResult(MD_ChildCountFromNode(result.node) == 3); + } + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("'@'bar foo")); + TestResult(result.errors.first == 0); + TestResult(MD_ChildCountFromNode(result.node) == 3); + } + { + MD_ParseResult result = MD_ParseWholeString(file_name, + MD_S8Lit("foo: '(' ')'")); + TestResult(result.errors.first == 0); + TestResult(MD_ChildCountFromNode(result.node) == 1); + TestResult(MD_ChildCountFromNode(result.node->first_child) == 2); + } + } return 0; } \ No newline at end of file