4 use Test::More tests => 34;
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", q{[[foo a="1"]]}, 0, 0), "foo(a => 1)");
30 is(IkiWiki::preprocess("foo", "foo", q{[[foo a="""1"""]]}, 0, 0), "foo(a => 1)");
31 is(IkiWiki::preprocess("foo", "foo", q{[[foo a=""]]}, 0, 0), "foo(a)");
32 is(IkiWiki::preprocess("foo", "foo", q{[[foo a="" b="1"]]}, 0, 0), "foo(a, b => 1)");
33 is(IkiWiki::preprocess("foo", "foo", q{[[foo a=""""""]]}, 0, 0), "foo(a)");
34 is(IkiWiki::preprocess("foo", "foo", q{[[foo a="""""" b="1"]]}, 0, 0), "foo(a, b => 1)");
35 is(IkiWiki::preprocess("foo", "foo", q{[[foo a="""""" b="""1"""]]}, 0, 0), "foo(a, b => 1)");
36 is(IkiWiki::preprocess("foo", "foo", q{[[foo a="""""" b=""""""]]}, 0, 0), "foo(a, b)");
37 is(IkiWiki::preprocess("foo", "foo", q{[[foo a="" b=""""""]]}, 0, 0), "foo(a, b)");
38 is(IkiWiki::preprocess("foo", "foo", q{[[foo a="" b="""1"""]]}, 0, 0), "foo(a, b => 1)");
39 is(IkiWiki::preprocess("foo", "foo", "[[foo a=\"1 2 3 4\"]]", 0, 0), "foo(a => 1 2 3 4)");
40 is(IkiWiki::preprocess("foo", "foo", "[[foo ]] then [[foo a=2]]", 0, 0),
41 "foo() then foo(a => 2)");
42 is(IkiWiki::preprocess("foo", "foo", "[[foo b c \"d and e=f\"]]", 0, 0), "foo(b, c, d and e=f)");
43 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1]]", 0, 0),
44 "foo(a => 1, b, c => 1)");
45 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1 \t\t]]", 0, 0),
46 "foo(a => 1, b, c => 1)", "whitespace");
47 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1\nb \nc=1]]", 0, 0),
48 "foo(a => 1, b, c => 1)", "multiline directive");
49 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 a=2 a=3]]", 0, 0),
50 "foo(a => 1, a => 2, a => 3)", "dup item");
51 is(IkiWiki::preprocess("foo", "foo", '[[foo a="[[bracketed]]" b=1]]', 0, 0),
52 "foo(a => [[bracketed]], b => 1)");
53 my $multiline="here is my \"first\"
56 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
57 "foo(a => $multiline)");
58 is(IkiWiki::preprocess("foo", "foo", '[[foo """'.$multiline.'"""]]', 0, 0),
60 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'""" b="foo"]]', 0, 0),
61 "foo(a => $multiline, b => foo)");
62 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'."\n".$multiline."\n".'""" b="foo"]]', 0, 0),
63 "foo(a => $multiline, b => foo)", "leading/trailing newline stripped");
64 my $long='[[foo a="""'.("a" x 100000).'';
65 is(IkiWiki::preprocess("foo", "foo", $long, 0, 0), $long,
66 "unterminated triple-quoted string inside unterminated directive(should not warn about over-recursion)");
67 is(IkiWiki::preprocess("foo", "foo", $long."]]", 0, 0), $long."]]",
68 "unterminated triple-quoted string is not treated as a bare word");
70 is(IkiWiki::preprocess("foo", "foo", "[[!foo a=<<HEREDOC\n".$multiline."\nHEREDOC]]", 0, 0),
71 "foo(a => $multiline)", "nested strings via heredoc (for key)");
72 is(IkiWiki::preprocess("foo", "foo", "[[!foo <<HEREDOC\n".$multiline."\nHEREDOC]]", 0, 0),
73 "foo($multiline)", "nested strings via heredoc (without keyless)");
74 is(IkiWiki::preprocess("foo", "foo", "[[!foo '''".$multiline."''']]", 0, 0),
75 "foo($multiline)", "triple-single-quoted multiline string");
78 local $TODO = "nested strings not yet implemented";
80 $multiline='here is a string containing another [[foo val="""string""]]';
81 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
82 "foo(a => $multiline)", "nested multiline strings");