Sha256: 945d337718aaa1b143b38f80a192ea4bee3de5026ab4178e94c29e12909c5d01
Contents?: true
Size: 1.11 KB
Versions: 20
Compression:
Stored size: 1.11 KB
Contents
#!/usr/bin/env perl6 use v6; use Test; use JSON::Tiny; use lib my $path = IO::Path.new($?FILE).parent.path; BEGIN { plan 12; use-ok %*ENV<EXERCISM> ?? 'Example' !! 'Phone', 'Module loaded'; } 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<valid>) { my $phone = Phone.new(number => .<input>); my $msg = 'for ' ~ .<test>; is $phone.number, .<number>, "number $msg"; is $phone.area-code, .<area-code>, "area-code $msg"; is $phone.pretty, .<pretty>, "pretty $msg"; } my $exception; if %*ENV<EXERCISM> { $exception = X::Phone::Invalid; } else { todo 'Optional Exception Tests'; # Remove this line for invalid input tests $exception = Exception; # Change this if you wish to specify a specific exception } subtest 'Throw exceptions for invalid input', { plan 5; throws-like {Phone.new(number => .<input>)}, $exception, .<test> for @(%tests<invalid>); }
Version data entries
20 entries across 20 versions & 1 rubygems