Commit | Line | Data |
f63e6310 |
1 | use strict; |
2 | use warnings; |
3 | |
9fbb5be9 |
4 | use Test::More tests => 6; |
5 | use Test::NoWarnings 1.04 ':early'; |
f63e6310 |
6 | |
7 | BEGIN { |
8 | use_ok('MooseX::Getopt'); |
9 | } |
10 | |
11 | { |
12 | package App; |
13 | use Moose; |
14 | use Moose::Util::TypeConstraints; |
2557b526 |
15 | |
f63e6310 |
16 | use Scalar::Util 'looks_like_number'; |
2557b526 |
17 | |
f63e6310 |
18 | with 'MooseX::Getopt'; |
19 | |
20 | subtype 'ArrayOfInts' |
21 | => as 'ArrayRef' |
22 | => where { scalar (grep { looks_like_number($_) } @$_) }; |
2557b526 |
23 | |
f63e6310 |
24 | has 'nums' => ( |
25 | is => 'ro', |
26 | isa => 'ArrayOfInts', |
27 | default => sub { [0] } |
2557b526 |
28 | ); |
f63e6310 |
29 | } |
30 | |
31 | { |
32 | local @ARGV = (); |
33 | |
34 | my $app = App->new_with_options; |
35 | isa_ok($app, 'App'); |
2557b526 |
36 | |
37 | is_deeply($app->nums, [0], '... nums is [0] as expected'); |
f63e6310 |
38 | } |
39 | |
40 | { |
41 | local @ARGV = ('--nums', 3, '--nums', 5); |
42 | |
43 | my $app = App->new_with_options; |
44 | isa_ok($app, 'App'); |
2557b526 |
45 | |
46 | is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); |
f63e6310 |
47 | } |
48 | |