Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Metamodel::Primitives parameterization methods #634

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion S12-meta/primitives.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 20;
plan 26;

{
my $union-type-checks = 0;
Expand Down Expand Up @@ -106,3 +106,49 @@ plan 20;
'Can rebless to a target mixin type';
is $obj.HOW.name, 'to', 'Object has expected type after rebless';
}

{
my class ParametricHOW does Metamodel::Naming {
# The work required for creating types is handled outside of here.
}

my class ParameterizedHOW does Metamodel::Naming {
has @!parameters is required;

submethod BUILD(::?CLASS:D: :@parameters! --> Nil) {
@!parameters := @parameters;
}

method new_type(::?CLASS:_: @parameters, Str:D :$name! --> Mu) {
my ::?CLASS:D $meta := self.bless: :@parameters;
my Mu $obj := Metamodel::Primitives.create_type: $meta, 'Uninstantiable';
$meta.set_name: $obj, $name;
$obj
}

method parameters(::?CLASS:D: Mu) { @!parameters }
}

my Mu $parametric := Metamodel::Primitives.create_type: ParametricHOW.new, 'Uninstantiable';
$parametric.^set_name: 'Parametric'; # Eases debugging.
lives-ok {
Metamodel::Primitives.set_parameterizer: $parametric, -> Mu \obj, @parameters {
my Str:D $name = 'Parameterized';
ParameterizedHOW.new_type: @parameters, :$name
}
}, 'can set the parameterizer for a metaobject';

my Mu $parameterized := Nil;
my Mu $parameter .= new; # Intentionally containerized with Scalar.
lives-ok {
$parameterized := Metamodel::Primitives.parameterize_type: $parametric, $parameter
}, 'can parameterize metaobjects';
cmp-ok $parameterized.^parameters.[0], &[=:=], $parameter,
'type parameters passed to the parameterizer for a metaobject keep their original containers';
cmp-ok Metamodel::Primitives.type_parameterized($parameterized), &[=:=], $parametric,
'can get the parametric type of the result of a parameterization';
cmp-ok Metamodel::Primitives.type_parameters($parameterized).[0], &[=:=], $parameter,
'can get the type parameters of the result of a parameterization';
cmp-ok Metamodel::Primitives.type_parameter_at($parameterized, 0), &[=:=], $parameter,
'can get a specific type parameter of the result of a parameterization';
}