Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 465 lines (374 sloc) 13.859 kb
42ef71a [t] move operator_overloading.t to spec/
moritz authored
1 use v6;
2
3 use Test;
4
d84f6bc Christian Bartolomäus Add test for RT #86906
usev6 authored
5 plan 74;
42ef71a [t] move operator_overloading.t to spec/
moritz authored
6
7 =begin pod
8
9 Testing operator overloading subroutines
10
11 =end pod
12
eda6db1 [t/spec] move smartlinks from POD to ordinary comments
moritz authored
13 # L<S06/"Operator overloading">
14
42ef71a [t] move operator_overloading.t to spec/
moritz authored
15 # This set of tests is very basic for now.
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
16 # TODO: all variants of overloading syntax (see spec "So any of these")
42ef71a [t] move operator_overloading.t to spec/
moritz authored
17
18 {
19 sub prefix:<X> ($thing) { return "ROUGHLY$thing"; };
20
21 is(X "fish", "ROUGHLYfish",
22 'prefix operator overloading for new operator');
23 }
24
25 {
26 sub prefix:<±> ($thing) { return "AROUND$thing"; };
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
27 is ± "fish", "AROUNDfish", 'prefix operator overloading for new operator (unicode, latin-1 range)';
42ef71a [t] move operator_overloading.t to spec/
moritz authored
28 sub prefix:<(+-)> ($thing) { return "ABOUT$thing"; };
04daf2d Tobias Leich eval => EVAL in S05, S06 and S09
FROGGS authored
29 is EVAL(q[ (+-) "fish" ]), "ABOUTfish", 'prefix operator overloading for new operator (nasty)';
42ef71a [t] move operator_overloading.t to spec/
moritz authored
30 }
31
32 {
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
33 sub prefix:<∔> ($thing) { return "AROUND$thing"; };
34 is ∔ "fish", "AROUNDfish", 'prefix operator overloading for new operator (unicode, U+2214 DOT PLUS)';
35 }
36
ad2abf4 Will Coleda standardize on NYI for things not yet implemented
coke authored
37 #?rakudo skip 'prefix:[] form NYI'
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
38 {
c270277 [sub.t] switch to foofix:['op'] form from :() which is reserved for sigs...
lwall authored
39 sub prefix:['Z'] ($thing) { return "ROUGHLY$thing"; };
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
40
41 is(Z "fish", "ROUGHLYfish",
42 'prefix operator overloading for new operator Z');
43 }
44
ad2abf4 Will Coleda standardize on NYI for things not yet implemented
coke authored
45 #?rakudo skip 'prefix:[] form NYI'
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
46 {
c270277 [sub.t] switch to foofix:['op'] form from :() which is reserved for sigs...
lwall authored
47 sub prefix:["∓"] ($thing) { return "AROUND$thing"; };
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
48 is ∓ "fish", "AROUNDfish", 'prefix operator overloading for new operator (unicode, U+2213 MINUS-OR-PLUS SIGN)';
49 }
50
ad2abf4 Will Coleda standardize on NYI for things not yet implemented
coke authored
51 #?rakudo skip 'prefix:[] form NYI'
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
52 {
c270277 [sub.t] switch to foofix:['op'] form from :() which is reserved for sigs...
lwall authored
53 sub prefix:["\x[2213]"] ($thing) { return "AROUND$thing"; };
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
54 is ∓ "fish", "AROUNDfish", 'prefix operator overloading for new operator (unicode, \x[2213] MINUS-OR-PLUS SIGN)';
55 }
56
ad2abf4 Will Coleda standardize on NYI for things not yet implemented
coke authored
57 #?rakudo skip 'prefix:[] form NYI'
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
58 {
c270277 [sub.t] switch to foofix:['op'] form from :() which is reserved for sigs...
lwall authored
59 sub prefix:["\c[MINUS-OR-PLUS SIGN]"] ($thing) { return "AROUND$thing"; };
e6734b4 [t/spec] added test for operator overloading; and TODO
wollmers authored
60 is ∓ "fish", "AROUNDfish", 'prefix operator overloading for new operator (unicode, \c[MINUS-OR-PLUS SIGN])';
61 }
62
63 {
42ef71a [t] move operator_overloading.t to spec/
moritz authored
64 my sub prefix:<->($thing) { return "CROSS$thing"; };
65 is(-"fish", "CROSSfish",
18a47ab Christian Bartolomäus Add test for RT #115724
usev6 authored
66 'prefix operator overloading for existing operator (but only lexically so we don\'t mess up runtime internals (needed at least for PIL2JS, probably for PIL-Run, too)');
42ef71a [t] move operator_overloading.t to spec/
moritz authored
67 }
68
69 {
70 sub infix:<×> ($a, $b) { $a * $b }
71 is(5 × 3, 15, "infix Unicode operator");
72 }
73
74 {
75 sub infix:<C> ($text, $owner) { return "$text copyright $owner"; };
76 is "romeo & juliet" C "Shakespeare", "romeo & juliet copyright Shakespeare",
18a47ab Christian Bartolomäus Add test for RT #115724
usev6 authored
77 'infix operator overloading for new operator';
42ef71a [t] move operator_overloading.t to spec/
moritz authored
78 }
79
80 {
81 sub infix:<©> ($text, $owner) { return "$text Copyright $owner"; };
82 is "romeo & juliet" © "Shakespeare", "romeo & juliet Copyright Shakespeare",
18a47ab Christian Bartolomäus Add test for RT #115724
usev6 authored
83 'infix operator overloading for new operator (unicode)';
42ef71a [t] move operator_overloading.t to spec/
moritz authored
84 }
85
86 {
87 sub infix:<(C)> ($text, $owner) { return "$text CopyRight $owner"; };
04daf2d Tobias Leich eval => EVAL in S05, S06 and S09
FROGGS authored
88 is EVAL(q[ "romeo & juliet" (C) "Shakespeare" ]), "romeo & juliet CopyRight Shakespeare",
18a47ab Christian Bartolomäus Add test for RT #115724
usev6 authored
89 'infix operator overloading for new operator (nasty)';
42ef71a [t] move operator_overloading.t to spec/
moritz authored
90 }
91
92 {
89f0409 Larry Wall warning suppression, mostly "not used"
TimToady authored
93 sub infix:«_<_ »($one, $two) { return 42 } #OK not used
42ef71a [t] move operator_overloading.t to spec/
moritz authored
94 is 3 _<_ 5, 42, "frenchquoted infix sub";
95 }
96
d03703e [t/spec] prevent syntax hilighter from going too mad
moritz authored
97 # unfreak perl6.vim: >>
98
42ef71a [t] move operator_overloading.t to spec/
moritz authored
99 {
100 sub postfix:<W> ($wobble) { return "ANDANDAND$wobble"; };
101
77a9ace add test for RT68662
frew authored
102 is("boop"W, "ANDANDANDboop",
42ef71a [t] move operator_overloading.t to spec/
moritz authored
103 'postfix operator overloading for new operator');
104 }
105
106 {
107 sub postfix:<&&&&&> ($wobble) { return "ANDANDANDANDAND$wobble"; };
108 is("boop"&&&&&, "ANDANDANDANDANDboop",
109 "postfix operator overloading for new operator (weird)");
110 }
111
3044290 [t/spec] fudge operator-overload/subs.t for rakudo
moritz authored
112 #?rakudo skip 'macros'
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
113 #?niecza skip 'Unhandled exception: Malformed block at (eval) line 1'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
114 {
115 my $var = 0;
04daf2d Tobias Leich eval => EVAL in S05, S06 and S09
FROGGS authored
116 ok(EVAL('macro circumfix:["<!--","-->"] ($text) is parsed / .*? / { "" }; <!-- $var = 1; -->; $var == 0;'), 'circumfix macro {"",""}');
117 ok(EVAL('macro circumfix:«<!-- -->» ($text) is parsed / .*? / { "" }; <!-- $var = 1; -->; $var == 0;'), 'circumfix macro «»');
42ef71a [t] move operator_overloading.t to spec/
moritz authored
118 }
119
120 # demonstrate sum prefix
121
122 {
123 my sub prefix:<Σ> (@x) { [+] @x }
124 is(Σ [1..10], 55, "sum prefix operator");
125 }
126
127 # check that the correct overloaded method is called
128 {
129 multi postfix:<!> ($x) { [*] 1..$x }
130 multi postfix:<!> (Str $x) { return($x.uc ~ "!!!") }
131
132 is(10!, 3628800, "factorial postfix operator");
a1e589c Will Coleda *eyeroll*
coke authored
133 is("bumbershoot"!, "BUMBERSHOOT!!!", "correct overloaded method called");
42ef71a [t] move operator_overloading.t to spec/
moritz authored
134 }
135
136 # Overloading by setting the appropriate code variable
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
137 #?rakudo skip "cannot bind with this LHS"
42ef71a [t] move operator_overloading.t to spec/
moritz authored
138 {
139 my &infix:<plus>;
140 BEGIN {
141 &infix:<plus> := { $^a + $^b };
142 }
143
144 is 3 plus 5, 8, 'overloading an operator using "my &infix:<...>" worked';
145 }
146
147 # Overloading by setting the appropriate code variable using symbolic
148 # dereferentiation
6fbd78a [t/spec] fudge sub.t for rakudo
moritz authored
149 #?rakudo skip '&::'
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
150 #?niecza skip 'Cannot use hash access on an object of type Array'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
151 {
152 my &infix:<times>;
153 BEGIN {
c270277 [sub.t] switch to foofix:['op'] form from :() which is reserved for sigs...
lwall authored
154 &::["infix:<times>"] := { $^a * $^b };
42ef71a [t] move operator_overloading.t to spec/
moritz authored
155 }
156
157 is 3 times 5, 15, 'operator overloading using symbolic dereferentiation';
158 }
159
160 # Accessing an operator using its subroutine name
161 {
162 is &infix:<+>(2, 3), 5, "accessing a builtin operator using its subroutine name";
163
164 my &infix:<z> := { $^a + $^b };
165 is &infix:<z>(2, 3), 5, "accessing a userdefined operator using its subroutine name";
166
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
167 #?rakudo skip 'undeclared name'
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
168 #?niecza skip 'Undeclared routine'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
169 is ~(&infix:<»+«>([1,2,3],[4,5,6])), "5 7 9", "accessing a hyperoperator using its subroutine name";
170 }
171
172 # Overriding infix:<;>
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
173 #?rakudo todo 'infix:<;>'
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
174 #?niecza todo
42ef71a [t] move operator_overloading.t to spec/
moritz authored
175 {
176 my proto infix:<;> ($a, $b) { $a + $b }
e1e9543 Larry Wall lolly-proof uses of (;)
TimToady authored
177 is $(3 ; 2), 5 # XXX correct?
42ef71a [t] move operator_overloading.t to spec/
moritz authored
178 }
179
180 # [NOTE]
181 # pmichaud ruled that prefix:<;> and postfix:<;> shouldn't be defined by
182 # the synopses:
183 # http://colabti.de/irclogger/irclogger_log/perl6?date=2006-07-29,Sat&sel=189#l299
184 # so we won't test them here.
185
186 # Overriding prefix:<if>
187 # L<S04/"Statement parsing" /"since prefix:<if> would hide statement_modifier:<if>">
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
188 #?rakudo skip 'missing block, apparently "if" not an op'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
189 {
190 my proto prefix:<if> ($a) { $a*2 }
191 is (if+5), 10;
192 }
193
194 # [NOTE]
195 # pmichaud ruled that infix<if> is incorrect:
196 # http://colabti.de/irclogger/irclogger_log/perl6?date=2006-07-29,Sat&sel=183#l292
197 # so we won't test it here either.
198
199 # great. Now, what about those silent auto-conversion operators a la:
200 # multi sub prefix:<+> (Str $x) returns Num { ... }
201 # ?
202
203 # I mean, + is all well and good for number classes. But what about
204 # defining other conversions that may happen?
205
206 # here is one that co-erces a MyClass into a Str and a Num.
5c64ac0 Will Coleda niecza fudge
coke authored
207 #?niecza skip 'import NYI'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
208 {
209 class OtherClass {
210 has $.x is rw;
211 }
212
213 class MyClass {
214 method prefix:<~> is export { "hi" }
215 method prefix:<+> is export { 42 }
89f0409 Larry Wall warning suppression, mostly "not used"
TimToady authored
216 method infix:<as>($self: OtherClass $to) is export { #OK not used
42ef71a [t] move operator_overloading.t to spec/
moritz authored
217 my $obj = $to.new;
218 $obj.x = 23;
219 return $obj;
220 }
221 }
89f0409 Larry Wall warning suppression, mostly "not used"
TimToady authored
222 import MyClass; # should import that sub forms of the exports
42ef71a [t] move operator_overloading.t to spec/
moritz authored
223
224 my $obj;
225 lives_ok { $obj = MyClass.new }, "instantiation of a prefix:<...> and infix:<as> overloading class worked";
7e6e783 Solomon Foster Fix fudging for rakudo.
colomon authored
226 lives_ok { ~$obj }, "our object can be stringified";
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
227 is ~$obj, "hi", "our object was stringified correctly";
04daf2d Tobias Leich eval => EVAL in S05, S06 and S09
FROGGS authored
228 is EVAL('($obj as OtherClass).x'), 23, "our object was coerced correctly";
42ef71a [t] move operator_overloading.t to spec/
moritz authored
229 }
230
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
231 #?rakudo skip 'infix Z will never work; no lexical Z'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
232 {
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
233 my sub infix:<Z> ($a, $b) {
234 $a ** $b;
235 }
236 is (2 Z 1 Z 2), 4, "default Left-associative works.";
42ef71a [t] move operator_overloading.t to spec/
moritz authored
237 }
238
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
239 #?rakudo skip 'missing block, no lexical Z'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
240 {
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
241 my sub infix:<Z> is assoc('left') ($a, $b) {
242 $a ** $b;
243 }
42ef71a [t] move operator_overloading.t to spec/
moritz authored
244
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
245 is (2 Z 1 Z 2), 4, "Left-associative works.";
42ef71a [t] move operator_overloading.t to spec/
moritz authored
246 }
247
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
248 #?rakudo skip 'missing block, no lexical Z'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
249 {
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
250 my sub infix:<Z> is assoc('right') ($a, $b) {
251 $a ** $b;
252 }
42ef71a [t] move operator_overloading.t to spec/
moritz authored
253
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
254 is (2 Z 1 Z 2), 2, "Right-associative works.";
42ef71a [t] move operator_overloading.t to spec/
moritz authored
255 }
256
b1a65f0 lizmat Unfudges, skip -> todo and other clarifications in S06 testing
lizmat authored
257 #?rakudo skip 'missing block, no lexical Z'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
258 {
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
259 my sub infix:<Z> is assoc('chain') ($a, $b) {
260 $a eq $b;
261 }
42ef71a [t] move operator_overloading.t to spec/
moritz authored
262
263
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
264 is (1 Z 1 Z 1), Bool::True, "Chain-associative works.";
265 is (1 Z 1 Z 2), Bool::False, "Chain-associative works.";
42ef71a [t] move operator_overloading.t to spec/
moritz authored
266 }
267
6fbd78a [t/spec] fudge sub.t for rakudo
moritz authored
268 #?rakudo skip 'assoc("non")'
42ef71a [t] move operator_overloading.t to spec/
moritz authored
269 {
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
270 sub infix:<our_non_assoc_infix> is assoc('non') ($a, $b) {
271 $a ** $b;
272 }
273 is (2 our_non_assoc_infix 3), (2 ** 3), "Non-associative works for just tow operands.";
274 is ((2 our_non_assoc_infix 2) our_non_assoc_infix 3), (2 ** 2) ** 3, "Non-associative works when used with parens.";
275 eval_dies_ok '2 our_non_assoc_infix 3 our_non_assoc_infix 4', "Non-associative should not parsed when used chainly.";
42ef71a [t] move operator_overloading.t to spec/
moritz authored
276 }
6fbd78a [t/spec] fudge sub.t for rakudo
moritz authored
277
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
278 #?niecza skip "roles NYI"
2ace3e3 [t/spec] RT #66552, Null PMC Access on user defined infix:<==>
moritz authored
279 {
280 role A { has $.v }
281 multi sub infix:<==>(A $a, A $b) { $a.v == $b.v }
282 lives_ok { 3 == 3 or die() }, 'old == still works on integers (+)';
283 lives_ok { 3 == 4 and die() }, 'old == still works on integers (-)';
284 ok (A.new(v => 3) == A.new(v => 3)), 'infix:<==> on A objects works (+)';
285 ok !(A.new(v => 2) == A.new(v => 3)), 'infix:<==> on A objects works (-)';
286 }
287
a2ec137 [t/spec] circumfix custom operator
moritz authored
288 {
289 sub circumfix:<<` `>>(*@args) { @args.join('-') }
5d47ee2 Moritz Lenz test for custom Unicode circumfix brackets
moritz authored
290 is `3, 4, "f"`, '3-4-f', 'slurpy circumfix:<<...>> works';
0f3284c Jonathan Worthington Tests for spaces inside user-defined circumfixes.
jnthn authored
291 is ` 3, 4, "f" `, '3-4-f', 'slurpy circumfix:<<...>> works, allows spaces';
2edaa16 Larry Wall fudge circumfix:<<` `>> misparse for now
TimToady authored
292 }
a2ec137 [t/spec] circumfix custom operator
moritz authored
293
2edaa16 Larry Wall fudge circumfix:<<` `>> misparse for now
TimToady authored
294 {
5d47ee2 Moritz Lenz test for custom Unicode circumfix brackets
moritz authored
295 sub circumfix:<⌊ ⌋>($e) { $e.floor }
296 is ⌊pi⌋, 3, 'circumfix with non-Latin1 bracketing characters';
0f3284c Jonathan Worthington Tests for spaces inside user-defined circumfixes.
jnthn authored
297 is ⌊ pi ⌋, 3, 'circumfix with non-Latin1 bracketing characters, allows spaces';
a2ec137 [t/spec] circumfix custom operator
moritz authored
298 }
299
d84f6bc Christian Bartolomäus Add test for RT #86906
usev6 authored
300 # RT #86906
301 {
302 throws_like { EVAL q[ multi sub circumfix:<⌊⌋>($a) { return $a.floor; } ] },
303 X::Syntax::AddCategorial::MissingSeparator,
304 message => "Unable to identify both starter and stopper from ⌊⌋\nPerhaps you forgot to separate them with whitespace?",
305 'circumfix definition without whitespace between starter and stopper fails with X::Syntax::AddCategorial::MissingSeparator';
306 }
307
77a9ace add test for RT68662
frew authored
308 {
3044290 [t/spec] fudge operator-overload/subs.t for rakudo
moritz authored
309 multi sub infix:<+=> (Int $a is rw, Int $b) { $a -= $b }
77a9ace add test for RT68662
frew authored
310 my $frew = 10;
311 $frew += 5;
24e0a35 adjust RT #68662 test
kyle authored
312 is $frew, 5, 'infix redefinition of += works';
77a9ace add test for RT68662
frew authored
313 }
314
15e6240 test that existing operators can be overloaded
moritz authored
315 {
316 class MMDTestType {
317 has $.a is rw;
318 method add(MMDTestType $b) { $.a ~ $b.a }
319 }
320
321 multi sub infix:<+>(MMDTestType $a, MMDTestType $b) { $a.add($b) };
322
323 my MMDTestType $a .= new(a=>'foo');
324 my MMDTestType $b .= new(a=>'bar');
325
326 is $a + $b, 'foobar', 'can overload exiting operators (here: infix:<+>)';
327 }
328
41fbc6a [t/spec] new operator multis should not interfere with existing ones
moritz authored
329 # test that multis with other arity don't interfere with existing ones
330 # used to be RT #65640
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
331 #?niecza skip 'No matching candidates to dispatch for &infix:<+>'
41fbc6a [t/spec] new operator multis should not interfere with existing ones
moritz authored
332 {
333 multi sub infix:<+>() { 42 };
334 ok 5 + 5 == 10, "New multis don't disturb old ones";
335 }
336
0c81aff [t/spec] get rid of S06-operator-overloading/method.t
moritz authored
337 # taken from S06-operator-overloading/method.t
338 {
339 class Bar {
340 has $.bar is rw;
662c6bd peschwa Remove a few unneccessary tests and correct useful ones.
peschwa authored
341 method Stringy() { ~self }; # the tests assume prefix:<~> gets called by qq[], but .Stringy gets actually called
0c81aff [t/spec] get rid of S06-operator-overloading/method.t
moritz authored
342 }
343
344 multi sub prefix:<~> (Bar $self) { return $self.bar }
345 multi sub infix:<+> (Bar $a, Bar $b) { return "$a $b" }
346
347 {
348 my $val;
662c6bd peschwa Remove a few unneccessary tests and correct useful ones.
peschwa authored
349 my $foo = Bar.new();
350 $foo.bar = 'software';
351 $val = "$foo";
0c81aff [t/spec] get rid of S06-operator-overloading/method.t
moritz authored
352 is($val, 'software', '... basic prefix operator overloading worked');
353
354 lives_ok {
355 my $foo = Bar.new();
356 $foo.bar = 'software';
357 $val = $foo + $foo;
358 }, '... class methods work for class';
7176c48 Will Coleda niecza (auto)unfudge
coke authored
359 #?niecza todo '... basic infix operator overloading worked'
0c81aff [t/spec] get rid of S06-operator-overloading/method.t
moritz authored
360 is($val, 'software software', '... basic infix operator overloading worked');
361 }
362
363 # Test that the object is correctly stringified when it is in an array.
364 # And test that »...« automagically work, too.
365 {
366 my $obj;
367 $obj = Bar.new;
368 $obj.bar = "pugs";
369
370 my @foo = ($obj, $obj, $obj);
371 my $res;
7176c48 Will Coleda niecza (auto)unfudge
coke authored
372 #?niecza todo "stringification didn't die"
662c6bd peschwa Remove a few unneccessary tests and correct useful ones.
peschwa authored
373 lives_ok { $res = ~<<@foo }, "stringification didn't die";
7176c48 Will Coleda niecza (auto)unfudge
coke authored
374 #?niecza todo "... worked in array stringification"
0c81aff [t/spec] get rid of S06-operator-overloading/method.t
moritz authored
375 is $res, "pugs pugs pugs", "stringification overloading worked in array stringification";
376 }
377
378
379 }
380
cc6ba56 [t/spec] Test for RT 65638
kyle authored
381 # RT #65638
382 {
04daf2d Tobias Leich eval => EVAL in S05, S06 and S09
FROGGS authored
383 is EVAL('sub infix:<,>($a, $b) { 42 }; 5, 5'), 42, 'infix:<,>($a, $b)';
384 is EVAL('sub infix:<,>(Int $x where 1, Int $y where 1) { 42 }; 1, 1'), 42,
cc6ba56 [t/spec] Test for RT 65638
kyle authored
385 'very specific infix:<,>';
25668e6 Will Coleda Prefer RT #XXXXXX
coke authored
386 #?rakudo todo 'RT #65638'
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
387 #?niecza todo
04daf2d Tobias Leich eval => EVAL in S05, S06 and S09
FROGGS authored
388 is EVAL('sub infix:<#>($a, $b) { 42 }; 5 # 5'), 42, 'infix:<comment char>($a, $b)';
389 is EVAL('multi sub infix:<+>() { 42 }; 5 + 5'), 10, 'infix:<+>()';
390 is EVAL('sub infix:<+>($a, $b) { 42 }; 5 + 5'), 42, 'infix:<+>($a, $b)';
cc6ba56 [t/spec] Test for RT 65638
kyle authored
391 }
392
1a5b410 [t/spec] add skipped tests for custom operators
bubaflub authored
393 {
394 multi sub infix:<foo>($a, $b) {$a + $b};
395
662c6bd peschwa Remove a few unneccessary tests and correct useful ones.
peschwa authored
396 # autoviv tries to call &[foo]() with no arguments, so we define first
397 # alternative is below, with a candidate with an empty parameter list
398 my $x = 0;
399 $x foo=6;
400 is $x, 6, 'foo= works for custom operators';
401 }
402
403 {
404 multi sub infix:<foo>($a, $b) {$a + $b};
405 multi sub infix:<foo>() { 0 };
406
407 # alternative with a candidate with an empty parameter list
1a5b410 [t/spec] add skipped tests for custom operators
bubaflub authored
408 my $x foo=6;
409 is $x, 6, 'foo= works for custom operators';
410 }
411
412 {
d1355fd Moritz Lenz fix two operator overloading tests, unfudge one for rakudo
moritz authored
413 our sub infix:<bar>($a, $b) {$a + $b};
1a5b410 [t/spec] add skipped tests for custom operators
bubaflub authored
414
662c6bd peschwa Remove a few unneccessary tests and correct useful ones.
peschwa authored
415 # similar to above, but without the empty param candidate
416 my $x = 0;
417 $x bar=6;
1a5b410 [t/spec] add skipped tests for custom operators
bubaflub authored
418 is $x, 6, 'bar= works for custom operators';
419
420 }
83e4c2e [t/spec] tests for RT #74104 overloading an operator hides other candida...
bbkr authored
421
422 # RT #74104
0d74a86 Solomon Foster Epic fudging for niecza.
colomon authored
423 #?niecza skip 'No matching candidates to dispatch for &infix:<+>'
83e4c2e [t/spec] tests for RT #74104 overloading an operator hides other candida...
bbkr authored
424 {
425 class RT74104 {}
426 multi sub infix:<+>(RT74104 $, RT74104 $) { -1 }
427 is 2+2, 4, 'overloading an operator does not hide other candidates';
428 }
429
4e78667 fixed RT number
Jimmy Zhuo authored
430 # RT #111418
76c7334 Moritz Lenz RT #112870, LTM and user-defined operators
moritz authored
431 # RT #112870
8437524 Moritz Lenz longest operator wins, even for user-defined operators. RT #11418
moritz authored
432 {
433 sub infix:<*+>($a, $b) { $a * $b + $b }
25668e6 Will Coleda Prefer RT #XXXXXX
coke authored
434 is 2 *+ 5, 15, 'longest operator wins (RT #111418)';
76c7334 Moritz Lenz RT #112870, LTM and user-defined operators
moritz authored
435 sub infix:<~eq>(Str $a, Str $b) { uc($a) eq uc($b) }
25668e6 Will Coleda Prefer RT #XXXXXX
coke authored
436 ok 'a' ~eq 'A', 'longest operator wins (RT #112870)';
8437524 Moritz Lenz longest operator wins, even for user-defined operators. RT #11418
moritz authored
437 }
438
a9171d7 peschwa Added test for RT #109800.
peschwa authored
439 # RT #109800
440 {
441 my &infix:<c> = { $^a + $^b };
442 is 1 c 2, 3, 'assignment to code variable works.';
443 }
444
dea36c4 Christian Bartolomäus Add test for RT #116643
usev6 authored
445 # RT #116643
446 {
447 lives_ok { sub prefix:<\o/>($) {} }, 'can declare operator with a backslash (1)';
448 lives_ok { sub postfix:<\\>($) {} }, 'can declare operator with a backslash (2)';
a8a495c Tobias Leich unfudge/improve tests for fixed lexical names on parrot, RT #116643, RT ...
FROGGS authored
449
450 my $RT116643 = EVAL 'sub infix:<\\o/>($a, $b) { $a * $b }; 21 \\o/ 2';
451 is $RT116643, 42, 'can declare and use operator with a backslash';
dea36c4 Christian Bartolomäus Add test for RT #116643
usev6 authored
452 }
453
18a47ab Christian Bartolomäus Add test for RT #115724
usev6 authored
454 # RT #115724
455 {
456 lives_ok { sub circumfix:<w "> ($a) { }; },
457 'can define circumfix operator with a double quote (")';
a8a495c Tobias Leich unfudge/improve tests for fixed lexical names on parrot, RT #116643, RT ...
FROGGS authored
458 my $RT115724 = EVAL 'sub circumfix:<w "> ($a) { $a }; w 111 "';
459 is $RT115724 , 111, 'can define and use circumfix operator with a double quote (")';
18a47ab Christian Bartolomäus Add test for RT #115724
usev6 authored
460 }
461
e76dd4c Moritz Lenz s/done_testing/done/ as per recent S24 changes
moritz authored
462 done;
cc6ba56 [t/spec] Test for RT 65638
kyle authored
463
6fbd78a [t/spec] fudge sub.t for rakudo
moritz authored
464 # vim: ft=perl6
Something went wrong with that request. Please try again.