Skip to content
Newer
Older
100644 84 lines (62 sloc) 2.12 KB
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
1 use v6;
2
3 use Test;
4
d4308c8 [t/spec] another test for ro-ness of arguments.
moritz authored Nov 6, 2008
5 plan 14;
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
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
db93e89 [t/spec] unmark some passing rakudo tests due to container/value refa…
particle authored Nov 8, 2008
18 # eval_dies_ok instead of dies_ok
d4308c8 [t/spec] another test for ro-ness of arguments.
moritz authored Nov 6, 2008
19 #
20 # test twice, once with assignment and once with increment, rakudo
21 # used to catch the first but not the latter.
22 #
97fdbb2 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
moritz authored Nov 6, 2008
23 #?rakudo todo 'TODO: catch modification of subroutine arg'
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
24 eval_dies_ok '
97fdbb2 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
moritz authored Nov 6, 2008
25 my $tmp = 1;
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
26 sub mods_param ($x) { $x++; }
97fdbb2 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
moritz authored Nov 6, 2008
27 mods_param($tmp)
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
28 ',
29 'can\'t modify parameter, constant by default';
db93e89 [t/spec] unmark some passing rakudo tests due to container/value refa…
particle authored Nov 8, 2008
30
d4308c8 [t/spec] another test for ro-ness of arguments.
moritz authored Nov 6, 2008
31 eval_dies_ok '
32 my $tmp = 1;
33 sub mods_param ($x) { $x = 1; }
34 mods_param($tmp)
35 ',
36 'can\'t modify parameter, constant by default';
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
37
38 # is readonly
db93e89 [t/spec] unmark some passing rakudo tests due to container/value refa…
particle authored Nov 8, 2008
39 eval_dies_ok 'sub mods_param_constant ($x is readonly) { $x++; };
40 mods_param_constant($foo);' ,
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
41 'can\'t modify constant parameter, constant by default';
42
43 sub mods_param_rw ($x is rw) { $x++; }
1b911a1 [t/spec] fudged S06-traits/misc.t for rakudo
moritz authored Sep 3, 2008
44 #?rakudo todo "'is rw' can't modify constants"
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
45 dies_ok { mods_param_rw(1) }, 'can\'t modify constant even if we claim it\'s rw';
46 sub mods_param_rw_does_nothing ($x is rw) { $x; }
47 lives_ok { mods_param_rw_does_nothing(1) }, 'is rw with non-lvalue should autovivify';
48
49 lives_ok { mods_param_rw($foo) }, 'pass by "is rw" doesn\'t die';
50 is($foo, 2, 'pass by reference works');
51
52 #icopy
53 $foo=1;
54 sub mods_param_copy ($x is copy) {$x++;}
55 lives_ok { mods_param_copy($foo) }, 'is copy';
56 is($foo, 1, 'pass by value works');
57
26e3caa [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
moritz authored Sep 29, 2008
58 # same test with default value
59 sub boom ($arg is copy = 0) { $arg++ }
60
61 lives_ok { boom(42) }, "can modify a copy";
62
63
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
64 # is ref
1b911a1 [t/spec] fudged S06-traits/misc.t for rakudo
moritz authored Sep 3, 2008
65 #?rakudo skip 'is ref'
66 {
67 $foo=1;
68 sub mods_param_ref ($x is ref) { $x++; }
69 dies_ok { mods_param_ref(1); }, 'is ref with non-lvalue';
70 lives_ok { mods_param_ref($foo); }, 'is ref with non-lvalue', :todo;
71 is($foo, 2, 'is ref works', :todo);
72 }
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
73
74 # is context
75 # Doesn't even compile, which is lucky, because I don't understand it well
76 # enough to write an actual test...
1b911a1 [t/spec] fudged S06-traits/misc.t for rakudo
moritz authored Sep 3, 2008
77 #?rakudo skip 'is context'
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
78 ok(eval('sub my_format (*@data is context(Item)) { }; 1'), "is context - compile check");
79
26e3caa [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
moritz authored Sep 29, 2008
80
81
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
82 # To do - check that is context actually works
83 # vim: ft=perl6
Something went wrong with that request. Please try again.