summaryrefslogtreecommitdiff
path: root/t/bestlink.t
blob: 9358bf3764b8b70afebab980b3316904f5602a62 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 9;
  5. BEGIN { use_ok("IkiWiki"); }
  6. sub test ($$$) {
  7. my $page=shift;
  8. my $link=shift;
  9. my @existing_pages=@{shift()};
  10. %IkiWiki::pagecase=();
  11. %links=();
  12. foreach my $page (@existing_pages) {
  13. $IkiWiki::pagecase{lc $page}=$page;
  14. $links{$page}=[];
  15. }
  16. return bestlink($page, $link);
  17. }
  18. is(test("bar", "foo", ["bar"]), "", "broken link");
  19. is(test("bar", "foo", ["bar", "foo"]), "foo", "simple link");
  20. is(test("bar", "FoO", ["bar", "foo"]), "foo", "simple link with different input case");
  21. is(test("bar", "foo", ["bar", "fOo"]), "fOo", "simple link with different page case");
  22. is(test("bar", "FoO", ["bar", "fOo"]), "fOo", "simple link with different page and input case");
  23. is(test("bar", "Foo", ["bar", "fOo", "foo", "fOO", "Foo", "fOo"]), "Foo", "in case of ambiguity, like case wins");
  24. is(test("bar", "foo", ["bar", "foo", "bar/foo"]), "bar/foo", "simple subpage link");
  25. is(test("bar", "foo/subpage", ["bar", "foo", "bar/subpage", "foo/subpage"]), "foo/subpage", "cross subpage link");