X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F061_instance_inline.t;h=1679245aa6d6fd2923d8aaad9d4457411d7c6859;hb=5caf45ce90def730e4c3743050c7354a78ed9800;hp=3e8c89ff068849a1464bfc8f4bf0d1baec3b4fb9;hpb=ee7c04677234b6bfa7eddc0896ef4255e713d1b2;p=gitmo%2FClass-MOP.git diff --git a/t/061_instance_inline.t b/t/061_instance_inline.t index 3e8c89f..1679245 100644 --- a/t/061_instance_inline.t +++ b/t/061_instance_inline.t @@ -7,7 +7,7 @@ use Test::More tests => 16; use Test::Exception; BEGIN { - use_ok('Class::MOP::Instance'); + use_ok('Class::MOP::Instance'); } my $C = 'Class::MOP::Instance'; @@ -17,92 +17,92 @@ my $C = 'Class::MOP::Instance'; my $slot_name = '"foo"'; my $value = '$value'; - is($C->inline_get_slot_value($instance, $slot_name), + is($C->inline_get_slot_value($instance, $slot_name), '$self->{"foo"}', '... got the right code for get_slot_value'); - - is($C->inline_set_slot_value($instance, $slot_name, $value), + + is($C->inline_set_slot_value($instance, $slot_name, $value), '$self->{"foo"} = $value', - '... got the right code for set_slot_value'); + '... got the right code for set_slot_value'); - is($C->inline_initialize_slot($instance, $slot_name), - '$self->{"foo"} = undef', + is($C->inline_initialize_slot($instance, $slot_name), + '', '... got the right code for initialize_slot'); - - is($C->inline_is_slot_initialized($instance, $slot_name), - 'exists $self->{"foo"} ? 1 : 0', - '... got the right code for get_slot_value'); - - is($C->inline_weaken_slot_value($instance, $slot_name), + + is($C->inline_is_slot_initialized($instance, $slot_name), + 'exists $self->{"foo"}', + '... got the right code for get_slot_value'); + + is($C->inline_weaken_slot_value($instance, $slot_name), 'Scalar::Util::weaken( $self->{"foo"} )', - '... got the right code for weaken_slot_value'); - - is($C->inline_strengthen_slot_value($instance, $slot_name), + '... got the right code for weaken_slot_value'); + + is($C->inline_strengthen_slot_value($instance, $slot_name), '$self->{"foo"} = $self->{"foo"}', - '... got the right code for strengthen_slot_value'); -} - + '... got the right code for strengthen_slot_value'); +} + { my $instance = '$_[0]'; my $slot_name = '$attr_name'; my $value = '[]'; - is($C->inline_get_slot_value($instance, $slot_name), + is($C->inline_get_slot_value($instance, $slot_name), '$_[0]->{$attr_name}', '... got the right code for get_slot_value'); - - is($C->inline_set_slot_value($instance, $slot_name, $value), + + is($C->inline_set_slot_value($instance, $slot_name, $value), '$_[0]->{$attr_name} = []', - '... got the right code for set_slot_value'); - - is($C->inline_initialize_slot($instance, $slot_name), - '$_[0]->{$attr_name} = undef', - '... got the right code for initialize_slot'); - - is($C->inline_is_slot_initialized($instance, $slot_name), - 'exists $_[0]->{$attr_name} ? 1 : 0', - '... got the right code for get_slot_value'); - - is($C->inline_weaken_slot_value($instance, $slot_name), + '... got the right code for set_slot_value'); + + is($C->inline_initialize_slot($instance, $slot_name), + '', + '... got the right code for initialize_slot'); + + is($C->inline_is_slot_initialized($instance, $slot_name), + 'exists $_[0]->{$attr_name}', + '... got the right code for get_slot_value'); + + is($C->inline_weaken_slot_value($instance, $slot_name), 'Scalar::Util::weaken( $_[0]->{$attr_name} )', - '... got the right code for weaken_slot_value'); - - is($C->inline_strengthen_slot_value($instance, $slot_name), + '... got the right code for weaken_slot_value'); + + is($C->inline_strengthen_slot_value($instance, $slot_name), '$_[0]->{$attr_name} = $_[0]->{$attr_name}', - '... got the right code for strengthen_slot_value'); -} - + '... got the right code for strengthen_slot_value'); +} + my $accessor_string = "sub {\n" . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]') . " if scalar \@_ == 2;\n" . $C->inline_get_slot_value('$_[0]', '$attr_name') . ";\n}"; -is($accessor_string, +is($accessor_string, q|sub { $_[0]->{$attr_name} = $_[1] if scalar @_ == 2; $_[0]->{$attr_name}; -}|, +}|, '... got the right code string for accessor'); my $reader_string = "sub {\n" . $C->inline_get_slot_value('$_[0]', '$attr_name') . ";\n}"; -is($reader_string, +is($reader_string, q|sub { $_[0]->{$attr_name}; -}|, +}|, '... got the right code string for reader'); - + my $writer_string = "sub {\n" . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]') . ";\n}"; -is($writer_string, +is($writer_string, q|sub { $_[0]->{$attr_name} = $_[1]; -}|, - '... got the right code string for writer'); - - \ No newline at end of file +}|, + '... got the right code string for writer'); + +