Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 112 lines (92 sloc) 2.468 kB
c09da2d [spec] moved var/is_copy.t to spec/
moritz authored
1 use v6;
2 use Test;
3
4 # L<S06/"Parameter traits"/"=item is copy">
5 # should be moved with other subroutine tests?
6
ba5ee93 @moritz RT #82810, ||= on an "is copy" array parameter
moritz authored
7 plan 22;
c09da2d [spec] moved var/is_copy.t to spec/
moritz authored
8
9 {
10 sub foo($a is copy) {
11 $a = 42;
12 return 19;
13 }
14
15 my $bar = 23;
16 is $bar, 23, "basic sanity";
17 is foo($bar), 19, "calling a sub with an is copy param";
18 is $bar, 23, "sub did not change our variable";
19 }
603f998 [t] merged is_copy_ne_is_rw.t into is-copy.t
moritz authored
20 {
21 sub copy_tester ($copy_tester is copy = 5, $bar is copy = 10) {
22 $copy_tester += $bar;
23 $copy_tester;
24 }
25
26 is(copy_tester(), 15, 'calling without arguments');
27
28 is(copy_tester(10), 20, 'calling with one argument');
29 is(copy_tester(10, 15), 25, 'calling with two arguments');
30
31 my ($baz, $quux) = (10, 15);
32
33 is(copy_tester($baz), 20, 'calling with one argument');
34 is($baz, 10, 'variable was not affected');
35
36 is(copy_tester($baz, $quux), 25, 'calling with two arguments');
37 is($baz, 10, 'variable was not affected');
38 }
0de48a0 Add tests for is copy in use with arrays and hashes.
jnthn authored
39
40 # is copy with arrays
41 {
42 sub array_test(@testc is copy) {
43 is(@testc[0], 1, 'array copied correctly by is copy');
44 @testc[0] = 123;
45 is(@testc[0], 123, 'can modify array copied by is copy...');
46 };
47 my @test = (1, 2, 3);
48 array_test(@test);
49 is(@test[0], 1, '...and original is unmodified.');
50 }
51
52 # is copy with hashes
53 {
54 sub hash_test(%h is copy) {
55 is(%h<x>, 1, 'hash copied correctly by is copy');
56 %h<x> = 123;
57 is(%h<x>, 123, 'can modify hash copied by is copy...');
58 };
59 my %test = (x => 1);
60 hash_test(%test);
61 is(%test<x>, 1, '...and original is unmodified.');
62 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
63
1914354 [t/spec] test for RT #76242, "is copy" array parameters
moritz authored
64 # RT #76242
65 {
66 sub t(@a is copy) {
67 my $x = 0;
68 $x++ for @a;
69 $x;
70 }
71
72 my $a = [1, 2, 3];
77ec25f @coke pugs fudge
coke authored
73 #?pugs todo
1914354 [t/spec] test for RT #76242, "is copy" array parameters
moritz authored
74 is t($a), 3, 'passing [1,2,3] to @a is copy does results in three array items';
75 }
76
594a92c [t/spec] Added tests for RT #76804.
Kodi authored
77 # RT #76804
78 {
79 sub f($arg is copy) {
80 my $other;
81 ($arg, $other) = 5, 6;
82 $arg;
83 };
84 is f(0), 5, 'list assignment (0)';
85 is f(1), 5, 'list assignment (1)';
86 }
87
4a42b2e @moritz test "is copy" on an optional hash parameter, RT #74454
moritz authored
88 # RT #74454
89 {
89f0409 @TimToady warning suppression, mostly "not used"
TimToady authored
90 sub g(%hash? is copy) { }; #OK not used
4a42b2e @moritz test "is copy" on an optional hash parameter, RT #74454
moritz authored
91 lives_ok { g() }, 'can call a sub with an optional "is copy" hash param';
92 }
93
584c1a8 @moritz test for RT #75302
moritz authored
94 # RT #75302
95 {
96 sub h($x is copy) {
97 $x = 'abc';
98 $x
99 }
100 is h(*), 'abc', 'can re-assign to "is copy" parameter that held a Whatever';
101 }
102
ba5ee93 @moritz RT #82810, ||= on an "is copy" array parameter
moritz authored
103 # RT #82810
104 {
f3ee697 @colomon Change meaningless function name from i to j so it doesn't interact w…
colomon authored
105 sub j(@a is copy) { @a ||= -1, -1, +1, +1; @a.join(',') }
77ec25f @coke pugs fudge
coke authored
106 #?pugs todo
f3ee697 @colomon Change meaningless function name from i to j so it doesn't interact w…
colomon authored
107 is j([1, 2, 3, 4]), '1,2,3,4', 'can use ||= on "is copy" array';
ba5ee93 @moritz RT #82810, ||= on an "is copy" array parameter
moritz authored
108 }
109
594a92c [t/spec] Added tests for RT #76804.
Kodi authored
110
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
111 # vim: ft=perl6
Something went wrong with that request. Please try again.