summaryrefslogtreecommitdiff
path: root/t/pagespec_match_result.t
blob: c2112bf140a053a1bea125103caafea6622d4463 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 71;
  5. BEGIN { use_ok("IkiWiki"); }
  6. # Note that new objects have to be constructed freshly for each test, since
  7. # object states are mutated as they are combined.
  8. sub S { IkiWiki::SuccessReason->new("match", @_) }
  9. sub F { IkiWiki::FailReason->new("no match", @_) }
  10. sub E { IkiWiki::ErrorReason->new("error in matching", @_) }
  11. ok(S() eq "match");
  12. ok(F() eq "no match");
  13. ok(E() eq "error in matching");
  14. ok(S());
  15. ok(! F());
  16. ok(! E());
  17. ok(!(! S()));
  18. ok(!(!(! F)));
  19. ok(!(!(! E)));
  20. ok(S() | F());
  21. ok(F() | S());
  22. ok(!(F() | E()));
  23. ok(!(!S() | F() | E()));
  24. ok(S() & S() & S());
  25. ok(!(S() & E()));
  26. ok(!(S() & F()));
  27. ok(!(S() & F() & E()));
  28. ok(S() & (F() | F() | S()));
  29. # influences are always merged, no matter the operation performed,
  30. # as long as the two items are always both present
  31. foreach my $op ('$s | $f', '$s & $f', '$s & $f & E()', '$s | E() | $f',
  32. '! $s | ! $f', '!(!(!$s)) | $f') {
  33. my $s=S(foo => 1, bar => 1);
  34. is($s->influences->{foo}, 1);
  35. is($s->influences->{bar}, 1);
  36. my $f=F(bar => 2, baz => 1);
  37. is($f->influences->{bar}, 2);
  38. is($f->influences->{baz}, 1);
  39. my $c = eval $op;
  40. ok(ref $c);
  41. is($c->influences->{foo}, 1, "foo ($op)");
  42. is($c->influences->{bar}, (1 | 2), "bar ($op)");
  43. is($c->influences->{baz}, 1, "baz ($op)");
  44. }
  45. my $s=S(foo => 0, bar => 1);
  46. $s->influences(baz => 1);
  47. ok(! $s->influences->{foo}, "removed 0 influence");
  48. ok(! $s->influences->{bar}, "removed 1 influence");
  49. ok($s->influences->{baz}, "set influence");
  50. ok($s->influences_static);
  51. # influence blocking
  52. my $r=F()->block & S(foo => 1);
  53. ok(! $r->influences->{foo}, "failed blocker & influence -> does not pass");
  54. $r=F()->block | S(foo => 1);
  55. ok($r->influences->{foo}, "failed blocker | influence -> does pass");
  56. $r=S(foo => 1) & F()->block;
  57. ok(! $r->influences->{foo}, "influence & failed blocker -> does not pass");
  58. $r=S(foo => 1) | F()->block;
  59. ok($r->influences->{foo}, "influence | failed blocker -> does pass");
  60. $r=S(foo => 1) & F()->block & S(foo => 2);
  61. ok(! $r->influences->{foo}, "influence & failed blocker & influence -> does not pass");
  62. $r=S(foo => 1) | F()->block | S(foo => 2);
  63. ok($r->influences->{foo}, "influence | failed blocker | influence -> does pass");
  64. $r=S()->block & S(foo => 1);
  65. ok($r->influences->{foo}, "successful blocker -> does pass");
  66. $r=(! S()->block) & S(foo => 1);
  67. ok(! $r->influences->{foo}, "! successful blocker -> failed blocker");