Revert autogenerated tests. Tests should not changed radically.
[gitmo/Mouse.git] / t / 020_attributes / failing / 021_method_generation_rules.t
CommitLineData
4060c871 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
9864f0e4 6use Test::More tests => 17;
4060c871 7use Test::Exception;
8
9
9864f0e4 10
4060c871 11=pod
12
13 is => rw, writer => _foo # turns into (reader => foo, writer => _foo)
14 is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before
15 is => rw, accessor => _foo # turns into (accessor => _foo)
16 is => ro, accessor => _foo # error, accesor is rw
17
18=cut
19
20sub make_class {
21 my ($is, $attr, $class) = @_;
22
23 eval "package $class; use Mouse; has 'foo' => ( is => '$is', $attr => '_foo' );";
24
25 return $@ ? die $@ : $class;
26}
27
28my $obj;
29my $class;
30
31$class = make_class('rw', 'writer', 'Test::Class::WriterRW');
32ok($class, "Can define attr with rw + writer");
33
34$obj = $class->new();
35
36can_ok($obj, qw/foo _foo/);
37lives_ok {$obj->_foo(1)} "$class->_foo is writer";
38is($obj->foo(), 1, "$class->foo is reader");
39dies_ok {$obj->foo(2)} "$class->foo is not writer"; # this should fail
40ok(!defined $obj->_foo(), "$class->_foo is not reader");
41
42$class = make_class('ro', 'writer', 'Test::Class::WriterRO');
43ok($class, "Can define attr with ro + writer");
44
45$obj = $class->new();
46
47can_ok($obj, qw/foo _foo/);
48lives_ok {$obj->_foo(1)} "$class->_foo is writer";
49is($obj->foo(), 1, "$class->foo is reader");
50dies_ok {$obj->foo(1)} "$class->foo is not writer";
51isnt($obj->_foo(), 1, "$class->_foo is not reader");
52
53$class = make_class('rw', 'accessor', 'Test::Class::AccessorRW');
54ok($class, "Can define attr with rw + accessor");
55
56$obj = $class->new();
57
58can_ok($obj, qw/_foo/);
59lives_ok {$obj->_foo(1)} "$class->_foo is writer";
60is($obj->_foo(), 1, "$class->foo is reader");
61
62dies_ok { make_class('ro', 'accessor', "Test::Class::AccessorRO"); } "Cant define attr with ro + accessor";
63