File: Pattern.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
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;