Remove shebangs from tests.
[gitmo/Class-MOP.git] / t / 061_instance_inline.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 15;
5 use Test::Exception;
6
7 use Class::MOP::Instance;
8
9 my $C = 'Class::MOP::Instance';
10
11 {
12     my $instance  = '$self';
13     my $slot_name = '"foo"';
14     my $value     = '$value';
15
16     is($C->inline_get_slot_value($instance, $slot_name),
17       '$self->{"foo"}',
18       '... got the right code for get_slot_value');
19
20     is($C->inline_set_slot_value($instance, $slot_name, $value),
21       '$self->{"foo"} = $value',
22       '... got the right code for set_slot_value');
23
24     is($C->inline_initialize_slot($instance, $slot_name),
25       '',
26       '... got the right code for initialize_slot');
27
28     is($C->inline_is_slot_initialized($instance, $slot_name),
29       'exists $self->{"foo"}',
30       '... got the right code for get_slot_value');
31
32     is($C->inline_weaken_slot_value($instance, $slot_name),
33       'Scalar::Util::weaken( $self->{"foo"} )',
34       '... got the right code for weaken_slot_value');
35
36     is($C->inline_strengthen_slot_value($instance, $slot_name),
37       '$self->{"foo"} = $self->{"foo"}',
38       '... got the right code for strengthen_slot_value');
39 }
40
41 {
42     my $instance  = '$_[0]';
43     my $slot_name = '$attr_name';
44     my $value     = '[]';
45
46     is($C->inline_get_slot_value($instance, $slot_name),
47       '$_[0]->{$attr_name}',
48       '... got the right code for get_slot_value');
49
50     is($C->inline_set_slot_value($instance, $slot_name, $value),
51       '$_[0]->{$attr_name} = []',
52       '... got the right code for set_slot_value');
53
54     is($C->inline_initialize_slot($instance, $slot_name),
55       '',
56       '... got the right code for initialize_slot');
57
58     is($C->inline_is_slot_initialized($instance, $slot_name),
59       'exists $_[0]->{$attr_name}',
60       '... got the right code for get_slot_value');
61
62     is($C->inline_weaken_slot_value($instance, $slot_name),
63       'Scalar::Util::weaken( $_[0]->{$attr_name} )',
64       '... got the right code for weaken_slot_value');
65
66     is($C->inline_strengthen_slot_value($instance, $slot_name),
67       '$_[0]->{$attr_name} = $_[0]->{$attr_name}',
68       '... got the right code for strengthen_slot_value');
69 }
70
71 my $accessor_string = "sub {\n"
72 . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
73 . " if scalar \@_ == 2;\n"
74 . $C->inline_get_slot_value('$_[0]', '$attr_name')
75 . ";\n}";
76
77 is($accessor_string,
78    q|sub {
79 $_[0]->{$attr_name} = $_[1] if scalar @_ == 2;
80 $_[0]->{$attr_name};
81 }|,
82     '... got the right code string for accessor');
83
84 my $reader_string = "sub {\n"
85 . $C->inline_get_slot_value('$_[0]', '$attr_name')
86 . ";\n}";
87
88 is($reader_string,
89    q|sub {
90 $_[0]->{$attr_name};
91 }|,
92     '... got the right code string for reader');
93
94 my $writer_string = "sub {\n"
95 . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
96 . ";\n}";
97
98 is($writer_string,
99    q|sub {
100 $_[0]->{$attr_name} = $_[1];
101 }|,
102     '... got the right code string for writer');
103
104