packages feed

country 0.1.6 → 0.2

raw patch · 6 files changed

+136/−39 lines, 6 filesdep +QuickCheckdep +quickcheck-classesdep +tastydep ~basenew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: QuickCheck, quickcheck-classes, tasty, tasty-quickcheck

Dependency ranges changed: base

API changes (from Hackage documentation)

- Country.Identifier: côteDIvoire :: Country
- Country.Identifier: guineaBissau :: Country
- Country.Identifier: koreaDemocraticPeopleSRepublicOf :: Country
- Country.Identifier: laoPeopleSDemocraticRepublic :: Country
- Country.Identifier: timorLeste :: Country
- Country.Identifier: virginIslandsUS :: Country
+ Country.Identifier: côteDivoire :: Country
+ Country.Identifier: guineabissau :: Country
+ Country.Identifier: koreaDemocraticPeoplesRepublicOf :: Country
+ Country.Identifier: laoPeoplesDemocraticRepublic :: Country
+ Country.Identifier: timorleste :: Country
+ Country.Identifier: virginIslandsUs :: Country

Files

country.cabal view
@@ -1,11 +1,11 @@ name: country-version: 0.1.6+version: 0.2 synopsis: Country data type and functions description:   The `country` library provides a data type for dealing with   the set of countries as defined by ISO 3166. The representation   is compact and is well-suited to use with vectors and-  primitive arrays. Additionally, this library exports functions +  primitive arrays. Additionally, this library exports functions   that provide the following encodings and decodings:   .   * ISO Alpha-2 (two-letter country code)@@ -14,6 +14,19 @@   .   * ISO Numeric (three-digit country code)   .+  .+  The main differences between this library and `iso3166-country-codes` are:+  .+  * it doesn't use an ADT to represent countries, instead it uses the country's three-digit country code.+  .+  * it doesn't use `String` for encoding/decoding+  .+  * it provides two-alpha and three-alpha country codes.+  .+  * it provides `Prim` instances from the `primitive` package to allow types to be used in unboxed vectors/arrays.+  .+  * BSD3 licence instead of LGPL+  .   Please open up an issue on github if there is anything   you would like to see added. homepage: https://github.com/andrewthad/country#readme@@ -40,14 +53,14 @@     Country.Unexposed.TrieByte     Country.Unexposed.Alias   build-depends:-      base >= 4.9.1.0 && < 4.12+      base >= 4.9.1.0 && < 4.14     , text >= 1.2 && < 1.3     , bytestring >= 0.10 && < 0.11     , deepseq >= 1.3.0.2 && < 1.5-    , primitive >= 0.6.1 && < 0.7+    , primitive >= 0.6.4 && < 0.8     , unordered-containers >= 0.2 && < 0.3     , ghc-prim >= 0.5 && < 0.6-    , hashable >= 1.2 && < 1.3+    , hashable >= 1.2 && < 1.4     , aeson >= 0.11 && < 1.5     , scientific >= 0.3 && < 0.4     , attoparsec >= 0.13 && < 0.14@@ -60,7 +73,11 @@   build-depends:       base     , country-  ghc-options: -threaded -rtsopts -with-rtsopts=-N+    , tasty+    , tasty-quickcheck+    , quickcheck-classes+    , QuickCheck+  ghc-options: -O2   default-language: Haskell2010  source-repository head
src/Country.hs view
@@ -3,6 +3,7 @@  {-# OPTIONS_GHC -Wall #-} +-- | Country type and helpers. module Country   ( Country     -- * Three digit code@@ -33,7 +34,7 @@ import Data.Word (Word16) import Data.Primitive (writeByteArray,indexByteArray,unsafeFreezeByteArray,newByteArray) import Data.Primitive.ByteArray (ByteArray(..))-import GHC.Prim (sizeofByteArray#,sizeofArray#)+import GHC.Prim (sizeofByteArray#) import GHC.Int (Int(..)) import Control.Monad.ST (runST) import Control.Monad@@ -52,7 +53,6 @@ encodeNumeric :: Country -> Word16 encodeNumeric (Country n) = n - -- | The alpha-2 country code, uppercase alphaTwoUpper :: Country -> Text alphaTwoUpper c = TI.text allAlphaTwoUpper (timesTwo (indexOfCountry c)) 2@@ -69,9 +69,11 @@ alphaThreeLower :: Country -> Text alphaThreeLower c = TI.text allAlphaThreeLower (timesThree (indexOfCountry c)) 3 +-- | Decode a 'Country' using its alpha-2 country code. decodeAlphaTwo :: Text -> Maybe Country decodeAlphaTwo = flip HM.lookup alphaTwoHashMap +-- | Decode a 'Country' using its alpha-3 country code. decodeAlphaThree :: Text -> Maybe Country decodeAlphaThree = flip HM.lookup alphaThreeHashMap @@ -94,6 +96,7 @@ decode :: Text -> Maybe Country decode = flip HM.lookup decodeMap +-- | Decode a 'Country' from a UTF-8-encoded 'ByteString'. decodeUtf8 :: ByteString -> Maybe Country decodeUtf8 = flip HM.lookup decodeMapUtf8 @@ -105,6 +108,7 @@ parser :: AT.Parser Country parser = coerce (trieParser decodeTrie) +-- | Parse a 'Country' using an 'AB.Parser'. parserUtf8 :: AB.Parser Country parserUtf8 = coerce (trieByteParser decodeTrieUtf8) @@ -116,16 +120,6 @@  word16ToChar :: Word16 -> Char word16ToChar = chr . fromIntegral---- arrayFoldl' :: (a -> b -> a) -> a -> Array b -> a--- arrayFoldl' f z a = go 0 z---   where---   go i !acc | i < sizeofArray a = go (i+1) (f acc $ indexArray a i)---             | otherwise         = acc---- sizeofArray :: Array a -> Int--- sizeofArray (Array a) = I# (sizeofArray# a)--- {-# INLINE sizeofArray #-}  numberOfCountries :: Int numberOfCountries = length countryNameQuads
src/Country/Identifier.hs view
@@ -166,8 +166,8 @@ costaRica :: Country costaRica = Country 188 -côteDIvoire :: Country-côteDIvoire = Country 384+côteDivoire :: Country+côteDivoire = Country 384  croatia :: Country croatia = Country 191@@ -283,8 +283,8 @@ guinea :: Country guinea = Country 324 -guineaBissau :: Country-guineaBissau = Country 624+guineabissau :: Country+guineabissau = Country 624  guyana :: Country guyana = Country 328@@ -355,8 +355,8 @@ kiribati :: Country kiribati = Country 296 -koreaDemocraticPeopleSRepublicOf :: Country-koreaDemocraticPeopleSRepublicOf = Country 408+koreaDemocraticPeoplesRepublicOf :: Country+koreaDemocraticPeoplesRepublicOf = Country 408  koreaRepublicOf :: Country koreaRepublicOf = Country 410@@ -367,8 +367,8 @@ kyrgyzstan :: Country kyrgyzstan = Country 417 -laoPeopleSDemocraticRepublic :: Country-laoPeopleSDemocraticRepublic = Country 418+laoPeoplesDemocraticRepublic :: Country+laoPeoplesDemocraticRepublic = Country 418  latvia :: Country latvia = Country 428@@ -667,8 +667,8 @@ thailand :: Country thailand = Country 764 -timorLeste :: Country-timorLeste = Country 626+timorleste :: Country+timorleste = Country 626  togo :: Country togo = Country 768@@ -733,8 +733,8 @@ virginIslandsBritish :: Country virginIslandsBritish = Country 92 -virginIslandsUS :: Country-virginIslandsUS = Country 850+virginIslandsUs :: Country+virginIslandsUs = Country 850  wallisAndFutuna :: Country wallisAndFutuna = Country 876
src/Country/Unexposed/Alias.hs view
@@ -13,6 +13,7 @@   , (248, T.pack "Åland Islands")   , (248, T.pack "Aaland Islands")   , (248, T.pack "Aland Islands")+  , (248, T.pack "Åland")   , (8, T.pack "Albania")   , (8, T.pack "Arbanon")   , (8, T.pack "Republic of Albania")@@ -60,10 +61,11 @@   , (204, T.pack "Benin")   , (60, T.pack "Bermuda")   , (64, T.pack "Bhutan")-  , (68, T.pack "Bolivia")   , (68, T.pack "Bolivia (Plurinational State of)")+  , (68, T.pack "Bolivia")   , (68, T.pack "Plurinational State of Bolivia")   , (535, T.pack "Bonaire, Sint Eustatius and Saba")+  , (535, T.pack "Bonaire, Sint Eustatius, and Saba")   , (70, T.pack "Bosnia and Herzegovina")   , (72, T.pack "Botswana")   , (74, T.pack "Bouvet Island")@@ -78,6 +80,7 @@   , (76, T.pack "United States of Brazil")   , (86, T.pack "British Indian Ocean Territory")   , (96, T.pack "Brunei Darussalam")+  , (96, T.pack "Brunei")   , (100, T.pack "Bulgaria")   , (854, T.pack "Burkina Faso")   , (108, T.pack "Burundi")@@ -101,9 +104,13 @@   , (156, T.pack "China")   , (162, T.pack "Christmas Island")   , (166, T.pack "Cocos (Keeling) Islands")+  , (166, T.pack "Cocos Islands")+  , (166, T.pack "Cocos [Keeling] Islands")+  , (166, T.pack "Keeling Islands")   , (170, T.pack "Colombia")   , (174, T.pack "Comoros")   , (178, T.pack "Congo")+  , (178, T.pack "Republic of the Congo")   , (180, T.pack "Congo (Democratic Republic of the)")   , (184, T.pack "Cook Islands")   , (188, T.pack "Costa Rica")@@ -115,6 +122,9 @@   , (531, T.pack "Curaçao")   , (196, T.pack "Cyprus")   , (203, T.pack "Czech Republic")+  , (203, T.pack "Czechia")+  , (203, T.pack "Česko")+  , (203, T.pack "Česká republika")   , (208, T.pack "Denmark")   , (208, T.pack "Danmark")   , (208, T.pack "Kingdom of Denmark")@@ -139,6 +149,8 @@   , (233, T.pack "Estonia")   , (231, T.pack "Ethiopia")   , (238, T.pack "Falkland Islands (Malvinas)")+  , (238, T.pack "Falkland Islands")+  , (238, T.pack "Falkland Islands [Malvinas]")   , (234, T.pack "Faroe Islands")   , (242, T.pack "Fiji")   , (246, T.pack "Finland")@@ -174,6 +186,8 @@   , (332, T.pack "Haiti")   , (334, T.pack "Heard Island and McDonald Islands")   , (336, T.pack "Holy See")+  , (336, T.pack "Vatican")+  , (336, T.pack "Vatican City")   , (340, T.pack "Honduras")   , (344, T.pack "Hong Kong")   , (348, T.pack "Hungary")@@ -198,6 +212,11 @@   , (356, T.pack "ഇന്ത്യ")   , (360, T.pack "Indonesia")   , (364, T.pack "Iran (Islamic Republic of)")+  , (364, T.pack "Faris")+  , (364, T.pack "Iran")+  , (364, T.pack "Islamic Republic of Iran")+  , (364, T.pack "Persia")+  , (364, T.pack "The Islamic Republic of Iran")   , (368, T.pack "Iraq")   , (368, T.pack "Assyria")   , (368, T.pack "Babylon")@@ -239,12 +258,19 @@   , (404, T.pack "Republic of Kenya")   , (296, T.pack "Kiribati")   , (408, T.pack "Korea (Democratic People's Republic of)")+  , (408, T.pack "Choson Minjujuui Inmin Konghwaguk")+  , (408, T.pack "D.P.R.K.")+  , (408, T.pack "DPRK")+  , (408, T.pack "Democratic People's Republic of Korea")   , (408, T.pack "North Korea")+  , (408, T.pack "조선민주주의인민공화국")   , (410, T.pack "Korea (Republic of)")+  , (410, T.pack "Republic of Korea")   , (410, T.pack "South Korea")   , (414, T.pack "Kuwait")   , (417, T.pack "Kyrgyzstan")   , (418, T.pack "Lao People's Democratic Republic")+  , (418, T.pack "Laos")   , (428, T.pack "Latvia")   , (428, T.pack "Latvija")   , (428, T.pack "Letland")@@ -260,6 +286,8 @@   , (438, T.pack "Liechtenstein")   , (440, T.pack "Lithuania")   , (440, T.pack "Lietuva")+  , (440, T.pack "Lithuania, Republic of")+  , (440, T.pack "Republic of Lithuania")   , (440, T.pack "Литва")   , (442, T.pack "Luxembourg")   , (442, T.pack "Grand Duchy of Luxembourg")@@ -270,8 +298,8 @@   , (442, T.pack "Luxemburg")   , (442, T.pack "Luxemburgo")   , (446, T.pack "Macao")-  , (807, T.pack "Macedonia")   , (807, T.pack "Macedonia (the former Yugoslav Republic of)")+  , (807, T.pack "Macedonia")   , (450, T.pack "Madagascar")   , (454, T.pack "Malawi")   , (454, T.pack "Nyasaland")@@ -309,7 +337,11 @@   , (484, T.pack "República Mexicana")   , (484, T.pack "United Mexican States")   , (583, T.pack "Micronesia (Federated States of)")+  , (583, T.pack "Federated States of Micronesia")+  , (583, T.pack "Micronesia")   , (498, T.pack "Moldova (Republic of)")+  , (498, T.pack "Moldova")+  , (498, T.pack "Republic of Moldova")   , (492, T.pack "Monaco")   , (492, T.pack "Principality of Monaco")   , (492, T.pack "Principauté de Monaco")@@ -323,6 +355,9 @@   , (504, T.pack "Morocco")   , (508, T.pack "Mozambique")   , (104, T.pack "Myanmar")+  , (104, T.pack "Burma")+  , (104, T.pack "Myanmar (Burma)")+  , (104, T.pack "Myanmar [Burma]")   , (516, T.pack "Namibia")   , (520, T.pack "Nauru")   , (524, T.pack "Nepal")@@ -347,6 +382,7 @@   , (604, T.pack "Peru")   , (608, T.pack "Philippines")   , (612, T.pack "Pitcairn")+  , (612, T.pack "Pitcairn Islands")   , (616, T.pack "Poland")   , (620, T.pack "Portugal")   , (630, T.pack "Puerto Rico")@@ -392,17 +428,25 @@   , (646, T.pack "Rwandese Republic")   , (646, T.pack "République du Rwanda")   , (652, T.pack "Saint Barthélemy")+  , (652, T.pack "Saint-Barthélemy")   , (654, T.pack "Saint Helena, Ascension and Tristan da Cunha")+  , (654, T.pack "Saint Helena")   , (659, T.pack "Saint Kitts and Nevis")   , (659, T.pack "Federation of Saint Kitts and Nevis")   , (659, T.pack "Saint Kitts-Nevis-Anguilla")+  , (659, T.pack "St Kitts and Nevis")+  , (659, T.pack "St. Kitts and Nevis")   , (662, T.pack "Saint Lucia")   , (663, T.pack "Saint Martin (French part)")+  , (663, T.pack "Saint Martin")+  , (663, T.pack "St Martin")+  , (663, T.pack "St. Martin")   , (666, T.pack "Saint Pierre and Miquelon")   , (670, T.pack "Saint Vincent and the Grenadines")   , (882, T.pack "Samoa")   , (674, T.pack "San Marino")   , (678, T.pack "Sao Tome and Principe")+  , (678, T.pack "São Tomé and Príncipe")   , (682, T.pack "Saudi Arabia")   , (686, T.pack "Senegal")   , (688, T.pack "Serbia")@@ -414,6 +458,7 @@   , (702, T.pack "Singapura")   , (702, T.pack "Yugoslavia")   , (534, T.pack "Sint Maarten (Dutch part)")+  , (534, T.pack "Sint Maarten")   , (703, T.pack "Slovakia")   , (705, T.pack "Slovenia")   , (90, T.pack "Solomon Islands")@@ -463,17 +508,23 @@   , (756, T.pack "Svizzera")   , (756, T.pack "Swiss Confederation")   , (760, T.pack "Syrian Arab Republic")+  , (760, T.pack "Syria")   , (158, T.pack "Taiwan, Province of China")   , (158, T.pack "Chinese Taipei")+  , (158, T.pack "People's Republic of China")   , (158, T.pack "Republic of China")   , (158, T.pack "Separate Customs Territory of Taiwan, Penghu, Kinmen and Matsu")   , (158, T.pack "Taiwan")+  , (158, T.pack "The People's Republic of China")   , (158, T.pack "Zhonggua Taipei")   , (158, T.pack "中華台北")   , (762, T.pack "Tajikistan")   , (834, T.pack "Tanzania, United Republic of")+  , (834, T.pack "Tanzania")+  , (834, T.pack "United Republic of Tanganyika and Zanzibar")   , (764, T.pack "Thailand")   , (626, T.pack "Timor-Leste")+  , (626, T.pack "Democratic Republic of Timor-Leste")   , (768, T.pack "Togo")   , (772, T.pack "Tokelau")   , (776, T.pack "Tonga")@@ -510,18 +561,24 @@   , (840, T.pack "Usa")   , (840, T.pack "Usono")   , (581, T.pack "United States Minor Outlying Islands")+  , (581, T.pack "U.S. Minor Outlying Islands")   , (858, T.pack "Uruguay")   , (860, T.pack "Uzbekistan")   , (548, T.pack "Vanuatu")   , (548, T.pack "Ripablik blong Vanuatu")   , (548, T.pack "République de Vanuatu")-  , (862, T.pack "Venezuela")   , (862, T.pack "Venezuela (Bolivarian Republic of)")   , (862, T.pack "Bolivarian Republic of Venezuela")   , (862, T.pack "República Bolivariana de Venezuela")+  , (862, T.pack "Venezuela")   , (704, T.pack "Viet Nam")+  , (704, T.pack "Cộng hòa Xã hội Chủ nghĩa Việt Nam")+  , (704, T.pack "Vietnam")+  , (704, T.pack "Việt Nam")   , (92, T.pack "Virgin Islands (British)")+  , (92, T.pack "British Virgin Islands")   , (850, T.pack "Virgin Islands (U.S.)")+  , (850, T.pack "U.S. Virgin Islands")   , (876, T.pack "Wallis and Futuna")   , (732, T.pack "Western Sahara")   , (887, T.pack "Yemen")
src/Country/Unexposed/Names.hs view
@@ -5,6 +5,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE TypeInType #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DeriveDataTypeable #-}  {-# OPTIONS_HADDOCK not-home #-} @@ -49,6 +50,7 @@ import qualified Data.Text as T import qualified Data.Scientific as SCI import GHC.Generics (Generic)+import Data.Data  -- | The name of a country given in English encodeEnglish :: Country -> Text@@ -85,7 +87,7 @@ word16ToInt = fromIntegral  decodeMap :: HashMap Text Country-decodeMap = +decodeMap =   let baseMap = HM.union alphaTwoHashMap alphaThreeHashMap       hm1 = L.foldl' (\hm (countryNum,name) -> HM.insert name (Country countryNum) hm) baseMap aliases       hm2 = L.foldl' (\hm (countryNum,name,_,_) -> HM.insert name (Country countryNum) hm) hm1 countryNameQuads@@ -109,7 +111,7 @@  -- | A country recognized by ISO 3166. newtype Country = Country Word16-  deriving (Eq,Ord,Prim,Hashable,Storable,NFData,Generic)+  deriving (Eq,Ord,Prim,Hashable,Storable,NFData,Generic,Data,Typeable)  instance Show Country where   show (Country n) = T.unpack (indexArray englishIdentifierNamesText (word16ToInt n))@@ -119,7 +121,6 @@   toEnum number = if number >= 0 && number < actualNumberOfCountries     then Country (indexByteArray sequentialToCountryCodeMapping number)     else error ("toEnum: cannot convert " ++ show number ++ " to Country")- instance Bounded Country where   minBound = Country (indexByteArray sequentialToCountryCodeMapping 0)   maxBound = Country (indexByteArray sequentialToCountryCodeMapping (actualNumberOfCountries - 1))@@ -146,8 +147,8 @@ actualNumberOfCountries :: Int actualNumberOfCountries = length countryNameQuads {-# NOINLINE actualNumberOfCountries #-}-   + codeToEnum :: Word16 -> Int codeToEnum w = indexByteArray countryCodeToSequentialMapping (word16ToInt w) @@ -203,7 +204,7 @@  alphaThreeHashMap :: HashMap Text Country alphaThreeHashMap = L.foldl'-  (\hm (countryNum,_,_,(c1,c2,c3)) -> +  (\hm (countryNum,_,_,(c1,c2,c3)) ->       HM.insert (T.pack [c1,c2,c3]) (Country countryNum)     $ HM.insert (T.pack [toLower c1, toLower c2, toLower c3]) (Country countryNum)     $ hm
test/Spec.hs view
@@ -1,2 +1,30 @@+import Country (Country)+import Data.Proxy (Proxy(..))+import Test.Tasty (defaultMain,testGroup,TestTree)++import qualified Test.QuickCheck.Classes as QCC+import qualified Test.QuickCheck.Classes.IsList as QCCL+import qualified Test.Tasty.QuickCheck as TQC+import qualified Test.QuickCheck as QC+ main :: IO ()-main = putStrLn "Test suite not yet implemented"+main = defaultMain+  $ testGroup "Country"+  $ map lawsToTest+  $ map ($ proxy)+  $ [ QCC.boundedEnumLaws+    , QCC.eqLaws+    , QCC.ordLaws+    , QCC.primLaws+    , QCC.showLaws+    , QCC.storableLaws+    ]++proxy :: Proxy Country+proxy = Proxy++lawsToTest :: QCC.Laws -> TestTree+lawsToTest (QCC.Laws name pairs) = testGroup name (map (uncurry TQC.testProperty) pairs)++instance QC.Arbitrary Country where+  arbitrary = QC.arbitraryBoundedEnum