summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-10-09 21:12:14 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-10-09 21:12:14 -0400
commit6d6fff8d87ae304427e222d20e4e49e671e3b0f3 (patch)
tree881a386bf1129dabe030c75732e46afd4f5c093c /t
parenta169e7b6a81485a918992328f053d899e3614547 (diff)
added tests of SuccessReason/FailReason objects
Diffstat (limited to 't')
-rwxr-xr-xt/pagespec_match_result.t54
1 files changed, 54 insertions, 0 deletions
diff --git a/t/pagespec_match_result.t b/t/pagespec_match_result.t
new file mode 100755
index 000000000..2319d8733
--- /dev/null
+++ b/t/pagespec_match_result.t
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More tests => 67;
+
+BEGIN { use_ok("IkiWiki"); }
+
+# Note that new objects have to be constructed freshly for each test, since
+# object states are mutated as they are combined.
+sub S { IkiWiki::SuccessReason->new("match") }
+sub F { IkiWiki::FailReason->new("no match") }
+sub E { IkiWiki::ErrorReason->new("error in matching") }
+
+ok(S() eq "match");
+ok(F() eq "no match");
+ok(E() eq "error in matching");
+
+ok(S());
+ok(! F());
+ok(! E());
+
+ok(!(! S()));
+ok(!(!(! F)));
+ok(!(!(! E)));
+
+ok(S() | F());
+ok(F() | S());
+ok(!(F() | E()));
+ok(!(!S() | F() | E()));
+
+ok(S() & S() & S());
+ok(!(S() & E()));
+ok(!(S() & F()));
+ok(!(S() & F() & E()));
+ok(S() & (F() | F() | S()));
+
+# influences are always merged, no matter the operation performed,
+# as long as the two items are always both present
+foreach my $op ('$s | $f', '$s & $f', '$s & $f & E()', '$s | E() | $f',
+ '! $s | ! $f', '!(!(!$s)) | $f') {
+ my $s=S();
+ $s->influences(foo => 1, bar => 1);
+ is($s->influences->{foo}, 1);
+ is($s->influences->{bar}, 1);
+ my $f=F();
+ $f->influences(bar => 2, baz => 1);
+ is($f->influences->{bar}, 2);
+ is($f->influences->{baz}, 1);
+ my $c = eval $op;
+ ok(ref $c);
+ is($c->influences->{foo}, 1, "foo ($op)");
+ is($c->influences->{bar}, (1 | 2), "bar ($op)");
+ is($c->influences->{baz}, 1, "baz ($op)");
+}