Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 126 lines (104 sloc) 2.814 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
3b76c73 @jnthn Test for RT#118183.
jnthn authored
7 plan 25;
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];
73 is t($a), 3, 'passing [1,2,3] to @a is copy does results in three array items';
74 }
75
594a92c [t/spec] Added tests for RT #76804.
Kodi authored
76 # RT #76804
77 {
78 sub f($arg is copy) {
79 my $other;
80 ($arg, $other) = 5, 6;
81 $arg;
82 };
83 is f(0), 5, 'list assignment (0)';
84 is f(1), 5, 'list assignment (1)';
85 }
86
4a42b2e @moritz test "is copy" on an optional hash parameter, RT #74454
moritz authored
87 # RT #74454
88 {
89f0409 @TimToady warning suppression, mostly "not used"
TimToady authored
89 sub g(%hash? is copy) { }; #OK not used
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
90 lives-ok { g() }, 'can call a sub with an optional "is copy" hash param';
4a42b2e @moritz test "is copy" on an optional hash parameter, RT #74454
moritz authored
91 }
92
584c1a8 @moritz test for RT #75302
moritz authored
93 # RT #75302
94 {
95 sub h($x is copy) {
96 $x = 'abc';
97 $x
98 }
99 is h(*), 'abc', 'can re-assign to "is copy" parameter that held a Whatever';
100 }
101
ba5ee93 @moritz RT #82810, ||= on an "is copy" array parameter
moritz authored
102 # RT #82810
103 {
f3ee697 @colomon Change meaningless function name from i to j so it doesn't interact w…
colomon authored
104 sub j(@a is copy) { @a ||= -1, -1, +1, +1; @a.join(',') }
105 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
106 }
107
dee9fde @timo test for RT #74430: index and is copy interaction
timo authored
108 # RT #74430
109 {
110 sub foo(@items is copy) { @items[0..^1] };
111 my @items = 'a'...'g';
112 is foo(@items), 'a', 'can slice "is copy" arrays';
113 }
114
2b710bd @moritz RT #117583: is copy param can be redeclared
moritz authored
115 # RT #117583
116 # the redeclaration thingy is only a warning
e816632 @lizmat s/eval_lives_ok/eval-lives-ok/g
lizmat authored
117 eval-lives-ok 'sub f ($x is copy) { my $x }';
2b710bd @moritz RT #117583: is copy param can be redeclared
moritz authored
118
3b76c73 @jnthn Test for RT#118183.
jnthn authored
119 # RT #118183
120 {
121 sub a ($a is copy) { $a = 5 }
122 is a(1), 5, 'Simple, easily inlinable, sub with copy trait not broken';
123 }
594a92c [t/spec] Added tests for RT #76804.
Kodi authored
124
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
125 # vim: ft=perl6
Something went wrong with that request. Please try again.