Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 206 lines (172 sloc) 6.358 kb
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
1 use v6;
2 use Test;
e122112 [t/spec] fix reduce-metaop.t, moritz--
moritz authored
3
f80ef63 [t/spec] Tests for RT #65164
kyle authored
4 plan 71;
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
5
6 =begin pod
7
8 =head1 DESCRIPTION
9
10 This test tests the C<[...]> reduce metaoperator.
11
12 Reference:
13 L<"http://groups.google.de/group/perl.perl6.language/msg/bd9eb275d5da2eda">
14
15 =end pod
16
17 # L<S03/"Reduction operators">
18
19 # [...] reduce metaoperator
20 {
21 my @array = <5 -3 7 0 1 -9>;
22 my $sum = 5 + -3 + 7 + 0 + 1 + -9; # laziness :)
23
24 is(([+] @array), $sum, "[+] works");
25 is(([*] 1,2,3), (1*2*3), "[*] works");
26 is(([-] 1,2,3), (1-2-3), "[-] works");
27 is(([/] 12,4,3), (12/4/3), "[/] works");
28 is(([**] 2,2,3), (2**2**3), "[**] works");
5d1999e [t/spec] a test for [%] (meta reduce modulo)
moritz authored
29 is(([%] 13,7,4), (13%7%4), "[%] works");
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
30
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
31 #?rakudo 2 skip '[\...] meta ops'
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
32 is((~ [\+] @array), "5 2 9 9 10 1", "[\\+] works");
33 is((~ [\-] 1, 2, 3), "1 -1 -4", "[\\-] works");
34 }
35
36 {
37 is ([~] <a b c d>), "abcd", "[~] works";
38
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
39 #?rakudo skip '[\...] meta ops'
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
40 is (~ [\~] <a b c d>), "a ab abc abcd", "[\\~] works";
41 }
42
43 {
44 ok ( [<] 1, 2, 3, 4), "[<] works (1)";
45 ok (not [<] 1, 3, 2, 4), "[<] works (2)";
46 ok ( [>] 4, 3, 2, 1), "[>] works (1)";
47 ok (not [>] 4, 2, 3, 1), "[>] works (2)";
48 ok ( [==] 4, 4, 4), "[==] works (1)";
49 ok (not [==] 4, 5, 4), "[==] works (2)";
50 ok ( [!=] 4, 5, 6), "[!=] works (1)";
51 ok (not [!=] 4, 4, 4), "[!=] works (2)";
e7dbb23 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
colomon authored
52 }
d1ccd8b [t/spec] tests for === and =:= and their negated forms inside meta ops
moritz authored
53
e7dbb23 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
colomon authored
54 {
e75736f [t/spec] tests for [eq], [ne]
moritz authored
55 ok (! [eq] <a a b a>), '[eq] basic sanity (positive)';
56 ok ( [eq] <a a a a>), '[eq] basic sanity (negative)';
57 ok ( [ne] <a b c a>), '[ne] basic sanity (positive)';
58 ok (! [ne] <a a b c>), '[ne] basic sanity (negative)';
59 ok ( [lt] <a b c e>), '[lt] basic sanity (positive)';
60 ok (! [lt] <a a c e>), '[lt] basic sanity (negative)';
e7dbb23 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
colomon authored
61 }
e75736f [t/spec] tests for [eq], [ne]
moritz authored
62
e7dbb23 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
colomon authored
63 #?rakudo skip "=:= NYI"
64 {
d1ccd8b [t/spec] tests for === and =:= and their negated forms inside meta ops
moritz authored
65 my ($x, $y);
66 ok ( [=:=] $x, $x, $x), '[=:=] basic sanity 1';
67 ok (not [=:=] $x, $y, $x), '[=:=] basic sanity 2';
68 ok ( [!=:=] $x, $y, $x), '[!=:=] basic sanity (positive)';
69 ok (not [!=:=] $y, $y, $x), '[!=:=] basic sanity (negative)';
70 $y := $x;
71 ok ( [=:=] $y, $x, $y), '[=:=] after binding';
e7dbb23 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
colomon authored
72 }
d1ccd8b [t/spec] tests for === and =:= and their negated forms inside meta ops
moritz authored
73
e7dbb23 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
colomon authored
74 {
d1ccd8b [t/spec] tests for === and =:= and their negated forms inside meta ops
moritz authored
75 my $a = [1, 2];
76 my $b = [1, 2];
77
78 ok ( [===] 1, 1, 1, 1), '[===] with literals';
79 ok ( [===] $a, $a, $a), '[===] with vars (positive)';
80 ok (not [===] $a, $a, [1, 2]), '[===] with vars (negative)';
81 ok ( [!===] $a, $b, $a), '[!===] basic sanity (positive)';
82 ok (not [!===] $a, $b, $b), '[!===] basic sanity (negative)';
434eb4e [t/spec] Unfudge tests for reduction meta-operator with chaining comparr...
jnthn authored
83 }
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
84
434eb4e [t/spec] Unfudge tests for reduction meta-operator with chaining comparr...
jnthn authored
85 #?rakudo skip '[\...] meta ops'
86 {
5cb1e9f [t/spec] Fix triangle form of reduce metaop tests.
bacek authored
87 is (~ [\<] 1, 2, 3, 4), "1 1 1 1", "[\\<] works (1)";
2126a8d [t/spec] Revert previous commit for reduce metaops.
bacek authored
88 is (~ [\<] 1, 3, 2, 4), "1 1 0 0", "[\\<] works (2)";
5cb1e9f [t/spec] Fix triangle form of reduce metaop tests.
bacek authored
89 is (~ [\>] 4, 3, 2, 1), "1 1 1 1", "[\\>] works (1)";
6ac9615 [t/spec] Update reduce-metaop to current spec.
bacek authored
90 is (~ [\>] 4, 2, 3, 1), "1 1 0 0", "[\\>] works (2)";
5cb1e9f [t/spec] Fix triangle form of reduce metaop tests.
bacek authored
91 is (~ [\==] 4, 4, 4), "1 1 1", "[\\==] works (1)";
92 is (~ [\==] 4, 5, 4), "1 0 0", "[\\==] works (2)";
6ac9615 [t/spec] Update reduce-metaop to current spec.
bacek authored
93 is (~ [\!=] 4, 5, 6), "1 1 1", "[\\!=] works (1)";
94 is (~ [\!=] 4, 5, 5), "1 1 0", "[\\!=] works (2)";
5cb1e9f [t/spec] Fix triangle form of reduce metaop tests.
bacek authored
95 is (~ [\**] 1, 2, 3), "3 8 1", "[\\**] (right assoc) works (1)";
96 is (~ [\**] 3, 2, 0), "0 1 3", "[\\**] (right assoc) works (2)";
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
97 }
98
99 {
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
100 my @array = (Mu, Mu, 3, Mu, 5);
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
101 is ([//] @array), 3, "[//] works";
4acefb9 [t/spec] unfudge [//] and [||] tests for rakudo
moritz authored
102 #?rakudo skip '[orelse]'
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
103 is ([orelse] @array), 3, "[orelse] works";
104 }
105
106 {
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
107 my @array = (Mu, Mu, 0, 3, Mu, 5);
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
108 is ([||] @array), 3, "[||] works";
109 is ([or] @array), 3, "[or] works";
110
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
111 # Mu as well as [//] should work too, but testing it like
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
112 # this would presumably emit warnings when we have them.
4acefb9 [t/spec] unfudge [//] and [||] tests for rakudo
moritz authored
113 #?rakudo skip '[\||]'
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
114 is (~ [\||] 0, 0, 3, 4, 5), "0 0 3 3 3", "[\\||] works";
115 }
116
bc058f2 [STD] improve parsing of reduceops
lwall authored
117 # not currently legal without an infix subscript operator
118 # {
119 # my $hash = {a => {b => {c => {d => 42, e => 23}}}};
120 # is try { [.{}] $hash, <a b c d> }, 42, '[.{}] works';
121 # }
122 #
123 # {
124 # my $hash = {a => {b => 42}};
125 # is ([.{}] $hash, <a b>), 42, '[.{}] works two levels deep';
126 # }
127 #
128 # {
129 # my $arr = [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]];
130 # is ([.[]] $arr, 1, 0, 2), 9, '[.[]] works';
131 # }
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
132
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
133 #?rakudo skip '[=>]'
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
134 {
135 # 18:45 < autrijus> hm, I found a way to easily do linked list consing in Perl6
136 # 18:45 < autrijus> [=>] 1..10;
137 my $list = [=>] 1,2,3;
ed68273 [t/spec] remove usage of try as a function
moritz authored
138 is $list.key, 1, "[=>] works (1)";
139 is (try {$list.value.key}), 2, "[=>] works (2)";
140 is (try {$list.value.value}), 3, "[=>] works (3)";
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
141 }
142
e7dbb23 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
colomon authored
143 #?rakudo todo '[,] issues'
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
144 {
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
145 my @array = <5 -3 7 0 1 -9>;
146 # according to http://irclog.perlgeek.de/perl6/2008-09-10#i_560910
147 # [,] returns a scalar (holding an Array)
148 my $count = 0;
149 $count++ for [,] @array;
150 is $count, 1, '[,] returns a single Array';
612a8a8 [t/spec] a few small improvements
moritz authored
151 isa_ok ([,] @array), Array, '[,] returns something of type Array';
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
152 }
153
154 # Following two tests taken verbatim from former t/operators/reduce.t
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
155 #?rakudo 2 skip '>>+<<'
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
156 lives_ok({my @foo = [1..3] >>+<< [1..3] >>+<< [1..3]},'Sanity Check');
157 lives_ok({my @foo = [>>+<<] ([1..3],[1..3],[1..3])},'Parse [>>+<<]');
158
159 # Check that user defined infix ops work with [...], too.
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
160 #?pugs todo 'bug'
8de8af6 [t/spec] partially fudge reduce.t for rakudo
moritz authored
161 #?rakudo skip 'reduce of user defined op'
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
162 {
163 sub infix:<more_than_plus>(Int $a, Int $b) { $a + $b + 1 }
d1ccd8b [t/spec] tests for === and =:= and their negated forms inside meta ops
moritz authored
164 is (try { [more_than_plus] 1, 2, 3 }), 8, "[...] reduce metaop works on user defined ops";
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
165 }
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
166
f148336 [STD vs t] user-defined prefix, infix, and postfix ops now derive new la...
lwall authored
167 # {
168 # my $arr = [ 42, [ 23 ] ];
169 # $arr[1][1] = $arr;
170 #
171 # is try { [.[]] $arr, 1, 1, 1, 1, 1, 0 }, 23, '[.[]] works with infinite data structures';
172 # }
173 #
174 # {
175 # my $hash = {a => {b => 42}};
176 # $hash<a><c> = $hash;
177 #
178 # is try { [.{}] $hash, <a c a c a b> }, 42, '[.{}] works with infinite data structures';
179 # }
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
180
181 # L<S03/"Reduction operators"/"Among the builtin operators, [+]() returns 0 and [*]() returns 1">
182
21768a7 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
moritz authored
183 is( ([*]()), 1, "[*]() returns 1");
184 is( ([+]()), 0, "[+]() returns 0");
932a1bc [gsoc_spectest] reorganization of reduce tests
Auzon authored
185
f80ef63 [t/spec] Tests for RT #65164
kyle authored
186 # RT #65164 (TODO: implement [^^])
187 #?rakudo skip 'implement [^^]'
188 {
189 is [^^](0, 42), 42, '[^^] works (one of two true)';
190 is [^^](42, 0), 42, '[^^] works (one of two true)';
191 ok ! [^^](1, 42), '[^^] works (two true)';
192 ok ! [^^](0, 0), '[^^] works (two false)';
193
194 ok ! [^^](0, 0, 0), '[^^] works (three false)';
195 ok ! [^^](5, 9, 17), '[^^] works (three true)';
196
197 is [^^](5, 9, 0), (5 ^^ 9 ^^ 0), '[^^] mix 1';
198 is [^^](5, 0, 17), (5 ^^ 0 ^^ 17), '[^^] mix 2';
199 is [^^](0, 9, 17), (0 ^^ 9 ^^ 17), '[^^] mix 3';
200 is [^^](5, 0, 0), (5 ^^ 0 ^^ 0), '[^^] mix 4';
201 is [^^](0, 9, 0), (0 ^^ 9 ^^ 0), '[^^] mix 5';
202 is [^^](0, 0, 17), (0 ^^ 0 ^^ 17), '[^^] mix 6';
203 }
204
4acefb9 [t/spec] unfudge [//] and [||] tests for rakudo
moritz authored
205 # vim: ft=perl6
Something went wrong with that request. Please try again.