|
1 |
| -plan(23); |
| 1 | +plan(33); |
2 | 2 |
|
3 | 3 | ok(nqp::isnull(nqp::decont(nqp::null())), 'nqp::decont works on nqp::null');
|
4 | 4 |
|
@@ -131,3 +131,56 @@ ok(nqp::isnull(nqp::decont(nqp::null())), 'nqp::decont works on nqp::null');
|
131 | 131 |
|
132 | 132 | $cont.check_self();
|
133 | 133 | }
|
| 134 | + |
| 135 | +{ |
| 136 | + my class SimpleCont { |
| 137 | + has $!content; |
| 138 | + } |
| 139 | + |
| 140 | + sub fetch($cont) { nqp::getattr($cont, SimpleCont, '$!content') } |
| 141 | + sub store($cont, $value) {nqp::bindattr($cont, SimpleCont, '$!content', $value) } |
| 142 | + |
| 143 | + nqp::setcontspec(SimpleCont, 'code_pair', nqp::hash( |
| 144 | + 'fetch', &fetch, |
| 145 | + 'store', &store |
| 146 | + )); |
| 147 | + |
| 148 | + my $cont := nqp::create(SimpleCont); |
| 149 | + |
| 150 | + my class Value { |
| 151 | + has $!attr; |
| 152 | + method attr() { $!attr } |
| 153 | + method set_attr($value) { $!attr := $value } |
| 154 | + } |
| 155 | + |
| 156 | + nqp::assign($cont, Value); |
| 157 | + |
| 158 | + ok(nqp::eqaddr(nqp::how_nd($cont), SimpleCont.HOW), 'nqp::how_nd does not decont'); |
| 159 | + ok(nqp::eqaddr(nqp::how($cont), Value.HOW), 'nqp::how deconts'); |
| 160 | + |
| 161 | + ok(nqp::isconcrete_nd($cont), 'nqp::isconcrete_nd does not decont'); |
| 162 | + ok(!nqp::isconcrete($cont), 'nqp::isconcrete does decont'); |
| 163 | + |
| 164 | + ok(nqp::eqaddr(nqp::what_nd($cont), SimpleCont), 'nqp::what_nd does not decont'); |
| 165 | + ok(nqp::eqaddr(nqp::what($cont), Value), 'nqp::what deconts'); |
| 166 | + |
| 167 | + nqp::assign($cont, Value.new(attr => 123)); |
| 168 | + |
| 169 | + my $clone_of_value := nqp::clone($cont); |
| 170 | + |
| 171 | + $clone_of_value.set_attr(456); |
| 172 | + |
| 173 | + is($cont.attr, 123, 'nqp::cloned cloned content'); |
| 174 | + |
| 175 | + my $clone_of_cont := nqp::clone_nd($cont); |
| 176 | + |
| 177 | + is($clone_of_cont.attr, 123, 'clone_nd container start with right value'); |
| 178 | + |
| 179 | + $clone_of_cont.set_attr(678); |
| 180 | + |
| 181 | + nqp::assign($clone_of_cont, $clone_of_value); |
| 182 | + |
| 183 | + is($clone_of_cont.attr, 456, 'clone_nd container can be assigned to'); |
| 184 | + |
| 185 | + is($cont.attr, 678, 'original container is independent of clone but had shared value'); |
| 186 | +} |
0 commit comments