@@ -53,11 +53,13 @@ data ParsedNumber = ParsedNumber (ParseMode, Maybe Region, ParserInput) PhoneNum
53 deriving stock (Show)
53 deriving stock (Show)
55instance Arbitrary ParsedNumber where
55instance Arbitrary ParsedNumber where
56− arbitrary = liftA3 (,,) (elements [Canonicalize, KeepRawInput]) arbitrary arbitrary
57+ mode <- elements [Canonicalize, KeepRawInput]
58+ liftA2 ((,,) mode) arbitrary arbitrary
57− `suchThatMap` \(mode, MReg mRegion, ParserInput input) ->
59+ `suchThatMap` \(_, MReg mRegion, ParserInput input) ->
58− case parseNumber mode mRegion input of
60+ case parseNumber mode mRegion input of
59− Right pn -> Just $ ParsedNumber (mode, mRegion, ParserInput input) pn
61+ Right pn -> Just $ ParsedNumber (mode, mRegion, ParserInput input) pn
60− _ -> Nothing
62+ _ -> Nothing
61 shrink (ParsedNumber (mode, region, input) _) = do
63 shrink (ParsedNumber (mode, region, input) _) = do
62 ParserInput input' <- shrink input
64 ParserInput input' <- shrink input
63 case parseNumber mode region input' of
65 case parseNumber mode region input' of
@@ -113,7 +115,7 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
113 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
115 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
114 describe "Dialable" $ do
116 describe "Dialable" $ do
115 -- PhoneNumberUtil::NormalizeDiallableCharsOnly will error on any invalid UTF8
117 -- PhoneNumberUtil::NormalizeDiallableCharsOnly will error on any invalid UTF8
116− xprop "doesn't randomly fail" $ \str ->
118+ prop "doesn't randomly fail" $ \str ->
117 not (BS.null $ normalizeNumber Digits $ "0" <> BS.pack str)
119 not (BS.null $ normalizeNumber Digits $ "0" <> BS.pack str)
118 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
120 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
@@ -123,15 +125,9 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
123 prop "returns only ASCII digits" $ \(ParsedNumber _ pn) ->
125 prop "returns only ASCII digits" $ \(ParsedNumber _ pn) ->
124 BSC.all (`elem` ['0'..'9']) $ nationalSignificantNumber pn
126 BSC.all (`elem` ['0'..'9']) $ nationalSignificantNumber pn
125 modifyMaxDiscardRatio (* 10) $ do
127 modifyMaxDiscardRatio (* 10) $ do
126− prop "concatenated with country code parses to the original (if valid and not MX)" $
128+ prop "concatenated with country code parses to the original (if valid)" $
127− \(ParsedNumber (_, mReg, ParserInput input) pn) ->
129+ \(ParsedNumber _ pn) ->
128− -- Apparently "+52112210000000" makes the parser/formatter do weird
129− -- stuff as it tries to handle the deprecated (?) mobile token ("1"
131− if "5211" `BS.isPrefixOf` normalizeNumber Digits input ||
132− mReg == Just "MX" && "11" `BS.isPrefixOf` normalizeNumber Digits input
134− else isValidNumber Nothing pn ==>
130+ isValidNumber Nothing pn ==>
136 cc = countryCode pn
132 cc = countryCode pn
137 nsn = nationalSignificantNumber pn
133 nsn = nationalSignificantNumber pn
@@ -155,14 +151,19 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
155 extension pn == Nothing ==>
151 extension pn == Nothing ==>
156 isRight $ parseNumber Canonicalize Nothing
152 isRight $ parseNumber Canonicalize Nothing
157 $ formatNumber International pn
153 $ formatNumber International pn
154+ modifyMaxDiscardRatio (* 10) $ do
158− prop "with E164 produces a parseable result" $
155+ prop "with E164 produces a parseable result (if Canonicalize)" $
156+ \(ParsedNumber (mode, _, _) pn) ->
157+ -- KeepRawInput with pn == "0000" breaks E164 formatting
159− \(ParsedNumber _ pn) -> possibleNumber Unknown pn == IsPossible ==>
158+ possibleNumber Unknown pn == IsPossible && mode == Canonicalize ==>
160− isRight $ parseNumber Canonicalize Nothing
159+ isRight $ parseNumber Canonicalize Nothing
161− $ formatNumber E164 pn
160+ $ formatNumber E164 pn
162− prop "with RFC3966 produces a parseable result" $
161+ prop "with RFC3966 produces a parseable result (if Canonicalize)" $
162+ \(ParsedNumber (mode, _, _) pn) ->
163+ -- KeepRawInput with pn == "0000" breaks RFC3966 formatting
163− \(ParsedNumber _ pn) -> possibleNumber Unknown pn == IsPossible ==>
164+ possibleNumber Unknown pn == IsPossible && mode == Canonicalize ==>
164− isRight $ parseNumber Canonicalize Nothing
165+ isRight $ parseNumber Canonicalize Nothing
165− $ formatNumber RFC3966 pn
166+ $ formatNumber RFC3966 pn
167 describe "truncateTooLongNumber" $ do
168 describe "truncateTooLongNumber" $ do