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