Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 103 lines (79 sloc) 2.804 kb
4ae127ae » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
1 use v6;
2
3 use Test;
4
5547d3f2 » kyle
2009-07-09 [t/spec] Test for RT #60966
5 plan 20;
4ae127ae » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
6
7 =begin description
8
9 Testing parameter traits for subroutines
10
11 =end description
12
eda6db14 » moritz
2009-08-02 [t/spec] move smartlinks from POD to ordinary comments
13 # L<S06/"Parameter traits">
14
4ae127ae » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
15 my $foo=1;
16
17 # note: many of these errors can be detected at compile time, so need
db93e894 » particle
2008-11-08 [t/spec] unmark some passing rakudo tests due to container/value refa…
18 # eval_dies_ok instead of dies_ok
d4308c84 » moritz
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 » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
23 eval_dies_ok '
97fdbb2e » moritz
2008-11-06 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
24 my $tmp = 1;
4ae127ae » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
25 sub mods_param ($x) { $x++; }
97fdbb2e » moritz
2008-11-06 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
26 mods_param($tmp)
4ae127ae » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
27 ',
28 'can\'t modify parameter, constant by default';
db93e894 » particle
2008-11-08 [t/spec] unmark some passing rakudo tests due to container/value refa…
29
d4308c84 » moritz
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 » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
36
37 # is readonly
db93e894 » particle
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 » moritz
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 » moritz
2008-09-03 [t/spec] fudged S06-traits/misc.t for rakudo
43 #?rakudo todo "'is rw' can't modify constants"
4ae127ae » moritz
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 » moritz
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 » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
63 # is ref
1b911a17 » moritz
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 » kyle
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 » moritz
2008-09-03 [t/spec] fudged S06-traits/misc.t for rakudo
73 }
4ae127ae » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
74
3b8f4d2d » jnthn
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 » moritz
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
5547d3f2 » kyle
2009-07-09 [t/spec] Test for RT #60966
92 # To do - check that is context actually works
26e3caa8 » moritz
2008-09-29 [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
93
5547d3f2 » kyle
2009-07-09 [t/spec] Test for RT #60966
94 #?rakudo todo 'RT 60966'
95 {
96 eval 'sub oh_noes( $gack is nonesuch ) { }';
97
98 ok $! ~~ Exception, "Can't use an unknown trait";
99 ok "$!" ~~ /trait/, 'error message mentions trait';
100 ok "$!" ~~ /nonesuch/, 'error message mentions the name of the trait';
101 }
26e3caa8 » moritz
2008-09-29 [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
102
4ae127ae » moritz
2008-09-03 [t] moved sub_parameter_traits to spec/
103 # vim: ft=perl6
Something went wrong with that request. Please try again.