4 use Test::More tests => 14;
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 ]] then [[foo a=2]]", 0, 0),
28 "foo() then foo(a => 2)");
29 is(IkiWiki::preprocess("foo", "foo", "[[foo b c \"d\"]]", 0, 0), "foo(b, c, d)");
30 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1]]", 0, 0),
31 "foo(a => 1, b, c => 1)");
32 is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 a=2 a=3]]", 0, 0),
33 "foo(a => 1, a => 2, a => 3)", "dup item");
34 is(IkiWiki::preprocess("foo", "foo", '[[foo a="[[bracketed]]" b=1]]', 0, 0),
35 "foo(a => [[bracketed]], b => 1)");
36 my $multiline="here is my \"first\"
39 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
40 "foo(a => $multiline)");
41 is(IkiWiki::preprocess("foo", "foo", '[[foo """'.$multiline.'"""]]', 0, 0),
43 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'""" b="foo"]]', 0, 0),
44 "foo(a => $multiline, b => foo)");
45 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'."\n".$multiline."\n".'""" b="foo"]]', 0, 0),
46 "foo(a => $multiline, b => foo)", "leading/trailing newline stripped");
49 local $TODO = "nested strings not yet implemented";
51 $multiline='here is a string containing another [[foo val="""string""]]';
52 is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
53 "foo(a=> $multiline)", "nested multiline strings");