remove useless shebangs in tests
[gitmo/MooseX-Getopt.git] / t / 107_union_bug.t
CommitLineData
416dcb2e 1use strict;
2use warnings;
3
8fb3af53 4use Test::More;
416dcb2e 5
6{
7 package example;
86fa042d 8
416dcb2e 9 use Moose;
10 use Moose::Util::TypeConstraints;
11 with qw(
12 MooseX::Getopt
13 );
86fa042d 14
15 subtype 'ResultSet'
416dcb2e 16 => as 'DBIx::Class::ResultSet';
86fa042d 17
18 subtype 'ResultList'
416dcb2e 19 => as 'ArrayRef[Int]';
20
21 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
22 'ResultList' => '=s',
23 );
86fa042d 24
25 coerce 'ResultList'
26 => from 'Str'
416dcb2e 27 => via {
28 return [ grep { m/^\d+$/ } split /\D/,$_ ]; # <- split string into arrayref
29 };
86fa042d 30
416dcb2e 31 has 'results' => (
32 is => 'rw',
33 isa => 'ResultList | ResultSet', # <- union constraint
34 coerce => 1,
35 );
86fa042d 36
416dcb2e 37 has 'other' => (
38 is => 'rw',
39 isa => 'Str',
40 );
41}
42
43# Without MooseX::Getopt
44{
45 my $example = example->new({
46 results => '1234,5678,9012',
47 other => 'test',
48 });
49 isa_ok($example, 'example');
8fb3af53 50 is_deeply($example->results, [qw(1234 5678 9012)], 'result as expected');
416dcb2e 51}
52
53# With MooseX::Getopt
54{
55 local @ARGV = ('--results','1234,5678,9012','--other','test');
56 my $example = example->new_with_options;
57 isa_ok($example, 'example');
86fa042d 58
416dcb2e 59 is($example->other,'test');
8fb3af53 60 is_deeply($example->results, [qw(1234 5678 9012)], 'result as expected');
86fa042d 61}
8fb3af53 62
63done_testing;
64