Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (52 sloc) 1.589 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
0de48a0 Add tests for is copy in use with arrays and hashes.
jnthn authored
7 plan 16;
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
64 # vim: ft=perl6
Something went wrong with that request. Please try again.