use v6-alpha; use Test; plan 22; =pod Parameterized role tests, see L =cut # L # L ok eval(' role InitialAttribVal[: $val] { has $.attr = $val; } 1 '), "parameterized role definition (1)", :todo; my $a; ok eval('$a does InitialAttribVal[42]'), "imperative does to apply a parametrized role (1)", :todo; is try { $a.attr }, 42, "attribute was initialized correctly (1)", :todo; # L ok eval('$a.HOW.does(InitialAttribVal)'), ".HOW.does gives correct information (1-1)", :todo; # L ok eval('!$a.HOW.does(InitialAttribVal[42])'), ".HOW.does gives correct information (1-2)", :todo; my $b; ok eval('$a does InitialAttribVal[23]'), "imperative does to apply a parametrized role (2)", :todo; is try { $a.attr }, 23, "attribute was initialized correctly (2)", :todo; # L ok eval('$a.HOW.does(InitialAttribVal)'), ".HOW.does gives correct information (2-1)", :todo; # L ok eval('!$a.HOW.does(InitialAttribVal[23])'), ".HOW.does gives correct information (2-2)", :todo; # L # L ok eval(' role InitialAttribType[^vartype:] { method hi(vartype $foo) { 42 } } '), "parameterized role definition (2)", :todo; my $c; ok eval('$c does InitialAttribType[Code]'), "imperative does to apply a parametrized role (3)", :todo; ok eval('$c.HOW.does(InitialAttribType)'), ".HOW.does gives correct information (3-1)", :todo; ok eval('$c.HOW.does(InitialAttribType[Code])'), ".HOW.does gives correct information (3-2)", :todo; is try { $c.hi(sub {}) }, 42, "type information was processed correctly (1)", :todo; dies_ok { $c.hi("not a code object") }, "type information was processed correctly (2)"; # Parameterized role using both a parameter which will add to the "long name" # of the role and one which doesn't. # (Explanation: This one is easier. The two attributes $.type and $.name will # be predefined (using the role parameterization). The $type adds to the long # name of the role, $name does not. Such: # my $a does InitialAttribBoth["foo", "bar"]; # my $b does InitialAttribBoth["foo", "grtz"]; # $a ~~ InitialAttribBoth ==> true # $b ~~ InitialAttribBoth ==> true # $a ~~ InitialAttribBoth["foo"] ==> true # $b ~~ InitialAttribBoth["foo"] ==> true # $a ~~ InitialAttribBoth["foo", "bar"] ==> false # $b ~~ InitialAttribBoth["foo", "grtz"] ==> false # Heavy stuff, eh?) ok eval(' role InitialAttribBoth[Str $type: Str $name] { has $.type = $type; has $.name = $name; } 1 '), "parameterized role definition (3)", :todo; my $d; ok eval('$d does InitialAttribBoth["type1", "name1"]'), "imperative does to apply a parametrized role (4)", :todo; ok eval('$c.HOW.does(InitialAttribType)'), ".HOW.does gives correct information (4-1)", :todo; ok eval('$d.HOW.does(InitialAttribType["type1"])'), ".HOW.does gives correct information (4-2)", :todo; ok eval('!$d.HOW.does(InitialAttribType["type1", "name1"])'), ".HOW.does gives correct information (4-3)"; is try { $d.type }, "type1", ".type works correctly", :todo; is try { $d.name }, "name1", ".name works correctly", :todo;