summaryrefslogtreecommitdiff
path: root/t/preprocess.t
blob: 7699f56baaa77737115fabe033e73e06383966e8 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 19;
  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. TODO: {
  52. local $TODO = "nested strings not yet implemented";
  53. $multiline='here is a string containing another [[foo val="""string""]]';
  54. is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0),
  55. "foo(a=> $multiline)", "nested multiline strings");
  56. }