Commit | Line | Data |
b2b106d7 |
1 | #!/usr/bin/perl |
5a592ad7 |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
b2b106d7 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
5a592ad7 |
9 | use Test::More; |
b2b106d7 |
10 | use Test::Exception; |
11 | |
b2b106d7 |
12 | |
13 | { |
14 | package Foo; |
15 | use Mouse; |
16 | use Mouse::Util::TypeConstraints; |
17 | |
18 | use Scalar::Util (); |
19 | |
20 | type Number |
21 | => where { defined($_) && !ref($_) && Scalar::Util::looks_like_number($_) }; |
22 | |
23 | type String |
24 | => where { defined($_) && !ref($_) && !Scalar::Util::looks_like_number($_) }; |
25 | |
26 | has vUndef => ( is => 'rw', isa => 'Undef' ); |
27 | has vDefined => ( is => 'rw', isa => 'Defined' ); |
28 | has vInt => ( is => 'rw', isa => 'Int' ); |
29 | has vNumber => ( is => 'rw', isa => 'Number' ); |
30 | has vStr => ( is => 'rw', isa => 'Str' ); |
31 | has vString => ( is => 'rw', isa => 'String' ); |
32 | |
33 | has v_lazy_Undef => ( is => 'rw', lazy => 1, default => sub { undef }, isa => 'Undef' ); |
34 | has v_lazy_Defined => ( is => 'rw', lazy => 1, default => sub { undef }, isa => 'Defined' ); |
35 | has v_lazy_Int => ( is => 'rw', lazy => 1, default => sub { undef }, isa => 'Int' ); |
36 | has v_lazy_Number => ( is => 'rw', lazy => 1, default => sub { undef }, isa => 'Number' ); |
37 | has v_lazy_Str => ( is => 'rw', lazy => 1, default => sub { undef }, isa => 'Str' ); |
38 | has v_lazy_String => ( is => 'rw', lazy => 1, default => sub { undef }, isa => 'String' ); |
39 | } |
40 | |
41 | # EXPORT TYPE CONSTRAINTS |
42 | # |
43 | Mouse::Util::TypeConstraints->export_type_constraints_as_functions; |
44 | |
45 | ok( Undef(undef), '... undef is a Undef'); |
46 | ok(!Defined(undef), '... undef is NOT a Defined'); |
5a592ad7 |
47 | ok(!Int(undef), '... undef is NOT an Int'); |
b2b106d7 |
48 | ok(!Number(undef), '... undef is NOT a Number'); |
49 | ok(!Str(undef), '... undef is NOT a Str'); |
50 | ok(!String(undef), '... undef is NOT a String'); |
51 | |
52 | ok(!Undef(5), '... 5 is a NOT a Undef'); |
53 | ok(Defined(5), '... 5 is a Defined'); |
5a592ad7 |
54 | ok(Int(5), '... 5 is an Int'); |
b2b106d7 |
55 | ok(Number(5), '... 5 is a Number'); |
56 | ok(Str(5), '... 5 is a Str'); |
57 | ok(!String(5), '... 5 is NOT a String'); |
58 | |
59 | ok(!Undef(0.5), '... 0.5 is a NOT a Undef'); |
60 | ok(Defined(0.5), '... 0.5 is a Defined'); |
5a592ad7 |
61 | ok(!Int(0.5), '... 0.5 is NOT an Int'); |
b2b106d7 |
62 | ok(Number(0.5), '... 0.5 is a Number'); |
63 | ok(Str(0.5), '... 0.5 is a Str'); |
64 | ok(!String(0.5), '... 0.5 is NOT a String'); |
65 | |
66 | ok(!Undef('Foo'), '... "Foo" is NOT a Undef'); |
67 | ok(Defined('Foo'), '... "Foo" is a Defined'); |
5a592ad7 |
68 | ok(!Int('Foo'), '... "Foo" is NOT an Int'); |
b2b106d7 |
69 | ok(!Number('Foo'), '... "Foo" is NOT a Number'); |
70 | ok(Str('Foo'), '... "Foo" is a Str'); |
71 | ok(String('Foo'), '... "Foo" is a String'); |
72 | |
73 | |
74 | my $foo = Foo->new; |
75 | |
76 | lives_ok { $foo->vUndef(undef) } '... undef is a Foo->Undef'; |
77 | dies_ok { $foo->vDefined(undef) } '... undef is NOT a Foo->Defined'; |
78 | dies_ok { $foo->vInt(undef) } '... undef is NOT a Foo->Int'; |
79 | dies_ok { $foo->vNumber(undef) } '... undef is NOT a Foo->Number'; |
80 | dies_ok { $foo->vStr(undef) } '... undef is NOT a Foo->Str'; |
81 | dies_ok { $foo->vString(undef) } '... undef is NOT a Foo->String'; |
82 | |
83 | dies_ok { $foo->vUndef(5) } '... 5 is NOT a Foo->Undef'; |
84 | lives_ok { $foo->vDefined(5) } '... 5 is a Foo->Defined'; |
85 | lives_ok { $foo->vInt(5) } '... 5 is a Foo->Int'; |
86 | lives_ok { $foo->vNumber(5) } '... 5 is a Foo->Number'; |
87 | lives_ok { $foo->vStr(5) } '... 5 is a Foo->Str'; |
88 | dies_ok { $foo->vString(5) } '... 5 is NOT a Foo->String'; |
89 | |
90 | dies_ok { $foo->vUndef(0.5) } '... 0.5 is NOT a Foo->Undef'; |
91 | lives_ok { $foo->vDefined(0.5) } '... 0.5 is a Foo->Defined'; |
92 | dies_ok { $foo->vInt(0.5) } '... 0.5 is NOT a Foo->Int'; |
93 | lives_ok { $foo->vNumber(0.5) } '... 0.5 is a Foo->Number'; |
94 | lives_ok { $foo->vStr(0.5) } '... 0.5 is a Foo->Str'; |
95 | dies_ok { $foo->vString(0.5) } '... 0.5 is NOT a Foo->String'; |
96 | |
97 | dies_ok { $foo->vUndef('Foo') } '... "Foo" is NOT a Foo->Undef'; |
98 | lives_ok { $foo->vDefined('Foo') } '... "Foo" is a Foo->Defined'; |
99 | dies_ok { $foo->vInt('Foo') } '... "Foo" is NOT a Foo->Int'; |
100 | dies_ok { $foo->vNumber('Foo') } '... "Foo" is NOT a Foo->Number'; |
101 | lives_ok { $foo->vStr('Foo') } '... "Foo" is a Foo->Str'; |
102 | lives_ok { $foo->vString('Foo') } '... "Foo" is a Foo->String'; |
103 | |
104 | # the lazy tests |
105 | |
106 | lives_ok { $foo->v_lazy_Undef() } '... undef is a Foo->Undef'; |
107 | dies_ok { $foo->v_lazy_Defined() } '... undef is NOT a Foo->Defined'; |
108 | dies_ok { $foo->v_lazy_Int() } '... undef is NOT a Foo->Int'; |
109 | dies_ok { $foo->v_lazy_Number() } '... undef is NOT a Foo->Number'; |
110 | dies_ok { $foo->v_lazy_Str() } '... undef is NOT a Foo->Str'; |
111 | dies_ok { $foo->v_lazy_String() } '... undef is NOT a Foo->String'; |
112 | |
5a592ad7 |
113 | done_testing; |