File: 01-compile.t

package info (click to toggle)
libdata-munge-perl 0.08-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 108 kB
  • ctags: 11
  • sloc: perl: 206; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,715 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
#!perl

use Test::More tests => 55;
use Test::Warnings;

use warnings FATAL => 'all';
use strict;
use Data::Munge;

{
    my $str = "abc|bar|baz|foo|\\*\\*|ab|\\!|\\*|a";
    is list2re(qw[! a abc ab foo bar baz ** *]), qr/$str/, 'list2re';
}

is +(byval { s/foo/bar/ } 'foo-foo'), 'bar-foo', 'byval';
is_deeply [mapval { tr[a-d][1-4] } qw[foo bar baz]], [qw[foo 21r 21z]], 'mapval';

is replace('Apples are round, and apples are juicy.', qr/apples/i, 'oranges', 'g'), 'oranges are round, and oranges are juicy.', 'replace g';
is replace('John Smith', qr/(\w+)\s+(\w+)/, '$2, $1'), 'Smith, John', 'replace';
is replace('97653 foo bar 42', qr/(\d)(\d)/, sub { $_[1] + $_[2] }, 'g'), '16113 foo bar 6', 'replace fun g';

is trim("  a  b  "), "a  b";
is trim(""), "";
is trim(","), ",";
is trim(" "), "";
is trim("  "), "";
is trim("\na"), "a";
is trim("b\t"), "b";
is trim("X\nY \n "), "X\nY";
is trim(undef), undef;

{
    my $fac = rec {
        my ($rec, $n) = @_;
        $n < 2 ? 1 : $n * $rec->($n - 1)
    };
    is $fac->(5), 120;
    is $fac->(6), 720;
}

is eval_string('"ab" . "cd"'), 'abcd';
is eval { eval_string('{') }, undef;
like $@, qr/Missing right curly/;

ok !elem 42, [];
ok elem 42, [42];
ok elem "A",   [undef, [], "A", "B"];
ok elem "B",   [undef, [], "A", "B"];
ok elem undef, [undef, [], "A", "B"];
ok !elem [],   [undef, [], "A", "B"];
ok !elem "C",  [undef, [], "A", "B"];
for my $ref ([], {}, sub {}) {
    ok !elem $ref, [];
    ok !elem $ref, [undef];
    ok !elem $ref, ["$ref"];
    ok !elem $ref, [[], {}];
    ok elem $ref, [$ref];
    ok elem $ref, ["A", "B", $ref];
    ok elem $ref, ["A", $ref, "B"];
    ok elem $ref, [$ref, "A", $ref, $ref];
    ok elem $ref, [undef, $ref];
}