Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (72 sloc) 2.532 kb
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
1 use v6;
2
3 use Test;
4
3b8f4d2d »
2009-02-11 [t/spec] Some more tests to exercise <->.
5 plan 17;
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
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
db93e894 »
2008-11-08 [t/spec] unmark some passing rakudo tests due to container/value refa…
18 # eval_dies_ok instead of dies_ok
d4308c84 »
2008-11-06 [t/spec] another test for ro-ness of arguments.
19 #
20 # test twice, once with assignment and once with increment, rakudo
21 # used to catch the first but not the latter.
22 #
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
23 eval_dies_ok '
97fdbb2e »
2008-11-06 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
24 my $tmp = 1;
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
25 sub mods_param ($x) { $x++; }
97fdbb2e »
2008-11-06 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
26 mods_param($tmp)
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
27 ',
28 'can\'t modify parameter, constant by default';
db93e894 »
2008-11-08 [t/spec] unmark some passing rakudo tests due to container/value refa…
29
d4308c84 »
2008-11-06 [t/spec] another test for ro-ness of arguments.
30 eval_dies_ok '
31 my $tmp = 1;
32 sub mods_param ($x) { $x = 1; }
33 mods_param($tmp)
34 ',
35 'can\'t modify parameter, constant by default';
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
36
37 # is readonly
db93e894 »
2008-11-08 [t/spec] unmark some passing rakudo tests due to container/value refa…
38 eval_dies_ok 'sub mods_param_constant ($x is readonly) { $x++; };
39 mods_param_constant($foo);' ,
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
40 'can\'t modify constant parameter, constant by default';
41
42 sub mods_param_rw ($x is rw) { $x++; }
1b911a17 »
2008-09-03 [t/spec] fudged S06-traits/misc.t for rakudo
43 #?rakudo todo "'is rw' can't modify constants"
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
44 dies_ok { mods_param_rw(1) }, 'can\'t modify constant even if we claim it\'s rw';
45 sub mods_param_rw_does_nothing ($x is rw) { $x; }
46 lives_ok { mods_param_rw_does_nothing(1) }, 'is rw with non-lvalue should autovivify';
47
48 lives_ok { mods_param_rw($foo) }, 'pass by "is rw" doesn\'t die';
49 is($foo, 2, 'pass by reference works');
50
51 #icopy
52 $foo=1;
53 sub mods_param_copy ($x is copy) {$x++;}
54 lives_ok { mods_param_copy($foo) }, 'is copy';
55 is($foo, 1, 'pass by value works');
56
26e3caa8 »
2008-09-29 [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
57 # same test with default value
58 sub boom ($arg is copy = 0) { $arg++ }
59
60 lives_ok { boom(42) }, "can modify a copy";
61
62
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
63 # is ref
1b911a17 »
2008-09-03 [t/spec] fudged S06-traits/misc.t for rakudo
64 #?rakudo skip 'is ref'
65 {
66 $foo=1;
67 sub mods_param_ref ($x is ref) { $x++; }
68 dies_ok { mods_param_ref(1); }, 'is ref with non-lvalue';
1c0341cb »
2009-06-19 [t/spec] Change more Pugs todo flags to fudge commands
69 #?pugs todo
70 lives_ok { mods_param_ref($foo); }, 'is ref with non-lvalue';
71 #?pugs todo
72 is($foo, 2, 'is ref works');
1b911a17 »
2008-09-03 [t/spec] fudged S06-traits/misc.t for rakudo
73 }
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
74
3b8f4d2d »
2009-02-11 [t/spec] Some more tests to exercise <->.
75
76 # with <-> we should still obey readonly traits
77 {
78 my $anon1 = <-> $a is readonly, $b { $b++ };
79 my $anon2 = <-> $a is readonly, $b { $a++ };
80 my $x = 1;
81 $anon1($x, $x);
82 is($x, 2, '<-> does not override explicit traints (sanity)');
83 dies_ok({ $anon2($x, $x) }, '<-> does not override explicit traints');
84 is($x, 2, '<-> does not override explicit traints (sanity)');
85 }
86
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
87 # is context
88 # Doesn't even compile, which is lucky, because I don't understand it well
89 # enough to write an actual test...
90 ok(eval('sub my_format (*@data is context(Item)) { }; 1'), "is context - compile check");
91
26e3caa8 »
2008-09-29 [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
92
93
4ae127ae »
2008-09-03 [t] moved sub_parameter_traits to spec/
94 # To do - check that is context actually works
95 # vim: ft=perl6
Something went wrong with that request. Please try again.