summaryrefslogtreecommitdiff
path: root/t/renamepage.t
blob: 0aa3a1c9fda8b127446516490429de1b2c01f164 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 21;
  5. use Encode;
  6. BEGIN { use_ok("IkiWiki"); }
  7. BEGIN { use_ok("IkiWiki::Plugin::link"); }
  8. %config=IkiWiki::defaultconfig();
  9. $config{srcdir}=$config{destdir}="/dev/null";
  10. IkiWiki::checkconfig();
  11. # tests of the link plugin's renamelink function
  12. sub try {
  13. my ($page, $oldpage, $newpage, $content)=@_;
  14. %IkiWiki::pagecase=();
  15. %links=();
  16. $IkiWiki::config{userdir}="foouserdir";
  17. foreach my $page ($page, $oldpage, $newpage) {
  18. $IkiWiki::pagecase{lc $page}=$page;
  19. $links{$page}=[];
  20. }
  21. IkiWiki::Plugin::link::renamelink(
  22. page => $page,
  23. oldpage => $oldpage,
  24. newpage => $newpage,
  25. content => $content,
  26. );
  27. }
  28. is(try("z", "foo" => "bar", "[[xxx]]"), "[[xxx]]"); # unrelated link
  29. is(try("z", "foo" => "bar", "[[bar]]"), "[[bar]]"); # link already to new page
  30. is(try("z", "foo" => "bar", "[[foo]]"), "[[bar]]"); # basic conversion to new page name
  31. is(try("z", "foo" => "bar", "[[/foo]]"), "[[/bar]]"); # absolute link
  32. is(try("z", "foo" => "bar", "[[Foo]]"), "[[Bar]]"); # preserve case
  33. is(try("z", "x/foo" => "x/bar", "[[x/Foo]]"), "[[x/Bar]]"); # preserve case of subpage
  34. is(try("z", "foo" => "bar", "[[/Foo]]"), "[[/Bar]]"); # preserve case w/absolute
  35. is(try("z", "foo" => "bar", "[[foo]] [[xxx]]"), "[[bar]] [[xxx]]"); # 2 links, 1 converted
  36. is(try("z", "foo" => "bar", "[[xxx|foo]]"), "[[xxx|bar]]"); # conversion w/text
  37. is(try("z", "foo" => "bar", "[[foo#anchor]]"), "[[bar#anchor]]"); # with anchor
  38. is(try("z", "foo" => "bar", "[[xxx|foo#anchor]]"), "[[xxx|bar#anchor]]"); # with anchor
  39. is(try("z", "foo" => "bar", "[[!moo ]]"), "[[!moo ]]"); # preprocessor directive unchanged
  40. is(try("bugs", "bugs/foo" => "wishlist/bar", "[[foo]]"), "[[wishlist/bar]]"); # subpage link
  41. is(try("z", "foo_bar" => "bar", "[[foo_bar]]"), "[[bar]]"); # old link with underscore
  42. is(try("z", "foo" => "bar_foo", "[[foo]]"), "[[bar_foo]]"); # new link with underscore
  43. is(try("z", "foo_bar" => "bar_foo", "[[foo_bar]]"), "[[bar_foo]]"); # both with underscore
  44. is(try("z", "foo" => "bar__".ord("(")."__", "[[foo]]"), "[[bar(]]"); # new link with escaped chars
  45. is(try("z", "foo__".ord("(")."__" => "bar(", "[[foo(]]"), "[[bar(]]"); # old link with escaped chars
  46. is(try("z", "foo__".ord("(")."__" => "bar__".ord(")")."__", "[[foo(]]"), "[[bar)]]"); # both with escaped chars