summaryrefslogtreecommitdiff
path: root/t/tag.t
blob: cc0a30cadf481c6d0d9be8ad431e67d05f84790e (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use Test::More tests => 24;
  6. BEGIN { use_ok("IkiWiki"); }
  7. BEGIN { use_ok("IkiWiki::Render"); }
  8. BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
  9. BEGIN { use_ok("IkiWiki::Plugin::tag"); }
  10. ok(! system("rm -rf t/tmp; mkdir t/tmp"));
  11. $config{srcdir} = 't/tmp';
  12. $config{underlaydir} = 't/tmp';
  13. $config{templatedir} = 'templates';
  14. $config{usedirs} = 1;
  15. $config{htmlext} = 'html';
  16. $config{wiki_file_chars} = "-[:alnum:]+/.:_";
  17. $config{userdir} = "users";
  18. $config{tagbase} = "tags";
  19. $config{tag_autocreate} = 1;
  20. $config{tag_autocreate_commit} = 0;
  21. $config{default_pageext} = "mdwn";
  22. $config{wiki_file_prune_regexps} = [qr/^\./];
  23. $config{underlaydirbase} = '.';
  24. is(checkconfig(), 1);
  25. %oldrenderedfiles=%pagectime=();
  26. %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
  27. %destsources=%renderedfiles=%pagecase=%pagestate=();
  28. foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
  29. $pagesources{$page} = "$page.mdwn";
  30. $pagemtime{$page} = $pagectime{$page} = 1000000;
  31. writefile("$page.mdwn", "t/tmp", "your ad here");
  32. }
  33. $links{one}=[qw(tags/numbers alpha tags/letters)];
  34. $links{two}=[qw(tags/numbers)];
  35. $links{alpha}=[qw(tags/letters one)];
  36. $links{beta}=[qw(tags/letters)];
  37. $typedlinks{one}={tag => {"tags/numbers" => 1 }};
  38. $typedlinks{two}={tag => {"tags/numbers" => 1 }};
  39. $typedlinks{alpha}={tag => {"tags/letters" => 1 }};
  40. $typedlinks{beta}={tag => {"tags/letters" => 1 }};
  41. ok(pagespec_match("one", "tagged(numbers)"));
  42. ok(!pagespec_match("two", "tagged(alpha)"));
  43. ok(pagespec_match("one", "link(tags/numbers)"));
  44. ok(pagespec_match("one", "link(alpha)"));
  45. # emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing
  46. # the "numbers" and "primes" tag pages to be auto-created
  47. IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef);
  48. is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag");
  49. is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag");
  50. is($autofiles{"tags/primes.mdwn"}{plugin}, "tag");
  51. is_deeply([sort keys %autofiles], [qw(tags/lucky.mdwn tags/numbers.mdwn tags/primes.mdwn)]);
  52. ok(!-e "t/tmp/tags/lucky.mdwn");
  53. my (%pages, @del);
  54. IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
  55. ok(! -s "t/tmp/tags/lucky.mdwn");
  56. ok(-s "t/tmp/.ikiwiki/transient/tags/lucky.mdwn");
  57. is_deeply(\%pages, {"t/tmp/tags/lucky" => 1});
  58. is_deeply(\@del, []);
  59. # generating an autofile that already exists does nothing
  60. %pages = @del = ();
  61. IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del);
  62. is_deeply(\%pages, {});
  63. is_deeply(\@del, []);
  64. # generating an autofile that we just deleted does nothing
  65. %pages = ();
  66. @del = ('tags/primes.mdwn');
  67. IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del);
  68. is_deeply(\%pages, {});
  69. is_deeply(\@del, ['tags/primes.mdwn']);
  70. # cleanup
  71. ok(! system("rm -rf t/tmp"));
  72. 1;