Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 38 lines (33 sloc) 1.235 kb
e67eb0c [t/spec] split S03-operators/smartmatch.t into S03-smartmatch/*.t
kyle authored
1 use v6;
2 use Test;
c25c3aa [t/spec] update some plan counts to make spectest progress stats more…
mberends authored
3 plan 10;
e67eb0c [t/spec] split S03-operators/smartmatch.t into S03-smartmatch/*.t
kyle authored
4
5 #L<S03/Smart matching/Any Pair test object attribute>
6 {
7 # ?."{X.key}" === ?X.value
8 # means:
9 # call the method with the name of X.key on the object, coerce to
10 # Bool, and check if it's the same as boolean value of X.value
11
12 class SmartmatchTest::AttrPair {
13 has $.a = 4;
14 has $.b = 'foo';
15 has $.c = Mu;
16 }
17 my $o = SmartmatchTest::AttrPair.new();
18 ok ($o ~~ :a(4)), '$obj ~~ Pair (Int, +)';
19 ok ($o ~~ :a(2)), '$obj ~~ Pair (Int, +)';
20 ok !($o ~~ :b(0)), '$obj ~~ Pair (different types)';
21 ok ($o ~~ :b<foo>), '$obj ~~ Pair (Str, +)';
22 ok ($o ~~ :b<ugh>), '$obj ~~ Pair (Str, -)';
23 ok ($o ~~ :c(Mu)), '$obj ~~ Pair (Mu, +)';
24 ok ($o ~~ :c(0)), '$obj ~~ Pair (0, +)';
25 ok !($o ~~ :b(Mu)), '$obj ~~ Pair (Mu, -)';
26 # not explicitly specced, but implied by the spec and decreed
27 # by TimToady: non-existing method or attribute dies:
28 # http://irclog.perlgeek.de/perl6/2009-07-06#i_1293199
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
29 #?niecza todo
e67eb0c [t/spec] split S03-operators/smartmatch.t into S03-smartmatch/*.t
kyle authored
30 dies_ok {$o ~~ :e(Mu)}, '$obj ~~ Pair, nonexistent, dies (1)';
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
31 #?niecza todo
e67eb0c [t/spec] split S03-operators/smartmatch.t into S03-smartmatch/*.t
kyle authored
32 dies_ok {$o ~~ :e(5)}, '$obj ~~ Pair, nonexistent, dies (2)';
33 }
34
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
35 done;
e67eb0c [t/spec] split S03-operators/smartmatch.t into S03-smartmatch/*.t
kyle authored
36
37 # vim: ft=perl6
Something went wrong with that request. Please try again.