Skip to content

Commit

Permalink
Merge pull request #126 from davekapp/brazilian_toll_free_support
Browse files Browse the repository at this point in the history
Add basic Brazilian toll-free number support
  • Loading branch information
fcevado committed Jan 20, 2020
2 parents 2286b4a + cf2431e commit de984f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/phone/br/toll_free.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Phone.BR.TollFree do
@moduledoc false

use Helper.Country

def regex, do: ~r/^(55)(800)([0-9].{6,7})$/
def country, do: "Brazil toll-free"
def a2, do: "BR"
def a3, do: "BRA"

matcher(:regex, ["55800"])
end
1 change: 1 addition & 0 deletions lib/phone/countries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule Phone.Countries do
Phone.BN,
Phone.BO,
Phone.BR,
Phone.BR.TollFree,
Phone.BT,
Phone.BW,
Phone.BY,
Expand Down
22 changes: 22 additions & 0 deletions test/phone/b_countries/br_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,26 @@ defmodule Phone.BRTest do
end
end)
end)

describe "Brazilian toll-free numbers" do
test "it can recognize Brazilian toll-free numbers" do
sample_number = "+558002345678"
assert Phone.valid?(sample_number)
assert {:ok, parsed} = Phone.parse(sample_number)

assert parsed.country == Phone.BR.TollFree.country
assert parsed.a2 == Phone.BR.TollFree.a2
assert parsed.a3 == Phone.BR.TollFree.a3
end

test "it won't accept a Brazilian toll-free number that seems implausibly long" do
bad_number = "+55800234567890"
refute Phone.valid?(bad_number)
assert {:error, _} = Phone.parse(bad_number)

assert_raise ArgumentError, "Not a valid phone number.", fn ->
Phone.BR.TollFree.build!(bad_number)
end
end
end
end

0 comments on commit de984f1

Please sign in to comment.