From 558230ea503411cc81dda642a2ffe272a5bdc9c1 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 12 Jul 2023 17:37:03 -0300 Subject: [PATCH] more tests --- TODO.md | 2 +- tests.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 4cdf511..55976f6 100644 --- a/TODO.md +++ b/TODO.md @@ -2,9 +2,9 @@ ## Things That May Get Done -* Add tests * Produce decent error structures * Detect mismatched start/end like {{% foo >}} +* Inform tag type (% or <) in result * Handle other kinds of quotes * Handle escaping quote characters * Handle escaping the shortcode itself like \{{% foo %}} (check with hugo docs) diff --git a/tests.c b/tests.c index af97d8d..b322001 100755 --- a/tests.c +++ b/tests.c @@ -38,6 +38,48 @@ Ensure(parse, simple_shortcode) assert_that(s.s, is_equal_to_string("{{% shortcode %}}")); } +Ensure(parse, inner_spaces_optional) +{ + char *input = "foobar {{% shortcode%}}blah"; + result = parse(input); + // Only 1 shortcode + assert_that(result[1].name.len, is_equal_to(0)); + + // It's a simple one called shortcode, no args + chunk_s(input, result[0].name); + assert_that(s.s, is_equal_to_string("shortcode")); + assert_that(result[0].matching, is_equal_to(0)); + assert_that(result[0].argcount, is_equal_to(0)); + // The whole shortcode is the whole thing + chunk_s(input, result[0].whole); + assert_that(s.s, is_equal_to_string("{{% shortcode%}}")); +} + +Ensure(parse, multiple_shortcodes) +{ + char *input = "foobar {{% shortcode %}}blah {{}}blahblah"; + result = parse(input); + // 2 shortcodes + assert_that(result[2].name.len, is_equal_to(0)); + + // It's a simple one called shortcode, no args + chunk_s(input, result[0].name); + assert_that(s.s, is_equal_to_string("shortcode")); + assert_that(result[0].matching, is_equal_to(0)); + assert_that(result[0].argcount, is_equal_to(0)); + // The whole shortcode is the whole thing + chunk_s(input, result[0].whole); + assert_that(s.s, is_equal_to_string("{{% shortcode %}}")); + // It's a simple one called sc2, no args + chunk_s(input, result[1].name); + assert_that(s.s, is_equal_to_string("sc2")); + assert_that(result[1].matching, is_equal_to(0)); + assert_that(result[1].argcount, is_equal_to(0)); + // The whole shortcode is the whole thing + chunk_s(input, result[1].whole); + assert_that(s.s, is_equal_to_string("{{}}")); +} + Ensure(parse, matching_shortcode) { char *input = "blah {{% shortcode %}}foo bar{{% /shortcode %}} blah"; @@ -65,6 +107,8 @@ int main(int argc, char **argv) TestSuite *suite = create_test_suite(); add_test_with_context(suite, parse, empty_string); add_test_with_context(suite, parse, simple_shortcode); + add_test_with_context(suite, parse, inner_spaces_optional); + add_test_with_context(suite, parse, multiple_shortcodes); add_test_with_context(suite, parse, matching_shortcode); return run_test_suite(suite, create_text_reporter()); }