<commit_before>#!/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 bail-out '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<commit_msg>Check Perl 6 version<commit_after>#!/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';

  unless $*PERL.compiler.version ~~ v2016.10+ {
    sub bail-out {};
    note 'Perl 6 ' ~ $*PERL.compiler.version ~ ' is not supported. Please use v2016.10 or newer';
    skip-rest;
    exit;
  }
}

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 bail-out '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
{'fraction_non_alphanumeric': 0.19767441860465115, 'fraction_numerical': 0.011627906976744186, 'mean_word_length': 3.952038369304556, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '946001', 'n_tokens_mistral': 804, 'n_tokens_neox': 766, 'n_words': 207}