use Test::Fatal instead of Test::Exception
[gitmo/MooseX-Types-Common.git] / t / 02-numeric.t
1 #! /usr/bin/perl -w
2
3 use strict;
4 use warnings;
5 use Test::More tests => 34;
6 use Test::Fatal;
7
8 {
9   package FooTest;
10   use Moose;
11   use MooseX::Types::Common::Numeric (
12     qw(PositiveNum PositiveOrZeroNum
13        PositiveInt PositiveOrZeroInt
14        NegativeNum NegativeOrZeroNum
15        NegativeInt NegativeOrZeroInt
16        SingleDigit)
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);
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);
28 }
29
30 my $ins = FooTest->new;
31
32 isnt(exception { $ins->digit(100); }, undef, 'SingleDigit');
33 is(exception { $ins->digit(1); }, undef, 'SingleDigit 2');
34
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)');
43
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)');
52
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)');
61
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)');