Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (41 sloc) 1.269 kb
207f13f [t] and [t/spec]
moritz authored
1 use v6;
2
3 use Test;
4
1844dc7 [t/spec] Add test case for RT#62828.
jnthn authored
5 plan 12;
207f13f [t] and [t/spec]
moritz authored
6
7 # L<S12/Construction and Initialization/You can clone an object, changing some of the attributes:>
8 class Foo {
9 has $.attr;
10 method set_attr ($attr) { $.attr = $attr; }
11 method get_attr () { $.attr }
12 }
13
14 my $a = Foo.new(:attr(13));
15 isa_ok($a, Foo);
16 is($a.get_attr(), 13, '... got the right attr value');
17
18 my $c = $a.clone();
19 isa_ok($c, Foo);
20 is($c.get_attr(), 13, '... cloned object retained attr value');
eb964b5 [t/spec] Modify test that re-declared a variable (but isn't testing for ...
jnthn authored
21
207f13f [t] and [t/spec]
moritz authored
22 my $val;
23 lives_ok {
24 $val = $c === $a;
25 }, "... cloned object isn't identity equal to the original object";
26 ok($val.defined && !$val, "... cloned object isn't identity equal to the original object");
27
28 my $d;
29 lives_ok {
30 $d = $a.clone(attr => 42)
31 }, '... cloning with supplying a new attribute value';
32
eb964b5 [t/spec] Modify test that re-declared a variable (but isn't testing for ...
jnthn authored
33 my $val2;
207f13f [t] and [t/spec]
moritz authored
34 lives_ok {
eb964b5 [t/spec] Modify test that re-declared a variable (but isn't testing for ...
jnthn authored
35 $val2 = $d.get_attr()
207f13f [t] and [t/spec]
moritz authored
36 }, '... getting attr from cloned value';
eb964b5 [t/spec] Modify test that re-declared a variable (but isn't testing for ...
jnthn authored
37 is($val2, 42, '... cloned object has proper attr value');
1844dc7 [t/spec] Add test case for RT#62828.
jnthn authored
38
39 # Test to cover RT#62828, which exposed a bad interaction between while loops
40 # and cloning.
41 class A {
42 has $.b;
43 };
44 while shift [A.new( :b(0) )] -> $a {
45 is($a.b, 0, 'sanity before clone');
46 my $x = $a.clone( :b($a.b + 1) );
47 is($a.b, 0, 'clone did not change value in original object');
48 is($x.b, 1, 'however, in the clone it was changed');
49 last;
50 }
Something went wrong with that request. Please try again.