File: 30_builtins.t

package info (click to toggle)
libperlude-perl 0.61-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 360 kB
  • sloc: perl: 903; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download
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
use strict;
use warnings;
use Test::More
    skip_all  => 'should this module be deprecated?';
use Perlude::Lazy;
use Perlude::builtins;

# first get the list of all builtins
my %builtins = map { $_ => $_ } grep { defined \&{"f::$_"} } keys %f::;

# these builtins are easy to test: it's basically a map
my %simple = (
    abs       => 'num',
    chr       => 'num',
    cos       => 'num',
    defined   => 'str',
    exp       => 'num',
    glob      => 'file',
    hex       => 'hex',
    int       => 'num',
    lcfirst   => 'str',
    lc        => 'str',
    length    => 'str',
    log       => 'pos',
    oct       => 'oct',
    ord       => 'chr',
    quotemeta => 'str',
    ref       => 'ref',
    sin       => 'num',
    sqrt      => 'pos',
    ucfirst   => 'str',
    uc        => 'str',
);

# some values used for testing
my %values = (
    num => [ 0, 1,   -1,   0.5, -1.48, 37.999 ],
    pos => [ 1, 0.5, 1.48, 37.999 ],
    str => [ '', $/, "$/$/", qw( MUON eTa_Prime GRaviTiNo xi &kj@!$jh ) ],
    hex => [ 0, 35, 173, 1415, 18499, 'a', 'ff', 'dead', 'beef' ],
    oct => [ 0, 1,  7,   5647251 ],
    chr => [qw( a b c é か )],
    ref => [ [], {}, sub { }, \'a', \1, bless( {}, 'zlonk' ) ],
    file => [ 'zlonk', '*', 'lib/*' ],
);

# skip this
delete $builtins{$_} for qw(
    sub
);

my @tests;

plan tests => 1 + @tests + keys %simple;

# test the simple builtins
for my $builtin ( sort keys %simple ) {
    my $f = \&{"f::$builtin"};
    my @v = @{ $values{ $simple{$builtin} } };
    is_deeply( [ fold $f->( unfold @v ) ],
        [ map { eval "$builtin( \$_ )" } @v ], $builtin );
    delete $builtins{$builtin};
}

TODO: {
    local $TODO = sprintf 'The tests are not yet implemented for %s',
                            join q{, }, sort keys %builtins;
    # did we test everything?
    is_deeply( [ sort keys %builtins ], [], "Tested all builtins" );
}