summaryrefslogtreecommitdiff
path: root/t/preprocess.t
blob: e5026ed64b575ba8ed2215e468bb322d4086f020 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 21;
  5. BEGIN { use_ok("IkiWiki"); }
  6. $IkiWiki::hooks{preprocess}{foo}{call}=sub {
  7. my @bits;
  8. while (@_) {
  9. my $key=shift;
  10. my $value=shift;
  11. next if $key eq 'page' || $key eq 'destpage' || $key eq 'preview';
  12. if (length $value) {
  13. push @bits, "$key => $value";
  14. }
  15. else {
  16. push @bits, $key;
  17. }
  18. }
  19. return "foo(".join(", ", @bits).")";
  20. };
  21. is(IkiWiki::preprocess("foo", "foo", "[[foo]]", 0, 0), "[[foo]]", "not wikilink");
  22. is(IkiWiki::preprocess("foo", "foo", "[[foo ]]", 0, 0), "foo()", "simple");
  23. is(IkiWiki::preprocess("foo", "foo", "[[!foo ]]", 0, 0), "foo()", "prefixed");
  24. is(IkiWiki::preprocess("foo", "foo", "[[!foo]]", 0, 0), "[[!foo]]", "prefixed, no space");
  25. is(IkiWiki::preprocess("foo", "foo", "[[foo a=1]]", 0, 0), "foo(a => 1)");
  26. is(IkiWiki::preprocess("foo", "foo", "[[foo a=\"1 2 3 4\"]]", 0, 0), "foo(a => 1 2 3 4)");
  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 and e=f\"]]", 0, 0), "foo(b, c, d and e=f)");
  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 b c=1 \t\t]]", 0, 0),
  33. "foo(a => 1, b, c => 1)", "whitespace");
  34. is(IkiWiki::preprocess("foo", "foo", "[[foo a=1\nb \nc=1]]", 0, 0),
  35. "foo(a => 1, b, c => 1)", "multiline directive");
  36. is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 a=2 a=3]]", 0, 0),
  37. "foo(a => 1, a => 2, a => 3)", "dup item");
  38. is(IkiWiki::preprocess("foo", "foo", '[[foo a="[[bracketed]]" b=1]]', 0, 0),
  39. "foo(a => [[bracketed]], b => 1)");
  40. my $multiline="here is my \"first\"
  41. !! [[multiline ]] !!
  42. string!";
  43. is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
  44. "foo(a => $multiline)");
  45. is(IkiWiki::preprocess("foo", "foo", '[[foo """'.$multiline.'"""]]', 0, 0),
  46. "foo($multiline)");
  47. is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'""" b="foo"]]', 0, 0),
  48. "foo(a => $multiline, b => foo)");
  49. is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'."\n".$multiline."\n".'""" b="foo"]]', 0, 0),
  50. "foo(a => $multiline, b => foo)", "leading/trailing newline stripped");
  51. my $long='[[foo a="""'.("a" x 100000).'';
  52. is(IkiWiki::preprocess("foo", "foo", $long, 0, 0), $long,
  53. "unterminated triple-quoted string inside unterminated directive(should not warn about over-recursion)");
  54. is(IkiWiki::preprocess("foo", "foo", $long."]]", 0, 0), $long."]]",
  55. "unterminated triple-quoted string is not treated as a bare word");
  56. TODO: {
  57. local $TODO = "nested strings not yet implemented";
  58. $multiline='here is a string containing another [[foo val="""string""]]';
  59. is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
  60. "foo(a=> $multiline)", "nested multiline strings");
  61. }