stop using excludes within moose, since it's no longer necessary
[gitmo/Moose.git] / t / cmop / AttributesWithHistory_test.t
CommitLineData
38bf2a25 1use strict;
2use warnings;
3
4use Test::More;
5use File::Spec;
6
7use Class::MOP;
8
9BEGIN {
10 require_ok(File::Spec->catfile('examples', 'AttributesWithHistory.pod'));
11}
12
13{
14 package Foo;
15 use metaclass;
16
17 Foo->meta->add_attribute(AttributesWithHistory->new('foo' => (
18 accessor => 'foo',
19 history_accessor => 'get_foo_history',
20 )));
21
22 Foo->meta->add_attribute(AttributesWithHistory->new('bar' => (
23 reader => 'get_bar',
24 writer => 'set_bar',
25 history_accessor => 'get_bar_history',
26 )));
27
28 sub new {
29 my $class = shift;
30 $class->meta->new_object(@_);
31 }
32}
33
34my $foo = Foo->new();
35isa_ok($foo, 'Foo');
36
37can_ok($foo, 'foo');
38can_ok($foo, 'get_foo_history');
39can_ok($foo, 'set_bar');
40can_ok($foo, 'get_bar');
41can_ok($foo, 'get_bar_history');
42
43my $foo2 = Foo->new();
44isa_ok($foo2, 'Foo');
45
46is($foo->foo, undef, '... foo is not yet defined');
47is_deeply(
48 [ $foo->get_foo_history() ],
49 [ ],
50 '... got correct empty history for foo');
51
52is($foo2->foo, undef, '... foo2 is not yet defined');
53is_deeply(
54 [ $foo2->get_foo_history() ],
55 [ ],
56 '... got correct empty history for foo2');
57
58$foo->foo(42);
59is($foo->foo, 42, '... foo == 42');
60is_deeply(
61 [ $foo->get_foo_history() ],
62 [ 42 ],
63 '... got correct history for foo');
64
65is($foo2->foo, undef, '... foo2 is still not yet defined');
66is_deeply(
67 [ $foo2->get_foo_history() ],
68 [ ],
69 '... still got correct empty history for foo2');
70
71$foo2->foo(100);
72is($foo->foo, 42, '... foo is still == 42');
73is_deeply(
74 [ $foo->get_foo_history() ],
75 [ 42 ],
76 '... still got correct history for foo');
77
78is($foo2->foo, 100, '... foo2 == 100');
79is_deeply(
80 [ $foo2->get_foo_history() ],
81 [ 100 ],
82 '... got correct empty history for foo2');
83
84$foo->foo(43);
85$foo->foo(44);
86$foo->foo(45);
87$foo->foo(46);
88
89is_deeply(
90 [ $foo->get_foo_history() ],
91 [ 42, 43, 44, 45, 46 ],
92 '... got correct history for foo');
93
94is($foo->get_bar, undef, '... bar is not yet defined');
95is_deeply(
96 [ $foo->get_bar_history() ],
97 [ ],
98 '... got correct empty history for foo');
99
100
101$foo->set_bar("FOO");
102is($foo->get_bar, "FOO", '... bar == "FOO"');
103is_deeply(
104 [ $foo->get_bar_history() ],
105 [ "FOO" ],
106 '... got correct history for foo');
107
108$foo->set_bar("BAR");
109$foo->set_bar("BAZ");
110
111is_deeply(
112 [ $foo->get_bar_history() ],
113 [ qw/FOO BAR BAZ/ ],
114 '... got correct history for bar');
115
116is_deeply(
117 [ $foo->get_foo_history() ],
118 [ 42, 43, 44, 45, 46 ],
119 '... still have the correct history for foo');
120
121done_testing;