1
exercism fetch perl5 pig-latin

piglatin.t

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
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env perl
use strict;
use warnings;

use Test::More;
use FindBin;
my $dir;
BEGIN { $dir = $FindBin::Bin . '/' };
use lib $dir;

my @cases = (
    {
        input    => "apple",
        expected => "appleay"
    },
    {
        input    => "pig",
        expected => "igpay"
    },
    {
        input    => "koala",
        expected => "oalakay"
    },
    {
        input    => "chair",
        expected => "airchay"
    },
    {
        input    => "queen",
        expected => "eenquay"
    },
    {
        input    => "square",
        expected => "aresquay"
    },
    {
        input    => "therapy",
        expected => "erapythay"
    },
    {
        input    => "thrush",
        expected => "ushthray"
    },
    {
        input    => "school",
        expected => "oolschay"
    },
    {
        input    => "quick fast run",
        expected => "ickquay astfay unray"
    },
    {
        input    => "yellow",
        expected => "ellowyay"
    },
    {
        input    => "yttria",
        expected => "yttriaay"
    },
    {
        input    => "xenon",
        expected => "enonxay"
    },
    {
        input    => "xray",
        expected => "xrayay"
    }
);

my $module = $ENV{EXERCISM} ? 'Example' : 'PigLatin';

plan tests => 3 + @cases;

ok -e "${dir}${module}.pm", "Missing file $module.pm",
        or BAIL_OUT "You need to create file: $module.pm";

eval "use $module";

ok !$@, "Cannot load $module.pm",
        or BAIL_OUT "Does $module.pm compile? Does it end with 1;?"; 

can_ok $module, "translate" or BAIL_OUT "Missing packge $module; or missing sub translate()";

foreach my $c ( @cases ) {
    no strict 'refs';
    my $sub = "${module}::translate";
    is $sub->($c->{input}), $c->{expected}, "translate " . $c->{input} . " to " . $c->{expected};
}