File: String.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 (78 lines) | stat: -rw-r--r-- 4,046 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use Test2::Bundle::Extended -target => 'Test2::Compare::String';

my $number = $CLASS->new(input => '22.0');
my $string = $CLASS->new(input => 'hello');
my $untru1 = $CLASS->new(input => '');
my $untru2 = $CLASS->new(input => 0);

isa_ok($_, $CLASS, 'Test2::Compare::Base') for $number, $string, $untru1, $untru2;

subtest name => sub {
    is($number->name, '22.0',    "got expected name");
    is($string->name, 'hello',   "got expected name");
    is($untru1->name, '',        "got expected name");
    is($untru2->name, '0',       "got expected name");
};

subtest operator => sub {
    is($number->operator(),      '',   "no operator for number + nothing");
    is($number->operator(undef), '',   "no operator for number + undef");
    is($number->operator('x'),   'eq', "eq operator for number + string");
    is($number->operator(1),     'eq', "eq operator for number + number");

    is($string->operator(),      '',   "no operator for string + nothing");
    is($string->operator(undef), '',   "no operator for string + undef");
    is($string->operator('x'),   'eq', "eq operator for string + string");
    is($string->operator(1),     'eq', "eq operator for string + number");

    is($untru1->operator(),      '',   "no operator for empty string + nothing");
    is($untru1->operator(undef), '',   "no operator for empty string + undef");
    is($untru1->operator('x'),   'eq', "eq operator for empty string + string");
    is($untru1->operator(1),     'eq', "eq operator for empty string + number");

    is($untru2->operator(),      '',   "no operator for 0 + nothing");
    is($untru2->operator(undef), '',   "no operator for 0 + undef");
    is($untru2->operator('x'),   'eq', "eq operator for 0 + string");
    is($untru2->operator(1),     'eq', "eq operator for 0 + number");
};

subtest verify => sub {
    ok(!$number->verify(exists => 0, got => undef), 'does not verify against DNE');
    ok(!$number->verify(exists => 1, got => {}),    'ref will not verify');
    ok(!$number->verify(exists => 1, got => undef), 'looking for a number, not undef');
    ok(!$number->verify(exists => 1, got => 'x'),   'not looking for a string');
    ok(!$number->verify(exists => 1, got => 1),     'wrong number');
    ok(!$number->verify(exists => 1, got => 22),     '22.0 ne 22');
    ok($number->verify(exists => 1, got => '22.0'), 'exact match with decimal');

    ok(!$string->verify(exists => 0, got => undef), 'does not verify against DNE');
    ok(!$string->verify(exists => 1, got => {}),    'ref will not verify');
    ok(!$string->verify(exists => 1, got => undef), 'looking for a string, not undef');
    ok(!$string->verify(exists => 1, got => 'x'),   'looking for a different string');
    ok(!$string->verify(exists => 1, got => 1),     'looking for a string, not a number');
    ok($string->verify(exists => 1, got => 'hello'), 'exact match');

    ok(!$untru1->verify(exists => 0, got => undef), 'does not verify against DNE');
    ok(!$untru1->verify(exists => 1, got => {}),    'ref will not verify');
    ok(!$untru1->verify(exists => 1, got => undef), 'looking for a string, not undef');
    ok(!$untru1->verify(exists => 1, got => 'x'),   'wrong string');
    ok(!$untru1->verify(exists => 1, got => 1),     'not a number');
    ok($untru1->verify(exists => 1, got => ''), 'exact match, empty string');

    ok(!$untru2->verify(exists => 0, got => undef), 'does not verify against DNE');
    ok(!$untru2->verify(exists => 1, got => {}),    'ref will not verify');
    ok(!$untru2->verify(exists => 1, got => undef), 'undef is not 0 for this test');
    ok(!$untru2->verify(exists => 1, got => 'x'),   'x is not 0');
    ok(!$untru2->verify(exists => 1, got => 1),     '1 is not 0');
    ok(!$untru2->verify(exists => 1, got => '0.0'),  '0.0 ne 0');
    ok(!$untru2->verify(exists => 1, got => '-0.0'), '-0.0 ne 0');
    ok($untru2->verify(exists => 1, got => 0),      'got 0');
};

like(
    dies { $CLASS->new() },
    qr/input must be defined for 'String' check/,
    "Cannot use undef as a string"
);

done_testing;