packages feed

aeson 0.3.2.3 → 0.3.2.4

raw patch · 5 files changed

+37/−16 lines, 5 filesdep ~attoparsecPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: attoparsec

API changes (from Hackage documentation)

Files

Data/Aeson/Encode/Double.hs view
@@ -28,9 +28,7 @@  double :: Double -> Builder double f-    | isNaN f                   = fromByteString "NaN"-    | isInfinite f              = fromByteString $-                                  if f < 0 then "-Infinity" else "Infinity"+    | isNaN f || isInfinite f   = fromByteString "null"     | f < 0 || isNegativeZero f = minus `mappend` goGeneric (floatToDigits (-f))     | otherwise                 = goGeneric (floatToDigits f)   where
Data/Aeson/Types.hs view
@@ -367,6 +367,7 @@     parseJSON (Number n) = case n of                              D d -> pure d                              I i -> pure (fromIntegral i)+    parseJSON Null       = pure (0/0)     parseJSON v          = typeMismatch "Double" v     {-# INLINE parseJSON #-} @@ -376,6 +377,7 @@  instance FromJSON Number where     parseJSON (Number n) = pure n+    parseJSON Null       = pure (D (0/0))     parseJSON v          = typeMismatch "Number" v     {-# INLINE parseJSON #-} @@ -387,6 +389,7 @@     parseJSON (Number n) = case n of                              D d -> pure . fromRational . toRational $ d                              I i -> pure (fromIntegral i)+    parseJSON Null       = pure (0/0)     parseJSON v          = typeMismatch "Float" v     {-# INLINE parseJSON #-} 
aeson.cabal view
@@ -1,5 +1,5 @@ name:            aeson-version:         0.3.2.3+version:         0.3.2.4 license:         BSD3 license-file:    LICENSE category:        Text, Web, JSON@@ -97,7 +97,7 @@     Data.Aeson.Functions    build-depends:-    attoparsec >= 0.8.5.0,+    attoparsec >= 0.8.5.3,     base == 4.*,     blaze-builder >= 0.2.1.4,     bytestring,
tests/Makefile view
@@ -3,7 +3,7 @@ all: qc  qc: Properties.hs-	$(ghc) -o --make $@ $<+	$(ghc) -Wall -o -threaded --make $@ $<  clean: 	-rm -f qc *.o *.hi
tests/Properties.hs view
@@ -1,28 +1,48 @@-{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}  import Data.Aeson.Encode import Data.Aeson.Parser (value) import Data.Aeson.Types import Data.Attoparsec.Number-import Test.Framework (defaultMain, testGroup)+import Test.Framework (Test, defaultMain, testGroup) import Test.Framework.Providers.QuickCheck2 (testProperty)-import Test.QuickCheck (Arbitrary(..))-import Test.QuickCheck.Monadic (assert, monadicIO, run) import qualified Data.ByteString.Lazy.Char8 as L import qualified Data.Attoparsec.Lazy as L -encodeDouble d  = encode (Number (D d)) == L.pack (show d)+encodeDouble :: Double -> Double -> Bool+encodeDouble num denom+    | isInfinite d || isNaN d = encode (Number (D d)) == "null"+    | otherwise               = encode (Number (D d)) == L.pack (show d)+  where d = num / denom++encodeInteger :: Integer -> Bool encodeInteger i = encode (Number (I i)) == L.pack (show i) -roundTrip :: (Eq a, FromJSON a, ToJSON a) => a -> Bool-roundTrip i = (fmap fromJSON . L.maybeResult . L.parse value . encode . toJSON) i == Just (Success i)+roundTrip :: (FromJSON a, ToJSON a) => (a -> a -> Bool) -> a -> Bool+roundTrip eq i =+    case fmap fromJSON . L.parse value . encode . toJSON $ i of+      L.Done _ (Success v) -> v `eq` i+      _                    -> False -roundTripBool (v::Bool) = roundTrip v-roundTripDouble (v::Double) = roundTrip v-roundTripInteger (v::Integer) = roundTrip v+roundTripBool :: Bool -> Bool+roundTripBool = roundTrip (==)+roundTripDouble :: Double -> Bool+roundTripDouble = roundTrip approxEq+roundTripInteger :: Integer -> Bool+roundTripInteger = roundTrip (==) +approxEq :: Double -> Double -> Bool+approxEq a b = a == b ||+               d < maxAbsoluteError ||+                 d / max (abs b) (abs a) <= maxRelativeError+    where d = abs (a - b)+          maxAbsoluteError = 1e-15+          maxRelativeError = 1e-15++main :: IO () main = defaultMain tests +tests :: [Test] tests = [   testGroup "encode" [       testProperty "encodeDouble" encodeDouble