fixing required
[gitmo/Moose.git] / t / 071_misc_attribute_tests.t
CommitLineData
94b8bbb8 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
f6e5456f 6use Test::More tests => 8;
94b8bbb8 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose');
11}
12
94b8bbb8 13{
4fd69d6c 14 {
ddbdc0cb 15 package Test::Attribute::Inline::Documentation;
16 use Moose;
17
18 has 'foo' => (
19 documentation => q{
20 The 'foo' attribute is my favorite
21 attribute in the whole wide world.
22 }
23 );
24 }
25
26 my $foo_attr = Test::Attribute::Inline::Documentation->meta->get_attribute('foo');
27
28 ok($foo_attr->has_documentation, '... the foo has docs');
29 is($foo_attr->documentation,
30 q{
31 The 'foo' attribute is my favorite
32 attribute in the whole wide world.
33 },
34 '... got the foo docs');
35}
36
37{
38 {
4fd69d6c 39 package Test::For::Lazy::TypeConstraint;
40 use Moose;
41 use Moose::Util::TypeConstraints;
94b8bbb8 42
4fd69d6c 43 has 'bad_lazy_attr' => (
44 is => 'rw',
45 isa => 'ArrayRef',
46 lazy => 1,
47 default => sub { "test" },
48 );
49
50 has 'good_lazy_attr' => (
51 is => 'rw',
52 isa => 'ArrayRef',
53 lazy => 1,
54 default => sub { [] },
55 );
94b8bbb8 56
4fd69d6c 57 }
94b8bbb8 58
4fd69d6c 59 my $test = Test::For::Lazy::TypeConstraint->new;
60 isa_ok($test, 'Test::For::Lazy::TypeConstraint');
61
62 dies_ok {
63 $test->bad_lazy_attr;
64 } '... this does not work';
65
66 lives_ok {
67 $test->good_lazy_attr;
68 } '... this does not work';
69}
f6e5456f 70
71{
72 {
73 package Test::Arrayref::Attributes;
74 use Moose;
75
76 has [qw(foo bar baz)] => (
77 is => 'rw',
78 );
79
80 }
81
82 my $test = Test::Arrayref::Attributes->new;
83 isa_ok($test, 'Test::Arrayref::Attributes');
84 can_ok($test, qw(foo bar baz));
85
86}