3
# $Id: constraints_affordance.t 682 2004-09-28 05:59:10Z theory $
5
##############################################################################
7
##############################################################################
10
use Test::More tests => 22;
12
##############################################################################
13
# Create a simple class.
14
##############################################################################
16
package Class::Meta::Testing123;
20
main::use_ok('Class::Meta');
21
main::use_ok('Class::Meta::Types::String', 'affordance');
25
# Import Test::More functions into this package.
27
ok( my $cm = Class::Meta->new, "Create new Class::Meta object" );
30
ok( $cm->add_constructor( name => 'new',
34
# Add a required attribute with a default
35
ok( $cm->add_attribute( name => 'req_def',
40
"Add required attribute with a default" );
42
# Add a once attribute.
43
ok( $cm->add_attribute( name => 'once',
47
"Add a once attribute" );
49
# Add a once attribute with a default.
50
ok( $cm->add_attribute( name => 'once_def',
55
"Add a once attribute" );
57
# Add a required once attribute with a default.
58
ok( $cm->add_attribute( name => 'once_req',
64
"Add a required once attribute" );
67
ok( $cm->build, "Build class" );
72
ok( my $obj = Class::Meta::Testing123->new, 'Create new object' );
74
# Check required attribute.
75
is( $obj->get_req_def, 'hello', 'Check required attribute' );
76
ok( $obj->set_req_def('foo'), 'Set required attribute' );
77
is( $obj->get_req_def, 'foo', 'Check required attribute new value' );
78
eval { $obj->set_req_def(undef) };
79
ok( $@, 'Catch required exception' );
81
# Check once attribute.
82
is( $obj->get_once, undef, "Once is undefined" );
83
ok( $obj->set_once('hee'), "set once attribute" );
84
is( $obj->get_once, 'hee', "Check new once value" );
85
eval { $obj->set_once('ha') };
86
ok( $@, 'Catch once exception' );
88
# Check once with a default.
89
is( $obj->get_once_def, 'hola', 'Check once_def' );
90
eval { $obj->set_once_def('ha') };
91
ok( $@, 'Catch once_def exception' );
93
# Check required once with a default.
94
is( $obj->get_once_req, 'bonjour', 'Check once_req' );
95
eval { $obj->set_once_def('ha') };
96
ok( $@, 'Catch once_req exception' );