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