Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
turn advent 2013 day 02 into a test
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| use v6; | ||
| use Test; | ||
| plan 12; | ||
|
|
||
| class Dog { | ||
| has $.name; | ||
| } | ||
|
|
||
| sub check(Dog $d) { | ||
| return "Yup, that's a dog for sure."; | ||
| } | ||
|
|
||
| my $name = 'Fido'; | ||
| my Dog $dog .= new(:$name); | ||
| ok check($dog), 'call with instance'; | ||
| ok check(Dog), 'call with type object'; | ||
|
|
||
| is Dog.gist, '(Dog)', '.gist'; | ||
|
|
||
| nok Dog, 'Type object is False'; | ||
| nok defined(Dog), 'Type object is undefined'; | ||
| ok $dog, 'instance is True'; | ||
| ok defined($dog), 'instance is defined'; | ||
| is $dog.name, 'Fido', 'Attribute access on instance'; | ||
| dies_ok { Dog.name }, 'Cannot access attribute on type object'; | ||
|
|
||
| multi sniff(Dog:U $dog) { | ||
| return "a type object, of course" | ||
| } | ||
| multi sniff(Dog:D $dog) { | ||
| return "definitely a real dog instance" | ||
| } | ||
|
|
||
| is sniff(Dog) , 'a type object, of course', 'multi with instance'; | ||
| is sniff($dog), 'definitely a real dog instance', 'multi with type object'; | ||
|
|
||
| is ((my @a = "Hip " x 2), @a.^name, "!").join, 'Hip Hip Array!', 'corniest one-liner'; | ||
|
|