summaryrefslogtreecommitdiff
path: root/t/bestlink.t
blob: ece900152e0b0648ba686895baa2036e18f1945f (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 9;
  5. sub test ($$$) {
  6. my $page=shift;
  7. my $link=shift;
  8. my @existing_pages=@{shift()};
  9. %IkiWiki::pagecase=();
  10. %IkiWiki::links=();
  11. foreach my $page (@existing_pages) {
  12. $IkiWiki::pagecase{lc $page}=$page;
  13. $IkiWiki::links{$page}=[];
  14. }
  15. return IkiWiki::bestlink($page, $link);
  16. }
  17. BEGIN { use_ok("IkiWiki"); }
  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");