Permalink
Browse files

rewrite ~~ tests to use sub routine smartmatchers

There's currently discussion on p5p about disallowing simple scalars on
the right hand side of a smart match, so better to avoid testing for it
now.
  • Loading branch information...
1 parent 6707318 commit 7b193db9c6d2467e9251ed729097cf73c30153e1 @rjbs committed Aug 29, 2012
Showing with 24 additions and 20 deletions.
  1. +24 −20 t/smartmatch.t
View
@@ -6,23 +6,27 @@ plan tests => 16;
use Perl6::Junction qw(all any none one);
-ok(! (5 ~~ all(1,2,5)), "5 !~~ all(1,2,5)" );
-ok( (5 ~~ any(1,2,5)), "5 ~~ any(1,2,5)" );
-ok(! (5 ~~ none(1,2,5)), "5 !~~ none(1,2,5)" );
-ok( (5 ~~ one(1,2,5)), "5 ~~ one(1,2,5)" );
-
-ok( (5 ~~ all(5,5,5)), "5 ~~ all(5,5,5)" );
-ok( (5 ~~ any(5,5,5)), "5 ~~ any(5,5,5)" );
-ok(! (5 ~~ none(5,5,5)), "5 !~~ none(5,5,5)" );
-ok(! (5 ~~ one(5,5,5)), "5 !~~ one(5,5,5)" );
-
-ok(! (3 ~~ all(1,2,5)), "3 !~~ all(1,2,5)" );
-ok(! (3 ~~ any(1,2,5)), "3 !~~ any(1,2,5)" );
-ok( (3 ~~ none(1,2,5)), "3 ~~ none(1,2,5)" );
-ok(! (3 ~~ one(1,2,5)), "3 !~~ one(1,2,5)" );
-
-
-ok(! ( all(1,2,5) ~~ 5), " all(1,2,5) !~~ 5" );
-ok( ( any(1,2,5) ~~ 5), " any(1,2,5) ~~ 5" );
-ok(! ( none(1,2,5) ~~ 5), "none(1,2,5) !~~ 5" );
-ok( ( one(1,2,5) ~~ 5), " one(1,2,5) ~~ 5" );
+my $is_1 = sub { $_[0] == 1 };
+my $is_2 = sub { $_[0] == 2 };
+my $is_5 = sub { $_[0] == 5 };
+
+ok(! (5 ~~ all($is_1,$is_2,$is_5)), '5 !~~ all($is_1,$is_2,$is_5)' );
+ok( (5 ~~ any($is_1,$is_2,$is_5)), '5 ~~ any($is_1,$is_2,$is_5)' );
+ok(! (5 ~~ none($is_1,$is_2,$is_5)), '5 !~~ none($is_1,$is_2,$is_5)' );
+ok( (5 ~~ one($is_1,$is_2,$is_5)), '5 ~~ one($is_1,$is_2,$is_5)' );
+
+ok( (5 ~~ all($is_5,$is_5,$is_5)), '5 ~~ all($is_5,$is_5,$is_5)' );
+ok( (5 ~~ any($is_5,$is_5,$is_5)), '5 ~~ any($is_5,$is_5,$is_5)' );
+ok(! (5 ~~ none($is_5,$is_5,$is_5)), '5 !~~ none($is_5,$is_5,$is_5)' );
+ok(! (5 ~~ one($is_5,$is_5,$is_5)), '5 !~~ one($is_5,$is_5,$is_5)' );
+
+ok(! (3 ~~ all($is_1,$is_2,$is_5)), '3 !~~ all($is_1,$is_2,$is_5)' );
+ok(! (3 ~~ any($is_1,$is_2,$is_5)), '3 !~~ any($is_1,$is_2,$is_5)' );
+ok( (3 ~~ none($is_1,$is_2,$is_5)), '3 ~~ none($is_1,$is_2,$is_5)' );
+ok(! (3 ~~ one($is_1,$is_2,$is_5)), '3 !~~ one($is_1,$is_2,$is_5)' );
+
+
+ok(! ( all(1,2,5) ~~ $is_5), ' all(1,2,5) !~~ $is_5' );
+ok( ( any(1,2,5) ~~ $is_5), ' any(1,2,5) ~~ $is_5' );
+ok(! ( none(1,2,5) ~~ $is_5), 'none(1,2,5) !~~ $is_5' );
+ok( ( one(1,2,5) ~~ $is_5), ' one(1,2,5) ~~ $is_5' );

0 comments on commit 7b193db

Please sign in to comment.