diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-04-29 11:30:52 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-04-29 11:30:52 +0100 |
| commit | 34c73958152a22dde29788e51e9df6f1c32dfb29 (patch) | |
| tree | 98e89d4359949db072f5d78dc69255afee5c1afa | |
| parent | 7830a49c60207022845f0bc55b63ba0072cb934a (diff) | |
| download | perlweeklychallenge-club-34c73958152a22dde29788e51e9df6f1c32dfb29.tar.gz perlweeklychallenge-club-34c73958152a22dde29788e51e9df6f1c32dfb29.tar.bz2 perlweeklychallenge-club-34c73958152a22dde29788e51e9df6f1c32dfb29.zip | |
- Added test script for task 1 of week 110.
| -rw-r--r-- | challenge-110/mohammad-anwar/perl/ch-1.t | 36 |
1 files changed, 36 insertions, 0 deletions
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; +} |
