Skip to content
Newer
Older
100644 59 lines (42 sloc) 1.56 KB
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
1 use v6;
2
3 use Test;
4
5 plan 12;
6
7 =begin description
8
9 Testing parameter traits for subroutines
10
11 L<S06/"Parameter traits">
12
13 =end description
14
15 my $foo=1;
16
17 # note: many of these errors can be detected at compile time, so need
18 # eval_dies_ok instead of dies_ok
19 eval_dies_ok '
20 sub mods_param ($x) { $x++; }
21 mods_param($foo)
22 ',
23 'can\'t modify parameter, constant by default';
24
25
26 # is readonly
27 eval_dies_ok 'sub mods_param_constant ($x is readonly) { $x++; };
28 mods_param_constant($foo);' ,
29 'can\'t modify constant parameter, constant by default';
30
31 sub mods_param_rw ($x is rw) { $x++; }
32 dies_ok { mods_param_rw(1) }, 'can\'t modify constant even if we claim it\'s rw';
33 sub mods_param_rw_does_nothing ($x is rw) { $x; }
34 lives_ok { mods_param_rw_does_nothing(1) }, 'is rw with non-lvalue should autovivify';
35
36 lives_ok { mods_param_rw($foo) }, 'pass by "is rw" doesn\'t die';
37 is($foo, 2, 'pass by reference works');
38
39 #icopy
40 $foo=1;
41 sub mods_param_copy ($x is copy) {$x++;}
42 lives_ok { mods_param_copy($foo) }, 'is copy';
43 is($foo, 1, 'pass by value works');
44
45 # is ref
46 $foo=1;
47 sub mods_param_ref ($x is ref) { $x++; }
48 dies_ok { mods_param_ref(1); }, 'is ref with non-lvalue';
49 lives_ok { mods_param_ref($foo); }, 'is ref with non-lvalue', :todo;
50 is($foo, 2, 'is ref works', :todo);
51
52 # is context
53 # Doesn't even compile, which is lucky, because I don't understand it well
54 # enough to write an actual test...
55 ok(eval('sub my_format (*@data is context(Item)) { }; 1'), "is context - compile check");
56
57 # To do - check that is context actually works
58 # vim: ft=perl6
Something went wrong with that request. Please try again.