File: Pattern.t

package info (click to toggle)
libtest-simple-perl 1.302211-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,972 kB
  • sloc: perl: 19,894; makefile: 7
file content (30 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use Test2::Bundle::Extended -target => 'Test2::Compare::Pattern';

my $one = $CLASS->new(pattern => qr/HASH/);
isa_ok($one, $CLASS, 'Test2::Compare::Base');
is($one->name, "" . qr/HASH/, "got name");
is($one->operator, '=~', "got operator");
ok(!$one->verify(got => {}, exists => 1), "A hashref does not validate against the pattern 'HASH'");
ok(!$one->verify(exists => 0), "DNE does not validate");
ok(!$one->verify(exists => 1, got => undef), "undef does not validate");
ok(!$one->verify(exists => 1, got => 'foo'), "Not a match");
ok($one->verify(exists => 1, got => 'A HASH B'), "Matches");

$one = $CLASS->new(pattern => qr/HASH/, negate => 1);
isa_ok($one, $CLASS, 'Test2::Compare::Base');
is($one->name, "" . qr/HASH/, "got name");
is($one->operator, '!~', "got operator");
ok(!$one->verify(exists => 1, got => {}), "A hashref does not validate against the pattern 'HASH' even when negated");
ok(!$one->verify(exists => 0), "DNE does not validate");
ok(!$one->verify(exists => 1, got => undef), "undef does not validate");
ok($one->verify(exists => 1, got => 'foo'), "Not a match, but negated");
ok(!$one->verify(exists => 1, got => 'A HASH B'), "Matches, but negated");


like(
    dies { $CLASS->new },
    qr/'pattern' is a required attribute/,
    "Need to specify a pattern"
);

done_testing;