4 use Test::More tests => 21;
6 BEGIN { use_ok("IkiWiki"); }
8 $IkiWiki::hooks{preprocess}{foo}{call}=sub {
13 next if $key eq 'page' || $key eq 'destpage' || $key eq 'preview';
15 push @bits, "$key => $value";
21 return "foo(".join(", ", @bits).")";
24 is(IkiWiki::preprocess("foo", "foo", "[[foo]]", 0, 0), "[[foo]]", "not wikilink");
25 is(IkiWiki::preprocess("foo", "foo", "[[foo ]]", 0, 0), "foo()", "simple");
26 is(IkiWiki::preprocess("foo", "foo", "[[!foo ]]", 0, 0), "foo()", "prefixed");
27 is(IkiWiki::preprocess("foo", "foo", "[[!foo]]", 0, 0), "[[!foo]]", "prefixed, no space");
28 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1]]", 0, 0), "foo(a => 1)");
29 is(IkiWiki::preprocess("foo", "foo", "[[foo a=\"1 2 3 4\"]]", 0, 0), "foo(a => 1 2 3 4)");
30 is(IkiWiki::preprocess("foo", "foo", "[[foo ]] then [[foo a=2]]", 0, 0),
31 "foo() then foo(a => 2)");
32 is(IkiWiki::preprocess("foo", "foo", "[[foo b c \"d and e=f\"]]", 0, 0), "foo(b, c, d and e=f)");
33 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1]]", 0, 0),
34 "foo(a => 1, b, c => 1)");
35 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1 \t\t]]", 0, 0),
36 "foo(a => 1, b, c => 1)", "whitespace");
37 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1\nb \nc=1]]", 0, 0),
38 "foo(a => 1, b, c => 1)", "multiline directive");
39 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 a=2 a=3]]", 0, 0),
40 "foo(a => 1, a => 2, a => 3)", "dup item");
41 is(IkiWiki::preprocess("foo", "foo", '[[foo a="[[bracketed]]" b=1]]', 0, 0),
42 "foo(a => [[bracketed]], b => 1)");
43 my $multiline="here is my \"first\"
46 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
47 "foo(a => $multiline)");
48 is(IkiWiki::preprocess("foo", "foo", '[[foo """'.$multiline.'"""]]', 0, 0),
50 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'""" b="foo"]]', 0, 0),
51 "foo(a => $multiline, b => foo)");
52 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'."\n".$multiline."\n".'""" b="foo"]]', 0, 0),
53 "foo(a => $multiline, b => foo)", "leading/trailing newline stripped");
54 my $long='[[foo a="""'.("a" x 100000).'';
55 is(IkiWiki::preprocess("foo", "foo", $long, 0, 0), $long,
56 "unterminated triple-quoted string inside unterminated directive(should not warn about over-recursion)");
57 is(IkiWiki::preprocess("foo", "foo", $long."]]", 0, 0), $long."]]",
58 "unterminated triple-quoted string is not treated as a bare word");
61 local $TODO = "nested strings not yet implemented";
63 $multiline='here is a string containing another [[foo val="""string""]]';
64 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
65 "foo(a=> $multiline)", "nested multiline strings");