Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 900_mouse_bugs / 005_large_int.t
1 # See also http://rt.cpan.org/Public/Bug/Display.html?id=55048
2 use strict;
3 use Test::More tests => 24;
4
5 {
6     package MyInteger;
7     use Mouse;
8
9     has a_int => (
10         is => 'rw',
11         isa => 'Int',
12     );
13
14     has a_num => (
15         is => 'rw',
16         isa => 'Num',
17     );
18 }
19
20 foreach my $i(2**32, 2**40, 2**46) {
21     for my $sig(1, -1) {
22         my $value = $i * $sig;
23
24         my $int = MyInteger->new( a_int => $value )->a_int;
25         cmp_ok($int, '==', $value, "Mouse groked the Int $i");
26
27
28         my $num = MyInteger->new( a_num => $value )->a_num;
29         cmp_ok($num, '==', $value, "Mouse groked the Num $i");
30
31         $value += 0.5;
32
33         eval { MyInteger->new( a_int => $value ) };
34         like $@, qr/does not pass the type constraint/, "Mouse does not regard $value as Int";
35         eval { MyInteger->new( a_num => $value ) };
36         is $@, '', "Mouse regards $value as Num";
37     }
38 }
39