Commit | Line | Data |
ac73ab52 |
1 | use strict; |
eae6c2c4 |
2 | use warnings FATAL => 'all'; |
d52d9696 |
3 | use Test::More tests => 34; |
3d272255 |
4 | use Test::Fatal; |
ac73ab52 |
5 | |
6 | { |
7 | package FooTest; |
8 | use Moose; |
5b561c82 |
9 | use MooseX::Types::Common::Numeric ( |
d52d9696 |
10 | qw(PositiveNum PositiveOrZeroNum |
11 | PositiveInt PositiveOrZeroInt |
12 | NegativeNum NegativeOrZeroNum |
13 | NegativeInt NegativeOrZeroInt |
14 | SingleDigit) |
ac73ab52 |
15 | ); |
16 | |
17 | has digit => ( is => 'rw', isa => SingleDigit); |
18 | has posnum => ( is => 'rw', isa => PositiveNum); |
19 | has posint => ( is => 'rw', isa => PositiveInt); |
20 | has negnum => ( is => 'rw', isa => NegativeNum); |
21 | has negint => ( is => 'rw', isa => NegativeInt); |
d52d9696 |
22 | has posorzeronum => ( is => 'rw', isa => PositiveOrZeroNum); |
23 | has posorzeroint => ( is => 'rw', isa => PositiveOrZeroInt); |
24 | has negorzeronum => ( is => 'rw', isa => NegativeOrZeroNum); |
25 | has negorzeroint => ( is => 'rw', isa => NegativeOrZeroInt); |
ac73ab52 |
26 | } |
27 | |
28 | my $ins = FooTest->new; |
29 | |
3d272255 |
30 | isnt(exception { $ins->digit(100); }, undef, 'SingleDigit'); |
31 | is(exception { $ins->digit(1); }, undef, 'SingleDigit 2'); |
ac73ab52 |
32 | |
3d272255 |
33 | isnt(exception { $ins->posint(-100); }, undef, 'PositiveInt (-100)'); |
34 | isnt(exception { $ins->posint(0); }, undef, 'PositiveInt (0)'); |
35 | isnt(exception { $ins->posint(100.885); }, undef, 'PositiveInt (100.885)'); |
36 | is(exception { $ins->posint(100); }, undef, 'PositiveInt (100)'); |
37 | isnt(exception { $ins->posnum(0); }, undef, 'PositiveNum (0)'); |
38 | is(exception { $ins->posnum(100.885); }, undef, 'PositiveNum (100.885)'); |
39 | isnt(exception { $ins->posnum(-100.885); }, undef, 'PositiveNum (-100.885)'); |
40 | is(exception { $ins->posnum(0.0000000001); }, undef, 'PositiveNum (0.0000000001)'); |
ac73ab52 |
41 | |
3d272255 |
42 | isnt(exception { $ins->posorzeroint(-100); }, undef, 'PositiveOrZeroInt (-100)'); |
43 | is(exception { $ins->posorzeroint(0); }, undef, 'PositiveOrZeroInt (0)'); |
44 | isnt(exception { $ins->posorzeroint(100.885); }, undef, 'PositiveOrZeroInt (100.885)'); |
45 | is(exception { $ins->posorzeroint(100); }, undef, 'PositiveOrZeroInt (100)'); |
46 | is(exception { $ins->posorzeronum(0); }, undef, 'PositiveOrZeroNum (0)'); |
47 | is(exception { $ins->posorzeronum(100.885); }, undef, 'PositiveOrZeroNum (100.885)'); |
48 | isnt(exception { $ins->posorzeronum(-100.885); }, undef, 'PositiveOrZeroNum (-100.885)'); |
49 | is(exception { $ins->posorzeronum(0.0000000001); }, undef, 'PositiveOrZeroNum (0.0000000001)'); |
d52d9696 |
50 | |
3d272255 |
51 | isnt(exception { $ins->negint(100); }, undef, 'NegativeInt (100)'); |
52 | isnt(exception { $ins->negint(-100.885); }, undef, 'NegativeInt (-100.885)'); |
53 | is(exception { $ins->negint(-100); }, undef, 'NegativeInt (-100)'); |
54 | isnt(exception { $ins->negint(0); }, undef, 'NegativeInt (0)'); |
55 | is(exception { $ins->negnum(-100.885); }, undef, 'NegativeNum (-100.885)'); |
56 | isnt(exception { $ins->negnum(100.885); }, undef, 'NegativeNum (100.885)'); |
57 | isnt(exception { $ins->negnum(0); }, undef, 'NegativeNum (0)'); |
58 | is(exception { $ins->negnum(-0.0000000001); }, undef, 'NegativeNum (-0.0000000001)'); |
d52d9696 |
59 | |
3d272255 |
60 | isnt(exception { $ins->negorzeroint(100); }, undef, 'NegativeOrZeroInt (100)'); |
61 | isnt(exception { $ins->negorzeroint(-100.885); }, undef, 'NegativeOrZeroInt (-100.885)'); |
62 | is(exception { $ins->negorzeroint(-100); }, undef, 'NegativeOrZeroInt (-100)'); |
63 | is(exception { $ins->negorzeroint(0); }, undef, 'NegativeOrZeroInt (0)'); |
64 | is(exception { $ins->negorzeronum(-100.885); }, undef, 'NegativeOrZeroNum (-100.885)'); |
65 | isnt(exception { $ins->negorzeronum(100.885); }, undef, 'NegativeOrZeroNum (100.885)'); |
66 | is(exception { $ins->negorzeronum(0); }, undef, 'NegativeOrZeroNum (0)'); |
67 | is(exception { $ins->negorzeronum(-0.0000000001); }, undef, 'NegativeOrZeroNum (-0.0000000001)'); |