4 use Test::More tests => 13;
11 my @existing_pages=@{shift()};
13 # This is what linkify and htmllink need set right now to work.
14 # This could change, if so, update it..
16 foreach my $page (@existing_pages) {
17 $IkiWiki::links{$page}=[];
18 $IkiWiki::renderedfiles{"$page.mdwn"}=$page;
20 %IkiWiki::config=IkiWiki::defaultconfig();
22 return IkiWiki::linkify($lpage, $page, $content);
29 if ($content =~ m!<a href="[^"]*\Q$link\E[^"]*">!) {
33 print STDERR "# expected link to $link in $content\n";
38 sub not_links_to ($$) {
42 if ($content !~ m!<a href="[^"]*\Q$link\E[^"]*">!) {
46 print STDERR "# expected no link to $link in $content\n";
55 if ($content =~ m!>\Q$text\E</a>!) {
59 print STDERR "# expected link text $text in $content\n";
65 BEGIN { use_ok("IkiWiki::Render"); }
67 ok(links_to("bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo", "bar"])), "ok link");
68 ok(not_links_to("bar", linkify("foo", "foo", "link to \\[[bar]] ok", ["foo", "bar"])), "escaped link");
69 ok(links_to("page=bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo"])), "broken link");
70 ok(links_to("bar", linkify("foo", "foo", "link to [[baz]] and [[bar]] ok", ["foo", "baz", "bar"])), "dual links");
71 ok(links_to("baz", linkify("foo", "foo", "link to [[baz]] and [[bar]] ok", ["foo", "baz", "bar"])), "dual links");
72 ok(links_to("bar", linkify("foo", "foo", "link to [[some_page|bar]] ok", ["foo", "bar"])), "named link");
73 ok(links_text("some page", linkify("foo", "foo", "link to [[some_page|bar]] ok", ["foo", "bar"])), "named link text");
74 ok(links_to("bar", linkify("foo", "foo", "link to [[some page|bar]] ok", ["foo", "bar"])), "named link, with whitespace");
75 ok(links_text("some page", linkify("foo", "foo", "link to [[some page|bar]] ok", ["foo", "bar"])), "named link text, with whitespace");
76 ok(links_text("Some long, & complex page name.", linkify("foo", "foo", "link to [[Some long, & complex page name.|bar]] ok, and this is not a link]] here", ["foo", "bar"])), "complex named link text");
77 ok(links_to("foo/bar", linkify("foo/item", "foo", "link to [[bar]] ok", ["foo", "foo/item", "foo/bar"])), "inline page link");
78 ok(links_to("bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo", "foo/item", "foo/bar"])), "same except not inline");