Skip to content

Commit

Permalink
Add a few more mad edge-cases to tz tests, and make sure tests run in…
Browse files Browse the repository at this point in the history
… a predictable order for easier debuggery if they fail
  • Loading branch information
DrHyde committed Mar 7, 2024
1 parent 3f60d1e commit a4f2477
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions t/timezones.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use Test::More;

my $all_nanp_timezones = ['America/Adak','America/Anchorage','America/Anguilla','America/Antigua','America/Barbados','America/Boise','America/Cayman','America/Chicago','America/Denver','America/Dominica','America/Edmonton','America/Fort_Nelson','America/Grand_Turk','America/Grenada','America/Halifax','America/Jamaica','America/Juneau','America/Los_Angeles','America/Lower_Princes','America/Montserrat','America/Nassau','America/New_York','America/North_Dakota/Center','America/Phoenix','America/Port_of_Spain','America/Puerto_Rico','America/Regina','America/Santo_Domingo','America/St_Johns','America/St_Kitts','America/St_Lucia','America/St_Thomas','America/St_Vincent','America/Toronto','America/Tortola','America/Vancouver','America/Winnipeg','Atlantic/Bermuda','Pacific/Guam','Pacific/Honolulu','Pacific/Pago_Pago','Pacific/Saipan'];

my %tests = (
my @tests = (
'+442087712924' => ['Europe/London'], # Geographic UK number
'+445511000000' => ['Europe/Guernsey','Europe/Isle_of_Man','Europe/Jersey','Europe/London'], # Non-geographic UK number
'+441481720014' => ['Europe/Guernsey'], # Geographic Guernsey number
'+12024181440' => ['America/New_York'], # geographic New York number
'+18765551234' => ['America/Jamaica'], # geographic Jamaican number
'+12642920000' => ['America/Anguilla'], # geographic Anguilla number
Expand All @@ -23,10 +24,15 @@ my %tests = (
'+815012345678' => ['Asia/Tokyo'], # non-geographic Japanese number
'+18885558888' => $all_nanp_timezones, # Non-geographic NANP number.
'+80012345678' => undef, # International Toll-Free.
'+61265632114' => ['Australia/Lord_Howe'], # Lord Howe Island, Australia
'+61735353535' => ['Australia/Brisbane'], # another Australian tz
'+16235555678' => ['America/Phoenix'], # Phoenix, Arizona, no DST
'+19285555678' => ['America/Denver', 'America/Phoenix'], # bit of AZ incl Navajo reservation which *does* do DST
);

note("timezones()");
while (my ($num, $expect) = each %tests) {
while (@tests) {
my ($num, $expect) = splice(@tests, 0, 2);
my $number = Number::Phone::Lib->new($num);
is_deeply($number->timezones(), $expect, "timezone of $num using libphonenumber");
}
Expand All @@ -35,7 +41,4 @@ while (my ($num, $expect) = each %tests) {
is_deeply(Number::Phone->new('+18885558888')->timezones(), $all_nanp_timezones, 'non-stubs returns the same as the stub country implementation');
is_deeply(Number::Phone::NANP->new('+12024181440')->timezones(), ['America/New_York'], 'non-stubs returns the same as the stub country implementation');

# International Toll-Free numbers return unknown.
is(Number::Phone->new('+80012345678')->timezones(), undef, 'international Toll-Free numbers (+800) return unknown');

done_testing();

0 comments on commit a4f2477

Please sign in to comment.