2016-03-17 01:38:35 +00:00
|
|
|
module Main (..) where
|
2015-10-13 23:05:05 +00:00
|
|
|
|
2016-03-17 01:38:35 +00:00
|
|
|
import Task
|
|
|
|
import Console
|
|
|
|
import ElmTest exposing (..)
|
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 =
|
|
|
|
suite
|
|
|
|
"PhoneNumber"
|
|
|
|
[ test
|
|
|
|
"cleans number"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual (Just "1234567890") (getNumber "(123) 456-7890"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"cleans number with dots"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual (Just "1234567890") (getNumber "123.456.7890"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"valid when 11 digits and first is 1"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual (Just "1234567890") (getNumber "11234567890"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"invalid when 11 digits"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual Nothing (getNumber "21234567890"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"invalid when 9 digits"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual Nothing (getNumber "123456789"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"invalid when 12 digits"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual Nothing (getNumber "123456789012"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"invalid when empty"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual Nothing (getNumber ""))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"invalid when no digits present"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual Nothing (getNumber " (-) "))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"valid with leading characters"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual (Just "1234567890") (getNumber "my number is 123 456 7890"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"valid with trailing characters"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual (Just "1234567890") (getNumber "123 456 7890 - bob"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"pretty print"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual (Just "(123) 456-7890") (prettyPrint "1234567890"))
|
2016-03-17 01:38:51 +00:00
|
|
|
, test
|
|
|
|
"pretty print with full us phone number"
|
2016-03-17 01:33:59 +00:00
|
|
|
(assertEqual (Just "(123) 456-7890") (prettyPrint "11234567890"))
|
2016-03-17 01:38:51 +00:00
|
|
|
]
|
|
|
|
|
2015-10-13 23:05:05 +00:00
|
|
|
|
2016-03-17 01:38:35 +00:00
|
|
|
port runner : Signal (Task.Task x ())
|
|
|
|
port runner =
|
|
|
|
Console.run (consoleRunner tests)
|