Skip to content

Commit 933e0cb

Browse files
committed
Test nqp::with with containers
1 parent 7d5f860 commit 933e0cb

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

t/nqp/067-container.t

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
plan(35);
1+
plan(41);
22

33
ok(nqp::isnull(nqp::decont(nqp::null())), 'nqp::decont works on nqp::null');
44

@@ -186,4 +186,31 @@ ok(nqp::isnull(nqp::decont(nqp::null())), 'nqp::decont works on nqp::null');
186186
is($clone_of_cont.attr, 456, 'clone_nd container can be assigned to');
187187

188188
is($cont.attr, 678, 'original container is independent of clone but had shared value');
189+
190+
class ValueWithDefined {
191+
has $!defined;
192+
method defined() {
193+
$!defined;
194+
}
195+
}
196+
197+
198+
my $cont_for_with_defined := nqp::create(SimpleCont);
199+
nqp::assign($cont_for_with_defined, ValueWithDefined.new(defined => 1));
200+
201+
my $cont_for_with_not_defined := nqp::create(SimpleCont);
202+
nqp::assign($cont_for_with_not_defined, ValueWithDefined.new(defined => 0));
203+
204+
my $cont_with_false_value := nqp::create(SimpleCont);
205+
nqp::assign($cont_with_false_value, 0);
206+
my $cont_for_with_container_defined := nqp::create(SimpleCont);
207+
nqp::assign($cont_for_with_container_defined, ValueWithDefined.new(defined => $cont_with_false_value));
208+
209+
is(nqp::with($cont_for_with_defined, "good", "bad"), "good", 'with - defined case');
210+
is(nqp::with($cont_for_with_not_defined, "good", "bad"), "bad", 'with - undefined case');
211+
is(nqp::with($cont_for_with_container_defined, "good", "bad"), "good", 'with - defined returns container');
212+
213+
is(nqp::without($cont_for_with_defined, "good", "bad"), "bad", 'without - defined case');
214+
is(nqp::without($cont_for_with_not_defined, "good", "bad"), "good", 'without - undefined case');
215+
is(nqp::without($cont_for_with_container_defined, "good", "bad"), "bad", 'without - defined returns container');
189216
}

0 commit comments

Comments
 (0)