Permalink
Browse files

[t/spec] Basic tests for meta-operators generated from user defined o…

…perators.

git-svn-id: http://svn.pugscode.org/pugs@26896 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent e9a791f commit 0df5ccbdf857f2f1492ea54c3754bb004063c4d6 jnthn committed May 20, 2009
Showing with 33 additions and 0 deletions.
  1. +33 −0 S13-overloading/metaoperators.t
View
33 S13-overloading/metaoperators.t
@@ -0,0 +1,33 @@
+use v6;
+use Test;
+
+plan 9;
+
+#L<S06/Operator overloading>
+
+# Define operator, check it works.
+sub infix:<wtf>($a, $b) { $a ~ "WTF" ~ $b };
+is 'OMG' wtf 'BBQ', 'OMGWTFBBQ', 'basic sanity';
+
+# Assignment meta-op.
+my $a = 'OMG';
+$a wtf= 'BBQ';
+is $a, 'OMGWTFBBQ', 'assignment meta-op';
+
+# Reduce meta-op.
+is ([wtf] <OMG BBQ PONIES>), 'OMGWTFBBQWTFPONIES', 'reduce meta-op generated';
+
+# Reverse meta-op.
+is 'BBQ' Rwtf 'OMG', 'OMGWTFBBQ', 'reverse meta-op generated';
+
+# Cross meta-op.
+is ~(('OMG','BBQ') Xwtf ('OMG','BBQ')), 'OMGWTFOMG OMGWTFBBQ BBQWTFOMG BBQWTFBBQ',
+ 'cross meta-op generated';
+
+# Hyper meta-op (todo: unicode variants, check variants apply correct constraints)
+is ~(('OMG','BBQ') >>wtf<< ('BBQ','OMG')), 'OMGWTFBBQ BBQWTFOMG', '>>...<< hyper generated';
+is ~(('OMG','BBQ') <<wtf<< ('BBQ','OMG')), 'OMGWTFBBQ BBQWTFOMG', '<<...<< hyper generated';
+is ~(('OMG','BBQ') >>wtf>> ('BBQ','OMG')), 'OMGWTFBBQ BBQWTFOMG', '>>...>> hyper generated';
+is ~(('OMG','BBQ') <<wtf>> ('BBQ','OMG')), 'OMGWTFBBQ BBQWTFOMG', '<<...>> hyper generated';
+
+# vim: ft=perl6

0 comments on commit 0df5ccb

Please sign in to comment.