Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (90 sloc) 2.422 kb
c09da2db »
2008-07-24 [spec] moved var/is_copy.t to spec/
1 use v6;
2 use Test;
3
4 # L<S06/"Parameter traits"/"=item is copy">
5 # should be moved with other subroutine tests?
6
ba5ee931 »
2012-01-30 RT #82810, ||= on an "is copy" array parameter
7 plan 22;
c09da2db »
2008-07-24 [spec] moved var/is_copy.t to spec/
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 }
603f9986 »
2009-02-01 [t] merged is_copy_ne_is_rw.t into is-copy.t
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 }
0de48a03 »
2009-02-13 Add tests for is copy in use with arrays and hashes.
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 }
7f29bc53 »
2009-08-08 [t/spec] Add vim: lines everywhere.
63
1914354d »
2010-06-29 [t/spec] test for RT #76242, "is copy" array parameters
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
594a92cc »
2010-07-29 [t/spec] Added tests for RT #76804.
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
4a42b2ed »
2011-10-01 test "is copy" on an optional hash parameter, RT #74454
87 # RT #74454
88 {
89 sub g(%hash? is copy) { };
90 lives_ok { g() }, 'can call a sub with an optional "is copy" hash param';
91 }
92
584c1a83 »
2011-10-01 test for RT #75302
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
ba5ee931 »
2012-01-30 RT #82810, ||= on an "is copy" array parameter
102 # RT #82810
103 {
104 sub i(@a is copy) { @a ||= -1, -1, +1, +1; @a.join(',') }
105 is i([1, 2, 3, 4]), '1,2,3,4', 'can use ||= on "is copy" array';
106 }
107
594a92cc »
2010-07-29 [t/spec] Added tests for RT #76804.
108
7f29bc53 »
2009-08-08 [t/spec] Add vim: lines everywhere.
109 # vim: ft=perl6
Something went wrong with that request. Please try again.