fixed a number of phone number failures
This commit is contained in:
parent
10cf319731
commit
6c56eb91ef
3 changed files with 19 additions and 4 deletions
|
@ -31,7 +31,7 @@ defmodule AutoLinker.Parser do
|
|||
@match_url ~r{^[\w\.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$}
|
||||
@match_scheme ~r{^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$}
|
||||
|
||||
@match_phone ~r"((?:\+|00)[17](?:[ \-\.])?|(?:\+|00)[1-9]\d{0,2}(?:[ \-\.])?|(?:\+|00)1[\-\.]\d{3}(?:[ \-\.])?)?(0\d|\([0-9]{3}\)|[1-9]{0,3})(?:((?:[ \-\.])[0-9]{2}){4}|((?:[0-9]{2}){4})|((?:[ \-\.])[0-9]{3}(?:[ \-\.])[0-9]{4})|([0-9]{7}))|(x[0-9][0-9]+)"
|
||||
@match_phone ~r"((?:x\d{2,7})|(?:(?:\+?1\s?(?:[.-]\s?)?)?(?:\(\s?(?:[2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s?\)|(?:[2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s?(?:[.-]\s?)?)(?:[2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s?(?:[.-]\s?)?(?:[0-9]{4}))"
|
||||
|
||||
@default_opts ~w(url)a
|
||||
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -1,7 +1,7 @@
|
|||
defmodule AutoLinker.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
@version "0.2.0"
|
||||
@version "0.2.1"
|
||||
|
||||
def project do
|
||||
[
|
||||
|
|
|
@ -35,7 +35,7 @@ defmodule AutoLinker.ParserTest do
|
|||
test "valid" do
|
||||
valid_phone_nunbers()
|
||||
|> Enum.each(fn number ->
|
||||
assert number |> match_phone() |> is_list
|
||||
assert number |> match_phone() |> valid_number?(number)
|
||||
end)
|
||||
end
|
||||
|
||||
|
@ -70,6 +70,12 @@ defmodule AutoLinker.ParserTest do
|
|||
end
|
||||
end
|
||||
|
||||
def valid_number?([list], number) do
|
||||
assert List.last(list) == number
|
||||
end
|
||||
|
||||
def valid_number?(_, _), do: false
|
||||
|
||||
def valid_scheme_urls, do: [
|
||||
"https://www.example.com",
|
||||
"http://www2.example.com",
|
||||
|
@ -117,7 +123,15 @@ defmodule AutoLinker.ParserTest do
|
|||
"555.555.5555",
|
||||
"613-555-5555",
|
||||
"1 (555) 555-5555",
|
||||
"(555) 555-5555"
|
||||
"(555) 555-5555",
|
||||
"1.555.555.5555",
|
||||
"800 555-5555",
|
||||
"1.800.555.5555",
|
||||
"1 (800) 555-5555",
|
||||
"888 555-5555",
|
||||
"887 555-5555",
|
||||
"1-877-555-5555",
|
||||
"1 800 710-5515"
|
||||
]
|
||||
|
||||
def invalid_phone_numbers, do: [
|
||||
|
@ -127,3 +141,4 @@ defmodule AutoLinker.ParserTest do
|
|||
]
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue