Skip to content

Commit

Permalink
Merge pull request #83 from aaronrenner/ar-nanp-tests
Browse files Browse the repository at this point in the history
Add tests for NANP area codes and support new area codes
  • Loading branch information
fcevado committed Nov 10, 2016
2 parents f03203b + f613110 commit 42e5290
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/phone/nanp/ca/ab.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.CA.AB do
use Helper.Area
field :regex, ~r/^(1)(403|780|587)([2-9].{6})$/
field :regex, ~r/^(1)(403|780|587|825)([2-9].{6})$/
field :area_name, "Alberta"
field :area_type, "province"
field :area_abbreviation, "AB"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/ca/ns_pe.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.CA.NS_PE do
use Helper.Area
field :regex, ~r/^(1)(902)([2-9].{6})$/
field :regex, ~r/^(1)(902|782)([2-9].{6})$/
field :area_name, ["Nova Scotia","Prince Edward Island"]
field :area_type, "provinces"
field :area_abbreviation, ["NS","PE"]
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/ca/on.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.CA.ON do
use Helper.Area
field :regex, ~r/^(1)(226|249|289|343|365|416|437|519|613|647|705|807|905)([2-9].{6})$/
field :regex, ~r/^(1)(226|249|289|343|365|416|437|519|548|613|647|705|807|905)([2-9].{6})$/
field :area_name, "Ontario"
field :area_type, "province"
field :area_abbreviation, "ON"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/gu.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.GU do
use Helper.Country
field :regex, ~r/^(1)(473)([2-9].{6})$/
field :regex, ~r/^(1)(671)([2-9].{6})$/
field :country, "Guam"
field :a2, "GU"
field :a3, "GUM"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/pr.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.PR do
use Helper.Country
field :regex, ~r/^(1)(787|393)([2-9].{6})$/
field :regex, ~r/^(1)(787|939)([2-9].{6})$/
field :country, "Puerto Rico"
field :a2, "PR"
field :a3, "PRI"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/al.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.AL do
use Helper.Area
field :regex, ~r/^(1)(205|251|256|334)([2-9].{6})$/
field :regex, ~r/^(1)(205|251|256|334|938)([2-9].{6})$/
field :area_name, "Alabama"
field :area_type, "state"
field :area_abbreviation, "AL"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/ca.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.CA do
use Helper.Area
field :regex, ~r/^(1)(209|213|310|323|408|415|424|510|530|559|562|619|626|650|661|707|714|760|805|818|831|858|909|916|925|949)([2-9].{6})$/
field :regex, ~r/^(1)(209|213|310|323|408|415|424|442|510|530|559|562|619|626|628|650|657|661|669|707|714|747|760|805|818|831|858|909|916|925|949|951)([2-9].{6})$/
field :area_name, "California"
field :area_type, "state"
field :area_abbreviation, "CA"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/ct.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.CT do
use Helper.Area
field :regex, ~r/^(1)(203|475|860)([2-9].{6})$/
field :regex, ~r/^(1)(203|475|860|959)([2-9].{6})$/
field :area_name, "Connecticut"
field :area_type, "state"
field :area_abbreviation, "CT"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/il.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.IL do
use Helper.Area
field :regex, ~r/^(1)(217|224|309|312|331|618|630|708|773|815|847|872)([2-9].{6})$/
field :regex, ~r/^(1)(217|224|309|312|331|618|630|708|773|779|815|847|872)([2-9].{6})$/
field :area_name, "Illinois"
field :area_type, "state"
field :area_abbreviation, "IL"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/in.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.IN do
use Helper.Area
field :regex, ~r/^(1)(219|260|317|574|765|812|930)([2-9].{6})$/
field :regex, ~r/^(1)(219|260|317|463|574|765|812|930)([2-9].{6})$/
field :area_name, "Indiana"
field :area_type, "state"
field :area_abbreviation, "IN"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/nc.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.NC do
use Helper.Area
field :regex, ~r/^(1)(252|336|704|828|910|919|980|984)([2-9].{6})$/
field :regex, ~r/^(1)(252|336|704|743|828|910|919|980|984)([2-9].{6})$/
field :area_name, "North Carolina"
field :area_type, "state"
field :area_abbreviation, "NC"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/ny.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.NY do
use Helper.Area
field :regex, ~r/^(1)(212|315|347|516|585|607|631|646|716|718|845|914|917|929)([2-9].{6})$/
field :regex, ~r/^(1)(212|315|332|347|516|518|585|607|631|646|680|716|718|845|914|917|929|934)([2-9].{6})$/
field :area_name, "New York"
field :area_type, "state"
field :area_abbreviation, "NY"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/tx.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.TX do
use Helper.Area
field :regex, ~r/^(1)(210|214|254|281|325|346|361|409|430|432|469|512|682|713|806|817|830|832|903|915|936|940|956|972|979)([2-9].{6})$/
field :regex, ~r/^(1)(210|214|254|281|325|346|361|409|430|432|469|512|682|713|737|806|817|830|832|903|915|936|940|956|972|979)([2-9].{6})$/
field :area_name, "Texas"
field :area_type, "state"
field :area_abbreviation, "TX"
Expand Down
2 changes: 1 addition & 1 deletion lib/phone/nanp/us/wv.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.NANP.US.WV do
use Helper.Area
field :regex, ~r/^(1)(304)([2-9].{6})$/
field :regex, ~r/^(1)(304|681)([2-9].{6})$/
field :area_name, "West Virginia"
field :area_type, "state"
field :area_abbreviation, "WV"
Expand Down
20 changes: 20 additions & 0 deletions test/phone/nanp_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Phone.NanpTest do
use ExUnit.Case, async: true

@external_resource area_codes_path = Path.join([__DIR__, "..", "support", "nanp-area-codes.csv"])

for line <- File.stream!(area_codes_path, [], :line) do
[area_code, state_abbreviation] = line |> String.strip |> String.split(",")

test "correctly parses NANP area code #{area_code} (#{state_abbreviation})" do
assert {:ok, result} = Phone.parse(unquote("1#{area_code}5551234"))

case result do
%{a2: "US"} ->
assert result.area_abbreviation == unquote(state_abbreviation)
_ ->
true
end
end
end
end
Loading

0 comments on commit 42e5290

Please sign in to comment.