1 use Test::More tests => 12;
4 # TODO: this test should be renamed constructor.t, since all it tests is
5 # UT behaviour during construction.
12 traits => [ qw(MooseX::UndefTolerant::Attribute)],
15 predicate => 'has_attr1'
21 predicate => 'has_attr2'
28 use MooseX::UndefTolerant;
33 predicate => 'has_attr1'
38 predicate => 'has_attr2'
44 note 'Testing class with a single UndefTolerant attribute';
47 ok(!$obj->has_attr1, 'attr1 has no value before it is assigned');
48 ok(!$obj->has_attr2, 'attr2 has no value before it is assigned');
52 my $obj = Foo->new(attr1 => undef);
53 ok(!$obj->has_attr1, 'UT attr1 has no value when assigned undef in constructor');
54 ok (exception { $obj = Foo->new(attr2 => undef) },
55 'But assigning undef to attr2 generates a type constraint error');
59 my $obj = Foo->new(attr1 => 1234);
60 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
61 ok($obj->has_attr1, '...and the predicate returns true as normal');
66 note 'Testing class with the entire class being UndefTolerant';
69 ok(!$obj->has_attr1, 'attr1 has no value before it is assigned');
73 my $obj = Bar->new(attr1 => undef);
74 ok(!$obj->has_attr1, 'attr1 has no value when assigned undef in constructor');
75 ok (!exception { $obj = Bar->new(attr2 => undef) },
76 'assigning undef to attr2 does not produce an error');
77 ok(!$obj->has_attr2, 'attr2 has no value when assigned undef in constructor');
81 my $obj = Bar->new(attr1 => 1234);
82 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
83 ok($obj->has_attr1, '...and the predicate returns true as normal');