From 34c73958152a22dde29788e51e9df6f1c32dfb29 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Thu, 29 Apr 2021 11:30:52 +0100 Subject: - Added test script for task 1 of week 110. --- challenge-110/mohammad-anwar/perl/ch-1.t | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 challenge-110/mohammad-anwar/perl/ch-1.t diff --git a/challenge-110/mohammad-anwar/perl/ch-1.t b/challenge-110/mohammad-anwar/perl/ch-1.t new file mode 100644 index 0000000000..574305981f --- /dev/null +++ b/challenge-110/mohammad-anwar/perl/ch-1.t @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use Test::Deep; + +is_deeply( valid_phone_numbers('input-1.txt'), + [ '0044 1148820341', + ' +44 1148820341', + '(44) 1148820341', ] ); + +done_testing; + +sub valid_phone_numbers { + my ($file) = @_; + + die "ERROR: Missing input file.\n" unless defined $file; + + open(my $fh, '<:encoding(utf8)', $file) + or die "ERROR: Unable to open $file: $!\n"; + + my $valid_phone_numbers = []; + while (my $row = <$fh>) { + chomp $row; + + if ( $row =~ / ( \+\d{2} | \(\d{2}\) | \d{4} ) \s \d{10} /x ) { + push @$valid_phone_numbers, $row; + } + } + + close($fh); + + return $valid_phone_numbers; +} -- cgit