packages feed

aeson-compat 0.3.1.0 → 0.3.2.0

raw patch · 5 files changed

+148/−30 lines, 5 filesdep +base-compatdep +base-orphansdep +semigroupsdep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: base-compat, base-orphans, semigroups, tagged

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.3.2.0++- Introduce instances from `aeson-0.11.1.0`: `Const`, `Tagged`, `Proxy` and `NonEmpty`+- Fix bug with `Natural` instance, `aeson-0.11.1.0` and `base <=4.7`+ # 0.3.1.0  - `aeson-0.11` support
aeson-compat.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.8.0.+-- This file has been generated from package.yaml by hpack version 0.11.2. -- -- see: https://github.com/sol/hpack  name:           aeson-compat-version:        0.3.1.0+version:        0.3.2.0 synopsis:       Compatibility layer for aeson description:    Compatibility layer for @aeson@ category:       Web@@ -31,7 +31,8 @@   ghc-options: -Wall   build-depends:       base                     >=4.6  && <4.10-    , aeson                    >=0.7.0.6 && <0.11.1+    , base-compat              >=0.6.0 && <0.10+    , aeson                    >=0.7.0.6 && <0.11.2     , attoparsec               >=0.12 && <0.14     , bytestring               >=0.10 && <0.11     , containers               >=0.5  && <0.6@@ -44,6 +45,8 @@     , time-locale-compat       >=0.1.0.1 && <0.2     , unordered-containers     >=0.2  && <0.3     , vector                   >=0.10 && <0.12+    , semigroups               >=0.16.2.2 && <0.19+    , tagged                   >=0.7.3 && <0.9   exposed-modules:       Data.Aeson.Compat   other-modules:@@ -58,7 +61,8 @@   ghc-options: -Wall   build-depends:       base                     >=4.6  && <4.10-    , aeson                    >=0.7.0.6 && <0.11.1+    , base-compat              >=0.6.0 && <0.10+    , aeson                    >=0.7.0.6 && <0.11.2     , attoparsec               >=0.12 && <0.14     , bytestring               >=0.10 && <0.11     , containers               >=0.5  && <0.6@@ -71,7 +75,10 @@     , time-locale-compat       >=0.1.0.1 && <0.2     , unordered-containers     >=0.2  && <0.3     , vector                   >=0.10 && <0.12+    , semigroups               >=0.16.2.2 && <0.19+    , tagged                   >=0.7.3 && <0.9     , aeson-compat+    , base-orphans          >=0.4.5 && <0.6     , tasty                 >=0.10 && <0.12     , tasty-hunit           >=0.9  && <0.10     , tasty-quickcheck      >=0.8  && <0.9
src/Data/Aeson/Compat.hs view
@@ -33,13 +33,8 @@   module Data.Aeson,   ) where -#if !MIN_VERSION_base(4,8,0)-import           Control.Applicative-#endif--#if MIN_VERSION_aeson(0,10,0)-import           Data.Monoid-#endif+import Prelude ()+import Prelude.Compat  import           Data.Aeson hiding   ((.:?), decode, decode', decodeStrict, decodeStrict'@@ -79,6 +74,16 @@ import Text.ParserCombinators.ReadP (readP_to_S) #endif +#if !MIN_VERSION_aeson(0,11,1)+import Control.Applicative (Const (..))+import Data.List.NonEmpty  (NonEmpty (..))+import Data.Proxy          (Proxy (..))+import Data.Tagged         (Tagged (..))++import qualified Data.List.NonEmpty as NonEmpty+import qualified Data.Vector        as V+#endif+ -- | Exception thrown by 'decode' - family of functions in this module. newtype AesonException = AesonException String   deriving (Show, Typeable)@@ -123,7 +128,7 @@ #if MIN_VERSION_aeson(0,10,0)                   modifyFailure addKeyName $ parseJSON v -- <?> Key key   where-    addKeyName = (("failed to parse field " <> T.unpack key <> ": ") <>)+    addKeyName = mappend $ mconcat ["failed to parse field ", T.unpack key, ": "] #else                   parseJSON v #endif@@ -139,7 +144,7 @@ #if MIN_VERSION_aeson(0,10,0)                   modifyFailure addKeyName $ Just <$> parseJSON v -- <?> Key key   where-    addKeyName = (("failed to parse field " <> T.unpack key <> ": ") <>)+    addKeyName = mappend $ mconcat ["failed to parse field ", T.unpack key, ": "] #else                   Just <$> parseJSON v #endif@@ -221,6 +226,7 @@ -- Instances in aeson-0.11 ----------------------------------------------------------------------- +#if !(MIN_VERSION_aeson(0,11,1)) #if !(MIN_VERSION_aeson(0,11,0) && MIN_VERSION_base(4,8,0)) instance ToJSON Natural where     toJSON = toJSON . toInteger@@ -237,6 +243,7 @@         then fail $ "Expected a Natural number but got the negative number: " ++ show s         else pure $ truncate s #endif+#endif  #if !MIN_VERSION_aeson(0,11,0) instance ToJSON Version where@@ -275,4 +282,59 @@       "EQ" -> return EQ       "GT" -> return GT       _ -> fail "Parsing Ordering value failed: expected \"LT\", \"EQ\", or \"GT\""+#endif++#if !MIN_VERSION_aeson(0,11,1)+instance ToJSON (Proxy a) where+    toJSON _ = Null+    {-# INLINE toJSON #-}++    -- No 'toEncoding', default is good enough++instance FromJSON (Proxy a) where+    {-# INLINE parseJSON #-}+    parseJSON Null = pure Proxy+    parseJSON v    = typeMismatch "Proxy" v++instance ToJSON b => ToJSON (Tagged a b) where+    toJSON (Tagged x) = toJSON x+    {-# INLINE toJSON #-}++#if MIN_VERSION_aeson(0,10,0)+    toEncoding (Tagged x) = toEncoding x+    {-# INLINE toEncoding #-}+#endif++instance FromJSON b => FromJSON (Tagged a b) where+    {-# INLINE parseJSON #-}+    parseJSON = fmap Tagged . parseJSON++instance ToJSON a => ToJSON (Const a b) where+    toJSON (Const x) = toJSON x+    {-# INLINE toJSON #-}++#if MIN_VERSION_aeson(0,10,0)+    toEncoding (Const x) = toEncoding x+    {-# INLINE toEncoding #-}+#endif++instance FromJSON a => FromJSON (Const a b) where+    {-# INLINE parseJSON #-}+    parseJSON = fmap Const . parseJSON++instance (ToJSON a) => ToJSON (NonEmpty a) where+    toJSON = toJSON . NonEmpty.toList+    {-# INLINE toJSON #-}++#if MIN_VERSION_aeson(0,10,0)+    toEncoding = toEncoding . NonEmpty.toList+    {-# INLINE toEncoding #-}+#endif++instance (FromJSON a) => FromJSON (NonEmpty a) where+    parseJSON = withArray "NonEmpty a" $+        (>>= ne) . traverse parseJSON . V.toList+      where+        ne []     = fail "Expected a NonEmpty but got an empty list"+        ne (x:xs) = pure (x :| xs) #endif
test/Orphans.hs view
@@ -2,21 +2,35 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Orphans where -#if !MIN_VERSION_base(4,8,0)-import           Control.Applicative-#endif+import Prelude                   ()+import Prelude.Compat -import Data.Vector as V-import Data.Version (Version(..))+import Data.Version              (Version (..)) import Test.Tasty.QuickCheck +import Data.Orphans              ()+import Test.QuickCheck.Instances ()++#if !MIN_VERSION_quickcheck_instances(0,3,12)+import Data.Vector               as V+#endif++#if !MIN_VERSION_QuickCheck(2,8,3)+import Control.Applicative       (Const (..))+import Data.List.NonEmpty        (NonEmpty (..))+import Data.Proxy                (Proxy (..))+import Data.Tagged               (Tagged (..))+#endif+ #if !(MIN_VERSION_QuickCheck(2,8,0) && MIN_VERSION_base(4,8,0))-import Numeric.Natural (Natural)+import Numeric.Natural           (Natural) #endif +#if !MIN_VERSION_quickcheck_instances(0,3,12) instance Arbitrary a => Arbitrary (Vector a) where   arbitrary = V.fromList <$> arbitrary   shrink    =  fmap V.fromList . shrink . V.toList+#endif  #if !(MIN_VERSION_QuickCheck(2,8,0) && MIN_VERSION_base(4,8,0)) instance Arbitrary Natural where@@ -28,3 +42,20 @@     x <- fmap abs arbitrary     xs <- (fmap . fmap) abs arbitrary     return $ Version (x : xs) []++#if !MIN_VERSION_QuickCheck(2,8,3)+instance Arbitrary a => Arbitrary (NonEmpty a) where+  arbitrary = do+    x <- arbitrary+    xs <- arbitrary+    return (x :| xs)++instance Arbitrary a => Arbitrary (Tagged t a) where+  arbitrary = fmap Tagged arbitrary++instance Arbitrary a => Arbitrary (Const a b) where+  arbitrary = fmap Const arbitrary++instance Arbitrary (Proxy a) where+  arbitrary = return Proxy+#endif
test/Tests.hs view
@@ -1,20 +1,29 @@-{-# LANGUAGE CPP #-}+{-# LANGUAGE CPP               #-} {-# LANGUAGE OverloadedStrings #-} module Main (main) where -import           Data.Time (Day, LocalTime)-import           Data.Version (Version)-import           Numeric.Natural (Natural)+import Prelude                   ()+import Prelude.Compat -import           Test.QuickCheck.Instances ()-import           Test.Tasty-import           Test.Tasty.QuickCheck-import           Test.Tasty.HUnit+import Control.Applicative       (Const)+import Data.List.NonEmpty        (NonEmpty)+import Data.Proxy                (Proxy)+import Data.Tagged               (Tagged)+import Data.Time                 (Day, LocalTime)+import Data.Version              (Version)+import Numeric.Natural           (Natural) -import           Data.Aeson.Compat+import Data.Orphans              () -import           Orphans ()+import Test.QuickCheck.Instances ()+import Test.Tasty+import Test.Tasty.HUnit+import Test.Tasty.QuickCheck +import Data.Aeson.Compat++import Orphans                   ()+ main :: IO () main = defaultMain $ testGroup "Tests"   [ dotColonMark@@ -24,6 +33,10 @@     , testProperty "Version"   $ roundtrip (undefined :: Version)     , testProperty "Ordering"  $ roundtrip (undefined :: Ordering)     , testProperty "Natural"   $ roundtrip (undefined :: Natural)+    , testProperty "Const"     $ roundtrip (undefined :: Const Int Int)+    , testProperty "Proxy"     $ roundtrip (undefined :: Proxy Int)+    , testProperty "Tagged"    $ roundtrip (undefined :: Tagged Int Int)+    , testProperty "NonEmpty"  $ roundtrip (undefined :: NonEmpty Int)     ]   ] @@ -65,7 +78,7 @@ #if MIN_VERSION_aeson(0,10,0) && !MIN_VERSION_aeson(0,11,0) roundtripBroken10 _ x = property $ case eitherDecode . encode $ x of   Right y -> False && x == y  -- x and y of the same type!-  Left _  -> True +  Left _  -> True #else roundtripBroken10 = roundtrip #endif