Regenerate test files
[gitmo/Mouse.git] / t / 020_attributes / 001_attribute_reader_generation.t
CommitLineData
4060c871 1#!/usr/bin/perl
fde8e43f 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4060c871 5
6use strict;
7use warnings;
8
0dc63056 9use Test::More;
fde8e43f 10$TODO = q{Mouse is not yet completed};
4060c871 11use Test::Exception;
12
13
4060c871 14{
15 package Foo;
16 use Mouse;
17
18 eval {
19 has 'foo' => (
20 reader => 'get_foo'
21 );
22 };
23 ::ok(!$@, '... created the reader method okay');
24
25 eval {
26 has 'lazy_foo' => (
27 reader => 'get_lazy_foo',
28 lazy => 1,
29 default => sub { 10 }
30 );
31 };
32 ::ok(!$@, '... created the lazy reader method okay') or warn $@;
33
34 my $warn;
35
36 eval {
37 local $SIG{__WARN__} = sub { $warn = $_[0] };
38 has 'mtfnpy' => (
39 reder => 'get_mftnpy'
40 );
41 };
42 ::ok($warn, '... got a warning for mispelled attribute argument');
43}
44
45{
46 my $foo = Foo->new;
47 isa_ok($foo, 'Foo');
48
49 can_ok($foo, 'get_foo');
50 is($foo->get_foo(), undef, '... got an undefined value');
51 dies_ok {
52 $foo->get_foo(100);
53 } '... get_foo is a read-only';
54
55 ok(!exists($foo->{lazy_foo}), '... no value in get_lazy_foo slot');
56
57 can_ok($foo, 'get_lazy_foo');
58 is($foo->get_lazy_foo(), 10, '... got an deferred value');
59 dies_ok {
60 $foo->get_lazy_foo(100);
61 } '... get_lazy_foo is a read-only';
62}
63
64{
65 my $foo = Foo->new;
66 isa_ok($foo, 'Foo');
67
68 my $attr = $foo->meta->find_attribute_by_name("lazy_foo");
69
70 isa_ok( $attr, "Mouse::Meta::Attribute" );
71
72 ok( $attr->is_lazy, "it's lazy" );
73
74 is( $attr->get_raw_value($foo), undef, "raw value" );
75
76 is( $attr->get_value($foo), 10, "lazy value" );
77
78 is( $attr->get_raw_value($foo), 10, "raw value" );
79}
80
81{
82 my $foo = Foo->new(foo => 10, lazy_foo => 100);
83 isa_ok($foo, 'Foo');
84
85 is($foo->get_foo(), 10, '... got the correct value');
86 is($foo->get_lazy_foo(), 100, '... got the correct value');
87}
88
0dc63056 89done_testing;