Commit | Line | Data |
f63e6310 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More tests => 5; |
5 | |
6 | BEGIN { |
7 | use_ok('MooseX::Getopt'); |
8 | } |
9 | |
10 | { |
11 | package App; |
12 | use Moose; |
13 | use Moose::Util::TypeConstraints; |
2557b526 |
14 | |
f63e6310 |
15 | use Scalar::Util 'looks_like_number'; |
2557b526 |
16 | |
f63e6310 |
17 | with 'MooseX::Getopt'; |
18 | |
19 | subtype 'ArrayOfInts' |
20 | => as 'ArrayRef' |
21 | => where { scalar (grep { looks_like_number($_) } @$_) }; |
2557b526 |
22 | |
f63e6310 |
23 | has 'nums' => ( |
24 | is => 'ro', |
25 | isa => 'ArrayOfInts', |
26 | default => sub { [0] } |
2557b526 |
27 | ); |
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 | |