git.iko.soy/typeable/libphonenumber
on 5ea8441 help sign in
4 files changed+53−56
since splitsnapshots
unifiedsplit
.github/workflows/ci.yaml+8−12 libphonenumber.cabal+12−16 src/Data/PhoneNumber/Number.hs+10−4 test/Spec.hs+23−24
.github/workflows/ci.yaml+8−12
@@ -22,19 +22,15 @@ jobs:
2222 - "8.8.4"
2323 - "8.10.7"
2424 - "9.0.2"
25− - "9.2.8"
26− - "9.4.8"
27− - "9.6.7"
28− - "9.8.4"
29− - "9.10.3"
30− - "9.12.2"
31− - "9.14.1"
25+ - "9.2.7"
26+ - "9.4.4"
27+ - "9.6.1"
3228 fail-fast: false
3329 name: Build on Linux, GHC ${{ matrix.ghc_version }}
3430 runs-on: ${{ matrix.platform }}
3531 steps:
36− - uses: actions/checkout@v4
37− - uses: haskell-actions/setup@v2
32+ - uses: actions/checkout@v3
33+ - uses: haskell/actions/setup@v2
3834 with:
3935 ghc-version: ${{ matrix.ghc_version }}
4036 cabal-version: "3.10.1.0"
@@ -70,7 +66,7 @@ jobs:
7066 if: github.event_name == 'release'
7167 steps:
7268 - uses: actions/checkout@v3
73− - uses: haskell-actions/setup@v2
69+ - uses: haskell/actions/setup@v2
7470 with:
7571 cabal-version: "3.10.1.0"
7672 - name: Install C++ library
@@ -85,11 +81,11 @@ jobs:
8581 run: |
8682 cabal haddock --builddir "$GITHUB_WORKSPACE/doc" --haddock-for-hackage --enable-doc
8783 echo "docs=$(find "$GITHUB_WORKSPACE/doc" -maxdepth 1 -type f -name '*-docs.tar.gz')" >> "$GITHUB_ENV"
88− - uses: actions/upload-artifact@v6
84+ - uses: actions/upload-artifact@v2
8985 with:
9086 name: Source tarball
9187 path: ${{ env.dist }}
92− - uses: svenstaro/upload-release-action@2.11.3
88+ - uses: svenstaro/upload-release-action@2.2.1
9389 with:
9490 repo_token: ${{ secrets.GITHUB_TOKEN }}
9591 file: ${{ env.dist }}
libphonenumber.cabal+12−16
@@ -1,6 +1,6 @@
11cabal-version: 3.0
22name: libphonenumber
3−version: 0.1.4.0
3+version: 0.1.1.0
44category: Data
55synopsis: Parsing, formatting, and validating international phone
66 numbers
@@ -25,7 +25,7 @@ description:
2525 and to avoid a dependency on @text@, we use 'ByteString'
2626 throughout the library instead of 'Data.Text.Text'.
2727
28−copyright: 2023-2025 Typeable
28+copyright: 2023 Typeable
2929author: Typeable
3030maintainer: mniip@typeable.io
3131homepage: https://github.com/typeable/libphonenumber/
@@ -37,13 +37,9 @@ tested-with:
3737 , GHC == 8.8.4
3838 , GHC == 8.10.7
3939 , GHC == 9.0.2
40− , GHC == 9.2.8
41− , GHC == 9.4.8
42− , GHC == 9.6.7
43− , GHC == 9.8.4
44− , GHC == 9.10.3
45− , GHC == 9.12.2
46− , GHC == 9.14.1
40+ , GHC == 9.2.7
41+ , GHC == 9.4.4
42+ , GHC == 9.6.1
4743
4844build-type: Simple
4945
@@ -64,13 +60,12 @@ library
6460 , Data.PhoneNumber.Internal.Number
6561 , Data.PhoneNumber.Internal.Util
6662 build-depends:
67− , base >= 4.12 && < 4.23
68− , bytestring >= 0.10.8 && < 0.13
69− , containers >= 0.6.0 && < 0.9
70− , deepseq >= 1.4.4 && < 1.6
63+ , base >= 4.12 && < 4.19
64+ , bytestring >= 0.10.8 && < 0.12
65+ , containers >= 0.6.0 && < 0.7
66+ , deepseq >= 1.4.4 && < 1.5
7167 , transformers >= 0.5.5 && < 0.7
7268 build-tool-depends: c2hs:c2hs
73− pkgconfig-depends: protobuf
7469 include-dirs: include
7570 includes:
7671 , c_phonenumber.h
@@ -80,6 +75,7 @@ library
8075 , cxxbits/c_phonenumberutil.cpp
8176 extra-libraries:
8277 , phonenumber
78+ , protobuf
8379 if impl(ghc >= 9.4)
8480 build-depends: system-cxx-std-lib
8581 else
@@ -109,9 +105,9 @@ test-suite spec_test
109105 , base
110106 , bytestring
111107 , containers
112− , hspec >= 2.10.8 && < 2.12
108+ , hspec >= 2.10.8 && < 2.11
113109 , libphonenumber
114− , QuickCheck >= 2.13.1 && < 2.16
110+ , QuickCheck >= 2.13.1 && < 2.15
115111 main-is: Spec.hs
116112 hs-source-dirs: test
117113 default-language: Haskell2010
src/Data/PhoneNumber/Number.hs+10−4
@@ -21,10 +21,16 @@ module Data.PhoneNumber.Number
2121 ) where
2222
2323import Data.ByteString (ByteString)
24−import Data.PhoneNumber.Internal.Number
25− ( CPhoneNumber(CPhoneNumber), PhoneNumber, CountryCodeSource, toCPhoneNumber
26− , fromCPhoneNumber
27− )
24+import Data.PhoneNumber.Internal.Number hiding
25+ ( pattern PhoneNumber
26+ , extension
27+ , rawInput
28+ , preferredDomesticCarrierCode
29+ , nationalNumber
30+ , countryCode
31+ , italianLeadingZero
32+ , countryCodeSource
33+ , numberOfLeadingZeros )
2834import qualified Data.PhoneNumber.Internal.Number as I
2935
3036-- | A country calling code (International Subscriber Dialing code, ISD code),
test/Spec.hs+23−24
@@ -53,13 +53,11 @@ data ParsedNumber = ParsedNumber (ParseMode, Maybe Region, ParserInput) PhoneNum
5353 deriving stock (Show)
5454
5555instance Arbitrary ParsedNumber where
56− arbitrary = do
57− mode <- elements [Canonicalize, KeepRawInput]
58− liftA2 ((,,) mode) arbitrary arbitrary
59− `suchThatMap` \(_, MReg mRegion, ParserInput input) ->
60− case parseNumber mode mRegion input of
61− Right pn -> Just $ ParsedNumber (mode, mRegion, ParserInput input) pn
62− _ -> Nothing
56+ arbitrary = liftA3 (,,) (elements [Canonicalize, KeepRawInput]) arbitrary arbitrary
57+ `suchThatMap` \(mode, MReg mRegion, ParserInput input) ->
58+ case parseNumber mode mRegion input of
59+ Right pn -> Just $ ParsedNumber (mode, mRegion, ParserInput input) pn
60+ _ -> Nothing
6361 shrink (ParsedNumber (mode, region, input) _) = do
6462 ParserInput input' <- shrink input
6563 case parseNumber mode region input' of
@@ -115,7 +113,7 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
115113 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
116114 describe "Dialable" $ do
117115 -- PhoneNumberUtil::NormalizeDiallableCharsOnly will error on any invalid UTF8
118− prop "doesn't randomly fail" $ \str ->
116+ xprop "doesn't randomly fail" $ \str ->
119117 not (BS.null $ normalizeNumber Digits $ "0" <> BS.pack str)
120118 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
121119
@@ -125,9 +123,15 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
125123 prop "returns only ASCII digits" $ \(ParsedNumber _ pn) ->
126124 BSC.all (`elem` ['0'..'9']) $ nationalSignificantNumber pn
127125 modifyMaxDiscardRatio (* 10) $ do
128− prop "concatenated with country code parses to the original (if valid)" $
129− \(ParsedNumber _ pn) ->
130− isValidNumber Nothing pn ==>
126+ prop "concatenated with country code parses to the original (if valid and not MX)" $
127+ \(ParsedNumber (_, mReg, ParserInput input) pn) ->
128+ -- Apparently "+52112210000000" makes the parser/formatter do weird
129+ -- stuff as it tries to handle the deprecated (?) mobile token ("1"
130+ -- after "+52")
131+ if "5211" `BS.isPrefixOf` normalizeNumber Digits input ||
132+ mReg == Just "MX" && "11" `BS.isPrefixOf` normalizeNumber Digits input
133+ then discard
134+ else isValidNumber Nothing pn ==>
131135 let
132136 cc = countryCode pn
133137 nsn = nationalSignificantNumber pn
@@ -151,19 +155,14 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
151155 extension pn == Nothing ==>
152156 isRight $ parseNumber Canonicalize Nothing
153157 $ formatNumber International pn
154− modifyMaxDiscardRatio (* 10) $ do
155− prop "with E164 produces a parseable result (if Canonicalize)" $
156− \(ParsedNumber (mode, _, _) pn) ->
157− -- KeepRawInput with pn == "0000" breaks E164 formatting
158− possibleNumber Unknown pn == IsPossible && mode == Canonicalize ==>
159− isRight $ parseNumber Canonicalize Nothing
160− $ formatNumber E164 pn
161− prop "with RFC3966 produces a parseable result (if Canonicalize)" $
162− \(ParsedNumber (mode, _, _) pn) ->
163− -- KeepRawInput with pn == "0000" breaks RFC3966 formatting
164− possibleNumber Unknown pn == IsPossible && mode == Canonicalize ==>
165− isRight $ parseNumber Canonicalize Nothing
166− $ formatNumber RFC3966 pn
158+ prop "with E164 produces a parseable result" $
159+ \(ParsedNumber _ pn) -> possibleNumber Unknown pn == IsPossible ==>
160+ isRight $ parseNumber Canonicalize Nothing
161+ $ formatNumber E164 pn
162+ prop "with RFC3966 produces a parseable result" $
163+ \(ParsedNumber _ pn) -> possibleNumber Unknown pn == IsPossible ==>
164+ isRight $ parseNumber Canonicalize Nothing
165+ $ formatNumber RFC3966 pn
167166
168167 describe "truncateTooLongNumber" $ do
169168 pure ()