File: 01_hashed.t

package info (click to toggle)
libgetopt-ex-hashed-perl 1.0602-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 312 kB
  • sloc: perl: 409; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,690 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;
use Test::More;
use lib './t';
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;

my @argv = qw(
    --string Alice
    Life
    --number 42
    --list mostly --list harmless
    Universe and
    --hash animal=dolphin --hash fish=babel
    --implicit
    -s -42
    --end 999
    --trillian=mcmillan
    --beeblebrox
    --so-long
    --both 99
    Everything
    --paranoid Marvin
    --ind-1 42
    );

BEGIN {
    $App::Foo::TAKE_IT_ALL = 1;
}

use App::Foo;
$App::Foo::DEFAULT = 42;
$App::Foo::ind_1 = 101;
$App::Foo::ind_2 = 102;
@argv = (my $app = App::Foo->new)->run(@argv);

is_deeply($app->{string}, "Alice", "String");
is_deeply($app->{say}, "Hello", "String (default)");
is_deeply($app->{number}, 42, "Number");
is_deeply($app->{implicit}, 42, "Default parameter");
is_deeply($app->{start}, -42, "alias (short)");
is_deeply($app->{finish}, 999, "alias (long)");
is_deeply($app->{tricia}, "mcmillan", "alias (mixed with spec)");
is_deeply($app->{zaphord}, 1, "alias (separate)");
is_deeply($app->{so_long}, 1, "convert underscore");
is_deeply($app->{list}, [ qw(mostly harmless) ], "List");
is_deeply($app->{hash}, { animal => 'dolphin', fish => 'babel' }, "Hash");
is_deeply($app->{left}, 99, "coderef");
is_deeply($app->{android}, "Marvin", "action");
if ($App::Foo::TAKE_IT_ALL) {
    is_deeply($app->{ARGV}, [ qw(Life Universe and Everything) ], '<>');
} else {
    is_deeply(\@argv, [ qw(Life Universe and Everything) ], '@argv');
}
is_deeply($app->{default}, 99, "normal default");
is_deeply($app->{lazy}, 42, "lazy default");
is_deeply($App::Foo::ind_1, 42, "indirect variable");
is_deeply($App::Foo::ind_2, 102, "indirect variable");

done_testing;