4 use Test::More tests => 71;
6 BEGIN { use_ok("IkiWiki"); }
8 # Note that new objects have to be constructed freshly for each test, since
9 # object states are mutated as they are combined.
10 sub S { IkiWiki::SuccessReason->new("match", @_) }
11 sub F { IkiWiki::FailReason->new("no match", @_) }
12 sub E { IkiWiki::ErrorReason->new("error in matching", @_) }
15 ok(F() eq "no match");
16 ok(E() eq "error in matching");
29 ok(!(!S() | F() | E()));
34 ok(!(S() & F() & E()));
35 ok(S() & (F() | F() | S()));
37 # influences are always merged, no matter the operation performed,
38 # as long as the two items are always both present
39 foreach my $op ('$s | $f', '$s & $f', '$s & $f & E()', '$s | E() | $f',
40 '! $s | ! $f', '!(!(!$s)) | $f') {
41 my $s=S(foo => 1, bar => 1);
42 is($s->influences->{foo}, 1);
43 is($s->influences->{bar}, 1);
44 my $f=F(bar => 2, baz => 1);
45 is($f->influences->{bar}, 2);
46 is($f->influences->{baz}, 1);
49 is($c->influences->{foo}, 1, "foo ($op)");
50 is($c->influences->{bar}, (1 | 2), "bar ($op)");
51 is($c->influences->{baz}, 1, "baz ($op)");
54 my $s=S(foo => 0, bar => 1);
55 $s->influences(baz => 1);
56 ok(! $s->influences->{foo}, "removed 0 influence");
57 ok(! $s->influences->{bar}, "removed 1 influence");
58 ok($s->influences->{baz}, "set influence");
59 ok($s->influences_static);
62 my $r=F()->block & S(foo => 1);
63 ok(! $r->influences->{foo}, "failed blocker & influence -> does not pass");
64 $r=F()->block | S(foo => 1);
65 ok($r->influences->{foo}, "failed blocker | influence -> does pass");
66 $r=S(foo => 1) & F()->block;
67 ok(! $r->influences->{foo}, "influence & failed blocker -> does not pass");
68 $r=S(foo => 1) | F()->block;
69 ok($r->influences->{foo}, "influence | failed blocker -> does pass");
70 $r=S(foo => 1) & F()->block & S(foo => 2);
71 ok(! $r->influences->{foo}, "influence & failed blocker & influence -> does not pass");
72 $r=S(foo => 1) | F()->block | S(foo => 2);
73 ok($r->influences->{foo}, "influence | failed blocker | influence -> does pass");
74 $r=S()->block & S(foo => 1);
75 ok($r->influences->{foo}, "successful blocker -> does pass");
76 $r=(! S()->block) & S(foo => 1);
77 ok(! $r->influences->{foo}, "! successful blocker -> failed blocker");