Skip to content

Commit

Permalink
Test accepts_type
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Nov 6, 2017
1 parent a051854 commit 00e8bd1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion t/nqp/103-typecache.t
@@ -1,4 +1,4 @@
plan(17);
plan(21);

class IsThisType {
}
Expand Down Expand Up @@ -52,6 +52,8 @@ class TypeCheckConstant {
}
}

my $got_accepts_type_type;
my $got_accepts_type_obj;
class AcceptingType {
has int $!accepts_type_called;

Expand All @@ -61,6 +63,8 @@ class AcceptingType {
$!accepts_type_called;
}
method accepts_type($type, $obj) {
$got_accepts_type_type := $type;
$got_accepts_type_obj := $obj;
$!accepts_type_called := $!accepts_type_called + 1;
$!accepts;
}
Expand All @@ -83,8 +87,17 @@ nqp::settypecheckmode($accepts_true, nqp::const::TYPE_CHECK_NEEDS_ACCEPTS);
nqp::settypecheckmode($accepts_false, nqp::const::TYPE_CHECK_NEEDS_ACCEPTS);
nqp::settypecheckmode($accepts_not_called, nqp::const::TYPE_CHECK_NEEDS_ACCEPTS);

$got_accepts_type_obj := NQPMu;
$got_accepts_type_type := NQPMu;
ok(nqp::istype($type_check_false, $accepts_true), 'nqp::const::TYPE_CHECK_NEEDS_ACCEPTS: istype (+)');
ok(nqp::eqaddr($got_accepts_type_obj, $type_check_false), 'accepts_type got correct obj');
ok(nqp::eqaddr($got_accepts_type_type, $accepts_true), 'accepts_type got correct type');

$got_accepts_type_obj := NQPMu;
$got_accepts_type_type := NQPMu;
ok(!nqp::istype($type_check_false, $accepts_false), 'nqp::const::TYPE_CHECK_NEEDS_ACCEPTS: istype (-)');
ok(nqp::eqaddr($got_accepts_type_obj, $type_check_false), 'accepts_type got correct obj');
ok(nqp::eqaddr($got_accepts_type_type, $accepts_false), 'accepts_type got correct type');

my $not_really_accepting_type := AcceptingType.new(accepts => 1).new_type;
nqp::settypecheckmode($not_really_accepting_type, nqp::const::TYPE_CHECK_CACHE_DEFINITIVE);
Expand Down

0 comments on commit 00e8bd1

Please sign in to comment.