-
Notifications
You must be signed in to change notification settings - Fork 135
/
any-pair.t
33 lines (30 loc) · 1.16 KB
/
any-pair.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use v6;
use Test;
plan 10;
#L<S03/Smart matching/Any Pair test object attribute>
{
# ?."{X.key}" === ?X.value
# means:
# call the method with the name of X.key on the object, coerce to
# Bool, and check if it's the same as boolean value of X.value
class SmartmatchTest::AttrPair {
has $.a = 4;
has $.b = 'foo';
has $.c = Mu;
}
my $o = SmartmatchTest::AttrPair.new();
ok ($o ~~ :a(4)), '$obj ~~ Pair (Int, +)';
ok ($o ~~ :a(2)), '$obj ~~ Pair (Int, +)';
ok !($o ~~ :b(0)), '$obj ~~ Pair (different types)';
ok ($o ~~ :b<foo>), '$obj ~~ Pair (Str, +)';
ok ($o ~~ :b<ugh>), '$obj ~~ Pair (Str, -)';
ok ($o ~~ :c(Mu)), '$obj ~~ Pair (Mu, +)';
ok ($o ~~ :c(0)), '$obj ~~ Pair (0, +)';
ok !($o ~~ :b(Mu)), '$obj ~~ Pair (Mu, -)';
# not explicitly specced, but implied by the spec and decreed
# by TimToady: non-existing method or attribute dies:
# http://irclog.perlgeek.de/perl6/2009-07-06#i_1293199
dies-ok {$o ~~ :e(Mu)}, '$obj ~~ Pair, nonexistent, dies (1)';
dies-ok {$o ~~ :e(5)}, '$obj ~~ Pair, nonexistent, dies (2)';
}
# vim: ft=perl6