#!/usr/bin/env perl6 use v6; use Test; use JSON::Tiny; use lib my $path = IO::Path.new($?FILE).parent.path; plan 12; my $module = %*ENV ?? 'Example' !! 'Phone'; use-ok $module; require ::($module) ; my %tests = from-json open("$path/cases.json").slurp-rest; subtest 'number, area-code and pretty methods', { plan 3; ok Phone.can('number'), 'can Phone.number'; ok Phone.can('area-code'), 'can Phone.area-code'; ok Phone.can('pretty'), 'can Phone.pretty'; } or fail 'Missing method(s).'; for @(%tests) { my $phone = Phone.new(number => .); my $msg = 'for ' ~ .; is $phone.number, ., "number $msg"; is $phone.area-code, ., "area-code $msg"; is $phone.pretty, ., "pretty $msg"; } todo 'Optional Exception Tests' unless %*ENV; # Remove this line for invalid input tests subtest 'Throw exceptions for invalid input', { plan 5; throws-like {Phone.new(number => .)}, Exception, . for @(%tests); }