Compare commits

..

No commits in common. "4dc22ff2daac3f456ead33979507cc40a2d6ca14" and "910b7ce86126319ed2b254f1fbb59b39721ef95e" have entirely different histories.

View File

@ -26,104 +26,180 @@ describe "Shortcodes" do
result.errors[0].code.should eq ERR_MISMATCHED_CLOSING_TAG result.errors[0].code.should eq ERR_MISMATCHED_CLOSING_TAG
input[result.errors[0].position, 8].should eq "{{% /foo" input[result.errors[0].position, 8].should eq "{{% /foo"
end end
# Ensure(parse, mismatched_tags)
# {
# char *input = "foobar {{% shortcode %}}blah{{% /foo %}}";
# result = parse(input);
# // One shortcode, one error
# assert_that(result.sccount, is_equal_to(1));
# assert_that(result.errcount, is_equal_to(1));
# assert_that(result.errors[0].code, is_equal_to(ERR_MISMATCHED_CLOSING_TAG));
# str_copyb(&s, input + result.errors[0].position, 8);
# assert_that(s.s, is_equal_to_string("{{% /foo"));
# }
it "should report mismatched brackets" do # Ensure(parse, mismatched_brackets)
input = "foobar {{% shortcode >}}blah" # {
result = parse(input) # char *input = "foobar {{% shortcode >}}blah";
result.shortcodes.size.should eq 0 # result = parse(input);
result.errors.size.should eq 1 # // No shortcodes, 1 error
result.errors[0].code.should eq ERR_MISMATCHED_BRACKET # assert_that(result.sccount, is_equal_to(0));
input[result.errors[0].position, 3].should eq ">}}" # assert_that(result.errcount, is_equal_to(1));
end # assert_that(result.errors[0].code, is_equal_to(ERR_MISMATCHED_BRACKET));
# str_copyb(&s, input + result.errors[0].position, 3);
# assert_that(s.s, is_equal_to_string(">}}"));
# }
it "should accept mismatched brackets inside data are ok" do # Ensure(parse, mismatched_brackets_inside_data_are_ok)
input = "foobar {{% sc %}} >}}blah {{% /sc %}} " # {
result = parse(input) # char *input = "foobar {{% sc %}} >}}blah {{% /sc %}} ";
result.shortcodes.size.should eq 1 # result = parse(input);
result.errors.size.should eq 0 # // 1 shortcode
result.shortcodes[0].whole.should eq "{{% sc %}} >}}blah {{% /sc %}}" # assert_that(result.sccount, is_equal_to(1));
result.shortcodes[0].data.should eq " >}}blah " # chunk_s(input, result.sc[0].whole);
end # assert_that(s.s, is_equal_to_string("{{% sc %}} >}}blah {{% /sc %}}"));
# chunk_s(input, result.sc[0].data);
# assert_that(s.s, is_equal_to_string(" >}}blah "));
# assert_that(result.errcount, is_equal_to(0));
# }
it "should accept mismatched brackets in qvals" do # Ensure(parse, mismatched_brackets_in_qval_are_ok)
input = "foobar {{% sc \">}}blah\" %}} {{% /sc %}}" # {
result = parse(input) # char *input = "foobar {{% sc \">}}blah\" %}} {{% /sc %}}";
result.shortcodes.size.should eq 1 # result = parse(input);
result.errors.size.should eq 0 # // 1 shortcode
result.shortcodes[0].whole.should eq "{{% sc \">}}blah\" %}} {{% /sc %}}" # assert_that(result.sccount, is_equal_to(1));
result.shortcodes[0].args.size.should eq 1 # chunk_s(input, result.sc[0].whole);
result.shortcodes[0].args[0].@value.should eq ">}}blah" # assert_that(s.s, is_equal_to_string("{{% sc \">}}blah\" %}} {{% /sc %}}"));
end # chunk_s(input, result.sc[0].argvals[0]);
# assert_that(s.s, is_equal_to_string(">}}blah"));
# assert_that(result.errcount, is_equal_to(0));
# }
it "should consider spaces in shortcodes optional" do # Ensure(parse, inner_spaces_optional)
input = "foobar {{% shortcode%}}blah" # {
result = parse(input) # char *input = "foobar {{% shortcode%}}blah";
result.shortcodes.size.should eq 1 # result = parse(input);
result.errors.size.should eq 0 # // Only 1 shortcode
result.shortcodes[0].name.should eq "shortcode" # assert_that(result.sccount, is_equal_to(1));
result.shortcodes[0].matching.should eq 0
result.shortcodes[0].args.size.should eq 0
result.shortcodes[0].whole.should eq "{{% shortcode%}}"
end
it "should allow path-like names" do # // It's a simple one called shortcode, no args
input = "foobar {{% shortcode/foo/bar %}}blah" # chunk_s(input, result.sc[0].name);
result = parse(input) # assert_that(s.s, is_equal_to_string("shortcode"));
result.shortcodes.size.should eq 1 # assert_that(result.sc[0].matching, is_equal_to(0));
result.errors.size.should eq 0 # assert_that(result.sc[0].argcount, is_equal_to(0));
result.shortcodes[0].name.should eq "shortcode/foo/bar" # // The whole shortcode is the whole thing
result.shortcodes[0].matching.should eq 0 # chunk_s(input, result.sc[0].whole);
result.shortcodes[0].args.size.should eq 0 # assert_that(s.s, is_equal_to_string("{{% shortcode%}}"));
result.shortcodes[0].whole.should eq "{{% shortcode/foo/bar %}}" # assert_that(result.errcount, is_equal_to(0));
end # }
it "should parse multiple shortcodes" do # Ensure(parse, name_can_be_path)
input = "foobar {{% shortcode %}}blah {{<sc2 >}}blahblah" # {
result = parse(input) # char *input = "foobar {{% shortcode/foo/bar %}}blah";
result.shortcodes.size.should eq 2 # result = parse(input);
result.errors.size.should eq 0 # // Only 1 shortcode
result.shortcodes[0].name.should eq "shortcode" # assert_that(result.sccount, is_equal_to(1));
result.shortcodes[0].matching.should eq 0
result.shortcodes[0].args.size.should eq 0
result.shortcodes[0].whole.should eq "{{% shortcode %}}"
result.shortcodes[1].name.should eq "sc2"
result.shortcodes[1].matching.should eq 0
result.shortcodes[1].args.size.should eq 0
result.shortcodes[1].whole.should eq "{{<sc2 >}}"
end
it "should parse matching shortcodes" do # // It's a simple one called shortcode, no args
input = "foobar {{% shortcode %}}blah {{% /shortcode %}} blah" # chunk_s(input, result.sc[0].name);
result = parse(input) # assert_that(s.s, is_equal_to_string("shortcode/foo/bar"));
result.shortcodes.size.should eq 1 # assert_that(result.sc[0].matching, is_equal_to(0));
result.errors.size.should eq 0 # assert_that(result.sc[0].argcount, is_equal_to(0));
result.shortcodes[0].name.should eq "shortcode" # assert_that(result.errcount, is_equal_to(0));
result.shortcodes[0].matching.should eq 1 # }
result.shortcodes[0].args.size.should eq 0
result.shortcodes[0].whole.should eq "{{% shortcode %}}blah {{% /shortcode %}}"
result.shortcodes[0].data.should eq "blah "
end
it "should parse shortcode args" do # Ensure(parse, multiple_shortcodes)
input = "foobar {{% shortcode foo \"bar\" 42 bat=v1 baz=\"v2\" %}}blah" # {
result = parse(input) # char *input = "foobar {{% shortcode %}}blah {{<sc2 >}}blahblah";
result.shortcodes.size.should eq 1 # result = parse(input);
result.errors.size.should eq 0 # // 2 shortcodes
result.shortcodes[0].name.should eq "shortcode" # assert_that(result.sccount, is_equal_to(2));
result.shortcodes[0].matching.should eq 0
result.shortcodes[0].args.size.should eq 5 # // It's a simple one called shortcode, no args
result.shortcodes[0].args[0].name.should eq "" # chunk_s(input, result.sc[0].name);
result.shortcodes[0].args[0].value.should eq "foo" # assert_that(s.s, is_equal_to_string("shortcode"));
result.shortcodes[0].args[1].name.should eq "" # assert_that(result.sc[0].matching, is_equal_to(0));
result.shortcodes[0].args[1].value.should eq "bar" # assert_that(result.sc[0].argcount, is_equal_to(0));
result.shortcodes[0].args[2].name.should eq "" # // The whole shortcode is the whole thing
result.shortcodes[0].args[2].value.should eq "42" # chunk_s(input, result.sc[0].whole);
result.shortcodes[0].args[3].name.should eq "bat" # assert_that(s.s, is_equal_to_string("{{% shortcode %}}"));
result.shortcodes[0].args[3].value.should eq "v1" # // It's a simple one called sc2, no args
result.shortcodes[0].args[4].name.should eq "baz" # chunk_s(input, result.sc[1].name);
result.shortcodes[0].args[4].value.should eq "v2" # assert_that(s.s, is_equal_to_string("sc2"));
result.shortcodes[0].whole.should eq "{{% shortcode foo \"bar\" 42 bat=v1 baz=\"v2\" %}}" # assert_that(result.sc[1].matching, is_equal_to(0));
end # assert_that(result.sc[1].argcount, is_equal_to(0));
# // The whole shortcode is the whole thing
# chunk_s(input, result.sc[1].whole);
# assert_that(s.s, is_equal_to_string("{{<sc2 >}}"));
# assert_that(result.errcount, is_equal_to(0));
# }
# Ensure(parse, matching_shortcode)
# {
# char *input = "blah {{% shortcode %}}foo bar{{% /shortcode %}} blah";
# result = parse(input);
# // Only 1 shortcode
# assert_that(result.sccount, is_equal_to(1));
# // It's a matching one called shortcode, no args
# chunk_s(input, result.sc[0].name);
# assert_that(s.s, is_equal_to_string("shortcode"));
# assert_that(result.sc[0].matching, is_equal_to(1));
# assert_that(result.sc[0].argcount, is_equal_to(0));
# // data is the stuff between the shortcode tags
# chunk_s(input, result.sc[0].data);
# assert_that(s.s, is_equal_to_string("foo bar"));
# // The whole shortcode is the whole thing
# chunk_s(input, result.sc[0].whole);
# assert_that(s.s, is_equal_to_string("{{% shortcode %}}foo bar{{% /shortcode %}}"));
# assert_that(result.errcount, is_equal_to(0));
# }
# Ensure(parse, shortcode_args)
# {
# char *input = "foobar {{% shortcode foo \"bar\" 42 bat=v1 baz=\"v2\" %}}blah";
# result = parse(input);
# // Only 1 shortcode
# assert_that(result.sccount, is_equal_to(1));
# // The whole shortcode is the whole thing
# chunk_s(input, result.sc[0].whole);
# assert_that(s.s, is_equal_to_string("{{% shortcode foo \"bar\" 42 bat=v1 baz=\"v2\" %}}"));
# // Name is shortcode
# chunk_s(input, result.sc[0].name);
# assert_that(s.s, is_equal_to_string("shortcode"));
# assert_that(result.sc[0].matching, is_equal_to(0));
# // Has 5 args
# assert_that(result.sc[0].argcount, is_equal_to(5));
# // Arg1 is foo, no name
# assert_that(result.sc[0].argnames[0].len, is_equal_to(0));
# chunk_s(input, result.sc[0].argvals[0]);
# assert_that(s.s, is_equal_to_string("foo"));
# // Arg2 is bar, no name
# assert_that(result.sc[0].argnames[1].len, is_equal_to(0));
# chunk_s(input, result.sc[0].argvals[1]);
# assert_that(s.s, is_equal_to_string("bar"));
# // Arg3 is 42, no name
# assert_that(result.sc[0].argnames[2].len, is_equal_to(0));
# chunk_s(input, result.sc[0].argvals[2]);
# assert_that(s.s, is_equal_to_string("42"));
# // Arg4 is bat=v1
# chunk_s(input, result.sc[0].argnames[3]);
# assert_that(s.s, is_equal_to_string("bat"));
# chunk_s(input, result.sc[0].argvals[3]);
# assert_that(s.s, is_equal_to_string("v1"));
# // Arg5 is baz=v2
# chunk_s(input, result.sc[0].argnames[4]);
# assert_that(s.s, is_equal_to_string("baz"));
# chunk_s(input, result.sc[0].argvals[4]);
# assert_that(s.s, is_equal_to_string("v2"));
# assert_that(result.errcount, is_equal_to(0));
# }
# // BUG? # // BUG?
# // Ensure(parse, escaped_shortcode) # // Ensure(parse, escaped_shortcode)