Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 143 lines (122 sloc) 5.054 kb
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
1 use v6;
2 use Test;
7a77ff86 » pmichaud
2012-07-07 [S06]: Add tests for capture parameter introspection of .positional, …
3 plan 52;
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
4
5 # L<S06/Signature Introspection>
6
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
7 sub j(*@i) {
29b04a98 » moritz
2010-09-23 fix tests for Bool stringification
8 @i.map({ $_ ?? '1' !! '0' }).join(' ');
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
9 }
10
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
11 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
12 sub a($x, Int $y?, :$z) { }; #OK not used
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
13 ok &a.signature.params ~~ Positional, '.params does Positional';
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
14 my @l = &a.signature.params;
31dd22f8 » jnthn
2012-01-12 Update signature introspection test for current spec, remove all but …
15 ok ?(all(@l >>~~>> Parameter)), 'And all items are Parameters';
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
16 is +@l, 3, 'we have three of them';
17 is ~(@l>>.name), '$x $y $z', 'can get the names with sigils';
18 ok @l[0].type === Any, 'Could get first type';
19 ok @l[1].type === Int, 'Could get second type';
20
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
21 is j(@l>>.readonly), '1 1 1', 'they are all read-only';
22 is j(@l>>.rw), '0 0 0', '... none rw';
23 is j(@l>>.copy), '0 0 0', '... none copy';
31dd22f8 » jnthn
2012-01-12 Update signature introspection test for current spec, remove all but …
24 is j(@l>>.parcel), '0 0 0', '... none ref';
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
25 is j(@l>>.slurpy), '0 0 0', '... none slurpy';
26 is j(@l>>.optional), '0 1 1', '... some optional';
27 is j(@l>>.invocant), '0 0 0', '... none invocant';
28 is j(@l>>.named), '0 0 1', '... one named';
be253a0b » moritz
2009-10-09 [t/spec] more signature introspection
29 }
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
30
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
31 #?niecza skip "Unhandled trait rwt"
be253a0b » moritz
2009-10-09 [t/spec] more signature introspection
32 {
31dd22f8 » jnthn
2012-01-12 Update signature introspection test for current spec, remove all but …
33 sub b(:x($a)! is rw, :$y is parcel, :$z is copy) { }; #OK not used
be253a0b » moritz
2009-10-09 [t/spec] more signature introspection
34 my @l = &b.signature.params;
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
35 is j(@l>>.readonly), '0 0 0', '(second sig) none are all read-only';
36 is j(@l>>.rw), '1 0 0', '... one rw';
31dd22f8 » jnthn
2012-01-12 Update signature introspection test for current spec, remove all but …
37 is j(@l>>.parcel), '0 1 0', '... one parcel';
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
38 is j(@l>>.copy), '0 0 1', '... one copy';
39 is j(@l>>.slurpy), '0 0 0', '... none slurpy';
40 is j(@l>>.optional), '0 1 1', '... some optional';
41 is j(@l>>.invocant), '0 0 0', '... none invocant';
42 is j(@l>>.named), '1 1 1', '... one named';
be253a0b » moritz
2009-10-09 [t/spec] more signature introspection
43
44 is ~@l[0].named_names, 'x', 'named_names work';
45 is ~@l[0].name, '$a', '.name works for renamed params';
46 }
47
48 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
49 sub d(*@pos, *%named) { }; #OK not used
be253a0b » moritz
2009-10-09 [t/spec] more signature introspection
50 my @l = &d.signature.params;
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
51 #?niecza todo
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
52 is j(@l>>.named), '0 1', '.named for slurpies';
53 is j(@l>>.slurpy), '1 1', '.slurpy';
be253a0b » moritz
2009-10-09 [t/spec] more signature introspection
54 is ~(@l>>.name), '@pos %named', '.name for slurpies';
55 }
56
57
58 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
59 sub d(:x(:y(:z($a)))) { }; #OK not used
be253a0b » moritz
2009-10-09 [t/spec] more signature introspection
60 is ~&d.signature.params.[0].named_names.sort, 'x y z', 'multi named_names';
61 is ~&d.signature.params.[0].name, '$a', '... and .name still works';
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
62 }
63
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
64 #?niecza skip "Parameter separator ; NYI"
9305b953 » moritz
2009-10-09 [t/spec] failing tests for .default
65 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
66 sub e($x = 3; $y = { 2 + $x }) { }; #OK not used
9305b953 » moritz
2009-10-09 [t/spec] failing tests for .default
67 my @l = &e.signature.params>>.default;
31dd22f8 » jnthn
2012-01-12 Update signature introspection test for current spec, remove all but …
68 ok ?( all(@l >>~~>> Code) ), '.default returns closure';
7aebfb03 » moritz
2010-03-17 [t/spec] explicitly coerce values to bool before comparison
69 is @l[0].(), 3, 'first closure works';
31dd22f8 » jnthn
2012-01-12 Update signature introspection test for current spec, remove all but …
70 # XXX The following test is very, very dubious...
27c639d7 » jnthn
2009-10-10 [t/spec] A little unfudging of some now-passing tests.
71 #?rakudo skip 'default closure when no call made fails lexical lookup with NPMCA'
9305b953 » moritz
2009-10-09 [t/spec] failing tests for .default
72 is @l[1].().(), 5, 'closure as default value captured outer default value';
73 }
74
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
75 #?niecza skip "Unable to resolve method constraints in class Parameter"
19d86b01 » moritz
2009-10-10 [t/spec] .constraints tests
76 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
77 sub f(Int $x where { $_ % 2 == 0 }) { }; #OK not used
19d86b01 » moritz
2009-10-10 [t/spec] .constraints tests
78 my $p = &f.signature.params[0];
79 ok 4 ~~ $p.constraints, '.constraints (+)';
80 ok 5 !~~ $p.constraints, '.constraints (-)';
81 ok 5 ~~ (-> $x { }).signature.params[0].constraints,
82 '.constraints on unconstraint param should still smartmatch truely';
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
83 sub g(Any $x where Int) { }; #OK not used
ef39b846 » moritz
2009-10-10 [t/spec] non-closure constraints
84 ok 3 ~~ &g.signature.params[0].constraints,
85 'smartmach against non-closure constraint (+)';
86 ok !(3.5 ~~ &g.signature.params[0].constraints),
87 'smartmach against non-closure constraint (-)';
19d86b01 » moritz
2009-10-10 [t/spec] .constraints tests
88 }
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
89
9ba17337 » moritz
2010-05-31 [t/spec] Test for RT #70720, :(3) has the 3 available to introspection
90 # RT #70720
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
91 #?niecza skip "Action method fakesignature not yet implemented"
9ba17337 » moritz
2010-05-31 [t/spec] Test for RT #70720, :(3) has the 3 available to introspection
92 {
93 is :(3).params[0].constraints, 3, ':(3) contains the 3';
94 ok :(3).params[0].type === Int, ':(3) has a parameter of type Int';
95 }
96
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
97 #?niecza skip "GLOBAL::T does not name any package"
3d2a4fce » moritz
2009-10-10 [t/spec] type_captures
98 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
99 sub h(::T $x, T $y) { }; #OK not used
3d2a4fce » moritz
2009-10-10 [t/spec] type_captures
100 my @l = &h.signature.params;
101 is @l[0].type_captures, 'T', '.type_captures';
102 lives_ok { @l[1].type }, "can access a type_capture'd type";
103 }
104
f1645a1d » moritz
2010-04-05 [t/spec] test that subsignatures appear in the output of Signature.perl
105 {
8dc7d4b8 » lwall
2010-07-15 [t/spec] mark various tests that intentionally declare things that ar…
106 sub i(%h($a, $b)) { }; #OK not used
f1645a1d » moritz
2010-04-05 [t/spec] test that subsignatures appear in the output of Signature.perl
107 my $s = &i.signature.perl;
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
108 #?niecza 2 todo
f1645a1d » moritz
2010-04-05 [t/spec] test that subsignatures appear in the output of Signature.perl
109 ok $s ~~ /'$a' >> /, '.perl on a nested signature contains variables of the subsignature (1)';
110 ok $s ~~ /'$b' >> /, '.perl on a nested signature contains variables of the subsignature (2)';
111
112 }
113
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
114 #?niecza skip "Action method fakesignature not yet implemented"
e70afa03 » moritz
2010-06-28 [t/spec] tests for RT #76116, parcel and capture binding in signature…
115 {
116 my $x;
e6ba01a5 » TimToady
2012-09-03 remove sigils from | and \
117 ok :(|x).params[0].capture, 'prefix | makes .capture true';
118 ok :(|x).perl ~~ / '|' /, 'prefix | appears in .perl output';
e70afa03 » moritz
2010-06-28 [t/spec] tests for RT #76116, parcel and capture binding in signature…
119
e6ba01a5 » TimToady
2012-09-03 remove sigils from | and \
120 ok :(\x).params[0].parcel, 'prefix \\ makes .parcel true';
121 ok :(\x).perl ~~ / '\\' /, 'prefix \\ appears in .perl output';
e70afa03 » moritz
2010-06-28 [t/spec] tests for RT #76116, parcel and capture binding in signature…
122 }
123
d63ef9c3 » moritz
2010-04-17 [t/spec] test for RT #69492
124 # RT #69492
59e35188 » colomon
2012-01-29 Heavy fudging for niecza.
125 #?niecza skip "Abbreviated named parameter must have a name"
d63ef9c3 » moritz
2010-04-17 [t/spec] test for RT #69492
126 {
127 sub foo(:$) {};
128 ok &foo.signature.perl ~~ / ':' /, '.perl of a signature with anonymous named parameter';
129 }
130
7a77ff86 » pmichaud
2012-07-07 [S06]: Add tests for capture parameter introspection of .positional, …
131 # Capture param introspection
132 {
e6ba01a5 » TimToady
2012-09-03 remove sigils from | and \
133 sub xyz(|c) {};
134 is &xyz.signature.params[0].name, 'c' , '.name of |c is "c"';
dc9f15fa » colomon
2012-07-16 Lots of niecza fudges.
135 #?niecza todo "Does this test make sense?"
7a77ff86 » pmichaud
2012-07-07 [S06]: Add tests for capture parameter introspection of .positional, …
136 is &xyz.signature.params[0].positional, False, '.positional on Capture param is False';
137 is &xyz.signature.params[0].capture, True , '.capture on Capture param is True';
138 is &xyz.signature.params[0].named, False, '.named on Capture param is True';
139 }
140
e76dd4c7 » moritz
2010-12-31 s/done_testing/done/ as per recent S24 changes
141 done;
94a97564 » moritz
2009-10-09 [t/spec] first real signature introspection tests
142
143 # vim: ft=perl6
Something went wrong with that request. Please try again.