2016-08-17 11:14:17 +00:00
|
|
|
port module Main exposing (..)
|
2015-10-13 23:05:05 +00:00
|
|
|
|
2016-08-17 11:14:17 +00:00
|
|
|
import Test.Runner.Node exposing (run)
|
|
|
|
import Json.Encode exposing (Value)
|
|
|
|
import Test exposing (..)
|
|
|
|
import Expect
|
2016-03-17 01:33:59 +00:00
|
|
|
import PhoneNumber exposing (getNumber, prettyPrint)
|
2015-10-13 23:05:05 +00:00
|
|
|
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2015-10-13 23:05:05 +00:00
|
|
|
tests : Test
|
2016-03-17 01:38:51 +00:00
|
|
|
tests =
|
2016-08-17 11:14:17 +00:00
|
|
|
describe "PhoneNumber"
|
|
|
|
[ test "cleans number" <|
|
|
|
|
\() -> Expect.equal (Just "1234567890") (getNumber "(123) 456-7890")
|
|
|
|
, test "cleans number with dots" <|
|
|
|
|
\() -> Expect.equal (Just "1234567890") (getNumber "123.456.7890")
|
|
|
|
, test "valid when 11 digits and first is 1" <|
|
|
|
|
\() -> Expect.equal (Just "1234567890") (getNumber "11234567890")
|
|
|
|
, test "invalid when 11 digits" <|
|
|
|
|
\() -> Expect.equal Nothing (getNumber "21234567890")
|
|
|
|
, test "invalid when 9 digits" <|
|
|
|
|
\() -> Expect.equal Nothing (getNumber "123456789")
|
|
|
|
, test "invalid when 12 digits" <|
|
|
|
|
\() -> Expect.equal Nothing (getNumber "123456789012")
|
|
|
|
, test "invalid when empty" <|
|
|
|
|
\() -> Expect.equal Nothing (getNumber "")
|
|
|
|
, test "invalid when no digits present" <|
|
|
|
|
\() -> Expect.equal Nothing (getNumber " (-) ")
|
|
|
|
, test "valid with leading characters" <|
|
|
|
|
\() -> Expect.equal (Just "1234567890") (getNumber "my number is 123 456 7890")
|
|
|
|
, test "valid with trailing characters" <|
|
|
|
|
\() -> Expect.equal (Just "1234567890") (getNumber "123 456 7890 - bob")
|
|
|
|
, test "pretty print" <|
|
|
|
|
\() -> Expect.equal (Just "(123) 456-7890") (prettyPrint "1234567890")
|
|
|
|
, test "pretty print with full us phone number" <|
|
|
|
|
\() -> Expect.equal (Just "(123) 456-7890") (prettyPrint "11234567890")
|
2016-06-19 21:46:13 +00:00
|
|
|
]
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2015-10-13 23:05:05 +00:00
|
|
|
|
2016-05-13 02:26:52 +00:00
|
|
|
main : Program Never
|
|
|
|
main =
|
2016-08-17 11:14:17 +00:00
|
|
|
run emit tests
|
|
|
|
|
|
|
|
|
|
|
|
port emit : ( String, Value ) -> Cmd msg
|