| 1 |
use Test2::Bundle::Extended -target => 'Test2::Compare::String'; |
| 2 |
|
| 3 |
my $number = $CLASS->new(input => '22.0'); |
| 4 |
my $string = $CLASS->new(input => 'hello'); |
| 5 |
my $untru1 = $CLASS->new(input => ''); |
| 6 |
my $untru2 = $CLASS->new(input => 0); |
| 7 |
|
| 8 |
isa_ok($_, $CLASS, 'Test2::Compare::Base') for $number, $string, $untru1, $untru2; |
| 9 |
|
| 10 |
subtest name => sub { |
| 11 |
is($number->name, '22.0', "got expected name"); |
| 12 |
is($string->name, 'hello', "got expected name"); |
| 13 |
is($untru1->name, '', "got expected name"); |
| 14 |
is($untru2->name, '0', "got expected name"); |
| 15 |
}; |
| 16 |
|
| 17 |
subtest operator => sub { |
| 18 |
is($number->operator(), '', "no operator for number + nothing"); |
| 19 |
is($number->operator(undef), '', "no operator for number + undef"); |
| 20 |
is($number->operator('x'), 'eq', "eq operator for number + string"); |
| 21 |
is($number->operator(1), 'eq', "eq operator for number + number"); |
| 22 |
|
| 23 |
is($string->operator(), '', "no operator for string + nothing"); |
| 24 |
is($string->operator(undef), '', "no operator for string + undef"); |
| 25 |
is($string->operator('x'), 'eq', "eq operator for string + string"); |
| 26 |
is($string->operator(1), 'eq', "eq operator for string + number"); |
| 27 |
|
| 28 |
is($untru1->operator(), '', "no operator for empty string + nothing"); |
| 29 |
is($untru1->operator(undef), '', "no operator for empty string + undef"); |
| 30 |
is($untru1->operator('x'), 'eq', "eq operator for empty string + string"); |
| 31 |
is($untru1->operator(1), 'eq', "eq operator for empty string + number"); |
| 32 |
|
| 33 |
is($untru2->operator(), '', "no operator for 0 + nothing"); |
| 34 |
is($untru2->operator(undef), '', "no operator for 0 + undef"); |
| 35 |
is($untru2->operator('x'), 'eq', "eq operator for 0 + string"); |
| 36 |
is($untru2->operator(1), 'eq', "eq operator for 0 + number"); |
| 37 |
}; |
| 38 |
|
| 39 |
subtest verify => sub { |
| 40 |
ok(!$number->verify(exists => 0, got => undef), 'does not verify against DNE'); |
| 41 |
ok(!$number->verify(exists => 1, got => {}), 'ref will not verify'); |
| 42 |
ok(!$number->verify(exists => 1, got => undef), 'looking for a number, not undef'); |
| 43 |
ok(!$number->verify(exists => 1, got => 'x'), 'not looking for a string'); |
| 44 |
ok(!$number->verify(exists => 1, got => 1), 'wrong number'); |
| 45 |
ok(!$number->verify(exists => 1, got => 22), '22.0 ne 22'); |
| 46 |
ok($number->verify(exists => 1, got => '22.0'), 'exact match with decimal'); |
| 47 |
|
| 48 |
ok(!$string->verify(exists => 0, got => undef), 'does not verify against DNE'); |
| 49 |
ok(!$string->verify(exists => 1, got => {}), 'ref will not verify'); |
| 50 |
ok(!$string->verify(exists => 1, got => undef), 'looking for a string, not undef'); |
| 51 |
ok(!$string->verify(exists => 1, got => 'x'), 'looking for a different string'); |
| 52 |
ok(!$string->verify(exists => 1, got => 1), 'looking for a string, not a number'); |
| 53 |
ok($string->verify(exists => 1, got => 'hello'), 'exact match'); |
| 54 |
|
| 55 |
ok(!$untru1->verify(exists => 0, got => undef), 'does not verify against DNE'); |
| 56 |
ok(!$untru1->verify(exists => 1, got => {}), 'ref will not verify'); |
| 57 |
ok(!$untru1->verify(exists => 1, got => undef), 'looking for a string, not undef'); |
| 58 |
ok(!$untru1->verify(exists => 1, got => 'x'), 'wrong string'); |
| 59 |
ok(!$untru1->verify(exists => 1, got => 1), 'not a number'); |
| 60 |
ok($untru1->verify(exists => 1, got => ''), 'exact match, empty string'); |
| 61 |
|
| 62 |
ok(!$untru2->verify(exists => 0, got => undef), 'does not verify against DNE'); |
| 63 |
ok(!$untru2->verify(exists => 1, got => {}), 'ref will not verify'); |
| 64 |
ok(!$untru2->verify(exists => 1, got => undef), 'undef is not 0 for this test'); |
| 65 |
ok(!$untru2->verify(exists => 1, got => 'x'), 'x is not 0'); |
| 66 |
ok(!$untru2->verify(exists => 1, got => 1), '1 is not 0'); |
| 67 |
ok(!$untru2->verify(exists => 1, got => '0.0'), '0.0 ne 0'); |
| 68 |
ok(!$untru2->verify(exists => 1, got => '-0.0'), '-0.0 ne 0'); |
| 69 |
ok($untru2->verify(exists => 1, got => 0), 'got 0'); |
| 70 |
}; |
| 71 |
|
| 72 |
like( |
| 73 |
dies { $CLASS->new() }, |
| 74 |
qr/input must be defined for 'String' check/, |
| 75 |
"Cannot use undef as a string" |
| 76 |
); |
| 77 |
|
| 78 |
done_testing; |