| 1 |
use Test2::Bundle::Extended -target => 'Test2::Compare::Pattern'; |
| 2 |
|
| 3 |
my $one = $CLASS->new(pattern => qr/HASH/); |
| 4 |
isa_ok($one, $CLASS, 'Test2::Compare::Base'); |
| 5 |
is($one->name, "" . qr/HASH/, "got name"); |
| 6 |
is($one->operator, '=~', "got operator"); |
| 7 |
ok(!$one->verify(got => {}, exists => 1), "A hashref does not validate against the pattern 'HASH'"); |
| 8 |
ok(!$one->verify(exists => 0), "DNE does not validate"); |
| 9 |
ok(!$one->verify(exists => 1, got => undef), "undef does not validate"); |
| 10 |
ok(!$one->verify(exists => 1, got => 'foo'), "Not a match"); |
| 11 |
ok($one->verify(exists => 1, got => 'A HASH B'), "Matches"); |
| 12 |
|
| 13 |
$one = $CLASS->new(pattern => qr/HASH/, negate => 1); |
| 14 |
isa_ok($one, $CLASS, 'Test2::Compare::Base'); |
| 15 |
is($one->name, "" . qr/HASH/, "got name"); |
| 16 |
is($one->operator, '!~', "got operator"); |
| 17 |
ok(!$one->verify(exists => 1, got => {}), "A hashref does not validate against the pattern 'HASH' even when negated"); |
| 18 |
ok(!$one->verify(exists => 0), "DNE does not validate"); |
| 19 |
ok(!$one->verify(exists => 1, got => undef), "undef does not validate"); |
| 20 |
ok($one->verify(exists => 1, got => 'foo'), "Not a match, but negated"); |
| 21 |
ok(!$one->verify(exists => 1, got => 'A HASH B'), "Matches, but negated"); |
| 22 |
|
| 23 |
|
| 24 |
like( |
| 25 |
dies { $CLASS->new }, |
| 26 |
qr/'pattern' is a required attribute/, |
| 27 |
"Need to specify a pattern" |
| 28 |
); |
| 29 |
|
| 30 |
done_testing; |