Created
March 21, 2015 17:38
-
-
Save j1n3l0/9fb24a4e8e15c26cf25a to your computer and use it in GitHub Desktop.
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
use v6; | |
use Test; | |
use MONKEY_TYPING; | |
class Job { | |
has Str $.title = 'unemployed'; | |
} | |
class Person { | |
has Int $.age = die '$.age must be provided'; | |
has Str $.name = die '$.name must be provided'; | |
has Job $.job; | |
} | |
role Generative { | |
method sample () { | |
$?CLASS.new(|%( | |
$?CLASS.^attributes.map({ | |
$_.name.split(/'!'/).[*-1] => $_.type.sample }))); | |
} | |
} | |
augment class Int does Generative { | |
method sample () { ( 1 .. 1000 ).pick } | |
} | |
augment class Str does Generative { | |
method sample () { <foo bar baz joe quux>.pick } | |
} | |
augment class Job does Generative {} | |
augment class Person does Generative {} | |
lives_ok { isa_ok Person.sample, Person }, 'Generate a sample Person'; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment