Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rewrite smart-matching test to conform to current spec
  • Loading branch information
moritz committed Aug 8, 2011
1 parent c1ac92d commit a96285b
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions S03-smartmatch/any-method.t
@@ -1,36 +1,16 @@
use v6;
use Test;
plan 4;

#L<S03/Smart matching/Any .foo method truth>
#L<S03/Smart matching/Any .foo(...) method truth>
{
class Smartmatch::Tester {
method a { 4 };
method b($x) { 5 * $x };
method c { 0 };
}
my $t = Smartmatch::Tester.new();
ok ($t ~~ .a), '$obj ~~ .method calls the method (+)';
ok !($t ~~ .c), '$obj ~~ .method calls the method (-)';
ok ($t ~~ .b(3)), '$obj ~~ .method(arg) calls the method (true)';
ok ($t ~~ .b: 3), '$obj ~~ .method: arg calls the method (true)';
ok !($t ~~ .b(0)), '$obj ~~ .method(arg) calls the method (false)';
ok !($t ~~ .b: 0), '$obj ~~ .method: arg calls the method (false)';
nok 'ab' ~~ .uc, 'smart-match happens after method calls on $_ 1';
ok 'AA' ~~ .uc, 'smart-match happens after method calls on $_ 2';
}

{
nok 'ab' ~~ .substr(1), 'method call with args 1';
ok 'ab' ~~ .substr(0), 'method call with args 2';

# now change the same in when blocks, which also smart-match
my ($a, $b, $c) = 0 xx 3;
given $t {
when .a { $a = 1 };
}
given $t {
when .b(3) { $b = 1 };
}
given $t {
when .b(0) { $c = 1 };
}
ok $a, '.method in when clause';
ok $b, '.method(args) in when clause';
ok !$c, '..method(args) should not trigger when-block when false';
}

done;
Expand Down

0 comments on commit a96285b

Please sign in to comment.