File Coverage

File:t/06-data-util.t
Coverage:92.2%

linestmtbrancondsubpodtimecode
1#!perl
2
3
1
1
1
25428
4
68
use strict;
4
1
1
1
4
2
43
use warnings;
5
6
1
1
1
620
23844
8
use Test::More tests => 16;
7
8
1
1
1
1574
4
3180
use Util::Underscore;
9
10my %functions = (
11
16
67
    is_ref => sub { _::is_ref $_, 2, 3 },
12
16
60
    is_scalar_ref => sub { _::is_scalar_ref $_, 2, 3 },
13
16
64
    is_array_ref => sub { _::is_array_ref $_, 2, 3 },
14
16
66
    is_hash_ref => sub { _::is_hash_ref $_, 2, 3 },
15
16
77
    is_code_ref => sub { _::is_code_ref $_, 2, 3 },
16
16
61
    is_glob_ref => sub { _::is_glob_ref $_, 2, 3 },
17
16
58
    is_regex => sub { _::is_regex $_, 2, 3 },
18
16
65
    is_plain => sub { _::is_plain $_, 2, 3 },
19
16
25082
    is_int => sub { _::is_int $_, 2, 3 },
20
16
74
    is_uint => sub { _::is_uint $_, 2, 3 },
21
16
66
    is_identifier => sub { _::is_identifier $_, 2, 3 },
22
16
71
    is_package => sub { _::is_package $_, 2, 3 },
23
1
199535
);
24
25sub value_matrix_ok {
26
3
23
    my ($names, $values, %results) = @_;
27
3
12
    for my $i (0 .. $#$names) {
28        subtest $names->[$i] => sub {
29
16
14359
            plan tests => scalar keys %results;
30
16
5369
            while (my ($fn, $expected) = each %results) {
31
192
119749
                my $code = $functions{$fn} // die "Unknown function $fn";
32
192
358
                local $_ = $values->[$i];
33
192
563
                my ($result) = $code->();
34
192
412
                $result = $result ? 1 : 0;
35
192
571
                is $result, $expected->[$i], $fn;
36            }
37
16
24552
        };
38    }
39}
40
41
0
sub FOO { }; # for the glob
42
43value_matrix_ok [qw[ scalar_ref array_ref hash_ref code_ref ]],
44
1
0
20
0
    [ \1, [], {}, sub { } ],
45    is_ref => [ 1, 1, 1, 1 ],
46    is_scalar_ref => [ 1, 0, 0, 0 ],
47    is_array_ref => [ 0, 1, 0, 0 ],
48    is_hash_ref => [ 0, 0, 1, 0 ],
49    is_code_ref => [ 0, 0, 0, 1 ],
50    is_glob_ref => [ 0, 0, 0, 0 ],
51    is_regex => [ 0, 0, 0, 0 ],
52    is_plain => [ 0, 0, 0, 0 ],
53    is_int => [ 0, 0, 0, 0 ],
54    is_uint => [ 0, 0, 0, 0 ],
55    is_identifier => [ 0, 0, 0, 0 ],
56    is_package => [ 0, 0, 0, 0 ];
57
1
1722
value_matrix_ok [qw[ glob_ref regex string integer float undef]],
58    [ \*FOO, qr//, '', 42, 42.3, undef ],
59    is_ref => [ 1, 0, 0, 0, 0, 0 ],
60    is_scalar_ref => [ 0, 0, 0, 0, 0, 0 ],
61    is_array_ref => [ 0, 0, 0, 0, 0, 0 ],
62    is_hash_ref => [ 0, 0, 0, 0, 0, 0 ],
63    is_code_ref => [ 0, 0, 0, 0, 0, 0 ],
64    is_glob_ref => [ 1, 0, 0, 0, 0, 0 ],
65    is_regex => [ 0, 1, 0, 0, 0, 0 ],
66    is_plain => [ 0, 0, 1, 1, 1, 0 ],
67    is_int => [ 0, 0, 0, 1, 0, 0 ],
68    is_uint => [ 0, 0, 0, 1, 0, 0 ],
69    is_identifier => [ 0, 0, 0, 0, 0, 0 ],
70    is_package => [ 0, 0, 0, 0, 0, 0 ];
71
1
26619
value_matrix_ok [qw[ negint ident package bad_package _4 _5 ]],
72    [ -42, 'fo_3', "x::y", "x'y", undef, undef ],
73    is_ref => [ 0, 0, 0, 0, 0, 0 ],
74    is_scalar_ref => [ 0, 0, 0, 0, 0, 0 ],
75    is_array_ref => [ 0, 0, 0, 0, 0, 0 ],
76    is_hash_ref => [ 0, 0, 0, 0, 0, 0 ],
77    is_code_ref => [ 0, 0, 0, 0, 0, 0 ],
78    is_glob_ref => [ 0, 0, 0, 0, 0, 0 ],
79    is_regex => [ 0, 0, 0, 0, 0, 0 ],
80    is_plain => [ 1, 1, 1, 1, 0, 0 ],
81    is_int => [ 1, 0, 0, 0, 0, 0 ],
82    is_uint => [ 0, 0, 0, 0, 0, 0 ],
83    is_identifier => [ 0, 1, 0, 0, 0, 0 ],
84    is_package => [ 0, 1, 1, 0, 0, 0 ];