4 use Test::More tests => 17;
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 a=1]]", 0, 0), "foo(a => 1)");
27 is(IkiWiki::preprocess("foo", "foo", "[[foo a=\"1 2 3 4\"]]", 0, 0), "foo(a => 1 2 3 4)");
28 is(IkiWiki::preprocess("foo", "foo", "[[foo ]] then [[foo a=2]]", 0, 0),
29 "foo() then foo(a => 2)");
30 is(IkiWiki::preprocess("foo", "foo", "[[foo b c \"d and e=f\"]]", 0, 0), "foo(b, c, d and e=f)");
31 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1]]", 0, 0),
32 "foo(a => 1, b, c => 1)");
33 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1 \t\t]]", 0, 0),
34 "foo(a => 1, b, c => 1)", "whitespace");
35 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1\nb \nc=1]]", 0, 0),
36 "foo(a => 1, b, c => 1)", "multiline directive");
37 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 a=2 a=3]]", 0, 0),
38 "foo(a => 1, a => 2, a => 3)", "dup item");
39 is(IkiWiki::preprocess("foo", "foo", '[[foo a="[[bracketed]]" b=1]]', 0, 0),
40 "foo(a => [[bracketed]], b => 1)");
41 my $multiline="here is my \"first\"
44 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
45 "foo(a => $multiline)");
46 is(IkiWiki::preprocess("foo", "foo", '[[foo """'.$multiline.'"""]]', 0, 0),
48 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'""" b="foo"]]', 0, 0),
49 "foo(a => $multiline, b => foo)");
50 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'."\n".$multiline."\n".'""" b="foo"]]', 0, 0),
51 "foo(a => $multiline, b => foo)", "leading/trailing newline stripped");
54 local $TODO = "nested strings not yet implemented";
56 $multiline='here is a string containing another [[foo val="""string""]]';
57 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
58 "foo(a=> $multiline)", "nested multiline strings");