bcp47-orphans (empty) → 0.1.0.1
raw patch · 16 files changed
+252/−0 lines, 16 filesdep +QuickCheckdep +basedep +bcp47setup-changed
Dependencies added: QuickCheck, base, bcp47, bcp47-orphans, cassava, errors, esqueleto, hashable, hspec, http-api-data, path-pieces, persistent, text
Files
- ChangeLog.md +11/−0
- LICENSE +19/−0
- README.md +3/−0
- Setup.hs +2/−0
- bcp47-orphans.cabal +67/−0
- library/Data/BCP47/Csv.hs +15/−0
- library/Data/BCP47/Esqueleto.hs +9/−0
- library/Data/BCP47/Hashable.hs +9/−0
- library/Data/BCP47/HttpApiData.hs +14/−0
- library/Data/BCP47/PathPieces.hs +11/−0
- library/Data/BCP47/Persist.hs +20/−0
- tests/Data/BCP47/CsvSpec.hs +21/−0
- tests/Data/BCP47/PathPiecesSpec.hs +17/−0
- tests/Data/BCP47/PersistSpec.hs +17/−0
- tests/Data/BCP47/Roundtrip.hs +16/−0
- tests/Main.hs +1/−0
+ ChangeLog.md view
@@ -0,0 +1,11 @@+## [*Unreleased*](https://github.com/freckle/bcp47/compare/bcp47-orphans-v0.1.0.1...master)++None++## [v0.1.0.1](https://github.com/freckle/bcp47/compare/bcp47-orphans-v0.1.0.0...bcp47-orphans-v0.1.0.1)++- Instances for `HttpApiData` [#10](https://github.com/freckle/bcp47/pull/10)++## [v0.1.0.0](https://github.com/freckle/bcp47/tree/v0.1.0.0)++First tagged release.
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright 2018 Freckle++Permission is hereby granted, free of charge, to any person obtaining a copy of+this software and associated documentation files (the "Software"), to deal in+the Software without restriction, including without limitation the rights to+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies+of the Software, and to permit persons to whom the Software is furnished to do+so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,3 @@+# bcp47-orphans++Orphan instances for the `BCP47` type
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ bcp47-orphans.cabal view
@@ -0,0 +1,67 @@+cabal-version: 1.12+name: bcp47-orphans+version: 0.1.0.1+license: MIT+license-file: LICENSE+copyright: 2019 Freckle Education+maintainer: engineering@freckle.com+author: Evan Rutledge Borden+homepage: https://github.com/freckle/bcp47#readme+bug-reports: https://github.com/freckle/bcp47/issues+synopsis: BCP47 orphan instances+description: Orphan instances for the BCP47 type+category: Orphan Instances+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://github.com/freckle/bcp47++library+ exposed-modules:+ Data.BCP47.Csv+ Data.BCP47.Esqueleto+ Data.BCP47.Hashable+ Data.BCP47.HttpApiData+ Data.BCP47.PathPieces+ Data.BCP47.Persist++ hs-source-dirs: library+ other-modules: Paths_bcp47_orphans+ default-language: Haskell2010+ build-depends:+ base >=4.7 && <5,+ bcp47 >=0.2.0.0 && <0.3,+ cassava >=0.5.2.0 && <0.6,+ errors >=2.3.0 && <2.4,+ esqueleto >=3.3.4.1 && <3.4,+ hashable >=1.3.0.0 && <1.4,+ http-api-data >=0.4.1.1 && <0.5,+ path-pieces >=0.2.1 && <0.3,+ persistent >=2.10.5.3 && <2.11,+ text >=1.2.4.0 && <1.3++test-suite spec+ type: exitcode-stdio-1.0+ main-is: Main.hs+ hs-source-dirs: tests+ other-modules:+ Data.BCP47.CsvSpec+ Data.BCP47.PathPiecesSpec+ Data.BCP47.PersistSpec+ Data.BCP47.Roundtrip+ Paths_bcp47_orphans++ default-language: Haskell2010+ build-depends:+ QuickCheck >=2.13.2 && <2.14,+ base >=4.7 && <5,+ bcp47 >=0.2.0.0 && <0.3,+ bcp47-orphans -any,+ cassava >=0.5.2.0 && <0.6,+ hspec >=2.7.4 && <2.8,+ path-pieces >=0.2.1 && <0.3,+ persistent >=2.10.5.3 && <2.11
+ library/Data/BCP47/Csv.hs view
@@ -0,0 +1,15 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Data.BCP47.Csv () where++import Data.BCP47 (BCP47, fromText, toText)+import Data.Csv (FromField(..), ToField(..))+import Data.Text (unpack)++instance ToField BCP47 where+ toField = toField . toText++instance FromField BCP47 where+ parseField bytes = do+ text <- parseField bytes+ either (fail . unpack) pure $ fromText text
+ library/Data/BCP47/Esqueleto.hs view
@@ -0,0 +1,9 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Data.BCP47.Esqueleto () where++import Data.BCP47+import Data.BCP47.Persist ()+import Database.Esqueleto (SqlString)++instance SqlString BCP47
+ library/Data/BCP47/Hashable.hs view
@@ -0,0 +1,9 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Data.BCP47.Hashable () where++import Data.BCP47 (BCP47, toText)+import Data.Hashable (Hashable(..))++instance Hashable BCP47 where+ hashWithSalt i = hashWithSalt i . toText
+ library/Data/BCP47/HttpApiData.hs view
@@ -0,0 +1,14 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Data.BCP47.HttpApiData+ ()+where++import Data.BCP47 (BCP47, fromText, toText)+import Web.HttpApiData (FromHttpApiData(..), ToHttpApiData(..))++instance ToHttpApiData BCP47 where+ toUrlPiece = toText++instance FromHttpApiData BCP47 where+ parseUrlPiece = fromText
+ library/Data/BCP47/PathPieces.hs view
@@ -0,0 +1,11 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Data.BCP47.PathPieces () where++import Control.Error.Util (hush)+import Data.BCP47 (BCP47, fromText, toText)+import Web.PathPieces (PathPiece(..))++instance PathPiece BCP47 where+ fromPathPiece = hush . fromText+ toPathPiece = toText
+ library/Data/BCP47/Persist.hs view
@@ -0,0 +1,20 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE TypeApplications #-}++module Data.BCP47.Persist () where++import Control.Monad ((<=<))+import Data.BCP47 (BCP47, fromText, toText)+import Data.Proxy (Proxy(..))+import Data.Text (Text)+import Database.Persist.Class (PersistField(..))+import Database.Persist.Sql (PersistFieldSql(..))++instance PersistField BCP47 where+ toPersistValue = toPersistValue . toText+ fromPersistValue = fromText <=< fromPersistValue++instance PersistFieldSql BCP47 where+ -- sqlType for Text should be SqlString, but we don't hardcode in the+ -- unlikely case that changes+ sqlType _ = sqlType @Text Proxy
+ tests/Data/BCP47/CsvSpec.hs view
@@ -0,0 +1,21 @@+{-# LANGUAGE TypeApplications #-}++module Data.BCP47.CsvSpec+ ( spec+ ) where++import Data.BCP47 (BCP47)+import Data.BCP47.Csv ()+import Data.BCP47.Roundtrip (roundtrips)+import Data.Csv (parseField, runParser, toField)+import Test.Hspec+import Test.QuickCheck (property)++spec :: Spec+spec =+ describe "ToField/FromField"+ . it "roundtrips"+ . property+ . roundtrips @BCP47 toField+ $ runParser+ . parseField
+ tests/Data/BCP47/PathPiecesSpec.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE TypeApplications #-}++module Data.BCP47.PathPiecesSpec+ ( spec+ ) where++import Data.BCP47 (BCP47)+import Data.BCP47.PathPieces ()+import Data.BCP47.Roundtrip (roundtrips)+import Test.Hspec+import Test.QuickCheck (property)+import Web.PathPieces (fromPathPiece, toPathPiece)++spec :: Spec+spec = describe "PathPiece" . it "roundtrips" . property $ roundtrips @BCP47+ toPathPiece+ fromPathPiece
+ tests/Data/BCP47/PersistSpec.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE TypeApplications #-}++module Data.BCP47.PersistSpec+ ( spec+ ) where++import Data.BCP47 (BCP47)+import Data.BCP47.Persist ()+import Data.BCP47.Roundtrip (roundtrips)+import Database.Persist.Class (fromPersistValue, toPersistValue)+import Test.Hspec+import Test.QuickCheck (property)++spec :: Spec+spec = describe "PersistField" . it "roundtrips" . property $ roundtrips @BCP47+ toPersistValue+ fromPersistValue
+ tests/Data/BCP47/Roundtrip.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE ScopedTypeVariables #-}++module Data.BCP47.Roundtrip+ ( roundtrips+ ) where++roundtrips+ :: forall a b f+ . (Eq (f a), Applicative f)+ => (a -> b)+ -- ^ Encode+ -> (b -> f a)+ -- ^ Decode+ -> a+ -> Bool+roundtrips encode decode x = decode (encode x) == pure x
+ tests/Main.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}