summaryrefslogtreecommitdiff
path: root/t/pagespec_match_result.t
blob: d9c31d6f062a47b8d976b1bf14d54b247d11957b (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);