on master help sign in
Merge pull request #363 from phadej/nats-old
f69ed10Adam Bergmark
Data/Aeson/Types/Instances.hs+1−3
@@ -86,6 +86,7 @@ import Data.Word (Word8, Word16, Word32, Word64)
86import Data.Version (Version, showVersion, parseVersion)
86import Data.Version (Version, showVersion, parseVersion)
87import Text.ParserCombinators.ReadP (readP_to_S)
87import Text.ParserCombinators.ReadP (readP_to_S)
88import Foreign.Storable (Storable)
88import Foreign.Storable (Storable)
89+import Numeric.Natural (Natural)
89import Prelude hiding (foldr)
90import Prelude hiding (foldr)
90import qualified Data.Aeson.Encode.Builder as E
91import qualified Data.Aeson.Encode.Builder as E
91import qualified Data.Aeson.Parser.Time as Time
92import qualified Data.Aeson.Parser.Time as Time
@@ -111,7 +112,6 @@ import qualified Data.Vector.Storable as VS
111import qualified Data.Vector.Unboxed as VU
112import qualified Data.Vector.Unboxed as VU
112
113
113#if MIN_VERSION_base(4,8,0)
114#if MIN_VERSION_base(4,8,0)
114−import Numeric.Natural
115#else
115#else
116import Control.Applicative ((<$>), (<*>), pure)
116import Control.Applicative ((<$>), (<*>), pure)
117import Data.Monoid (mempty)
117import Data.Monoid (mempty)
@@ -353,7 +353,6 @@ instance FromJSON Integer where
353 parseJSON = withScientific "Integral" $ pure . truncate
353 parseJSON = withScientific "Integral" $ pure . truncate
354 {-# INLINE parseJSON #-}
354 {-# INLINE parseJSON #-}
355
355
356−#if MIN_VERSION_base(4,8,0)
357instance ToJSON Natural where
356instance ToJSON Natural where
358 toJSON = toJSON . toInteger
357 toJSON = toJSON . toInteger
359 {-# INLINE toJSON #-}
358 {-# INLINE toJSON #-}
@@ -366,7 +365,6 @@ instance FromJSON Natural where
366 if Scientific.coefficient s < 0
365 if Scientific.coefficient s < 0
367 then fail $ "Expected a Natural number but got the negative number: " <> show s
366 then fail $ "Expected a Natural number but got the negative number: " <> show s
368 else pure $ truncate s
367 else pure $ truncate s
369−#endif
370
368
371instance ToJSON Int8 where
369instance ToJSON Int8 where
372 toJSON = Number . fromIntegral
370 toJSON = Number . fromIntegral
aeson.cabal+8−1
@@ -107,9 +107,13 @@ library
107 vector >= 0.7.1
107 vector >= 0.7.1
108
108
109 if !impl(ghc >= 8.0)
109 if !impl(ghc >= 8.0)
110− -- `Data.Semigroup` is available in base only since GHC 8.0
110+ -- `Data.Semigroup` is available in base only since GHC 8.0 / base 4.9
111 build-depends: semigroups >= 0.16.1
111 build-depends: semigroups >= 0.16.1
112
112
113+ if !impl(ghc >= 7.10)
114+ -- `Numeric.Natural` is available in base only since GHC 7.10 / base 4.8
115+ build-depends: nats >=1 && <1.1
116+
113 if flag(old-locale)
117 if flag(old-locale)
114 build-depends: time < 1.5, old-locale
118 build-depends: time < 1.5, old-locale
115 else
119 else
@@ -167,6 +171,9 @@ test-suite tests
167 else
171 else
168 build-depends: time >= 1.5
172 build-depends: time >= 1.5
169
173
174+ if !impl(ghc >= 7.10)
175+ build-depends: nats >=1 && <1.1
176+
170source-repository head
177source-repository head
171 type: git
178 type: git
172 location: git://github.com/bos/aeson.git
179 location: git://github.com/bos/aeson.git
tests/Instances.hs+9
@@ -21,6 +21,10 @@ import Functions
21
21
22import Test.QuickCheck.Instances ()
22import Test.QuickCheck.Instances ()
23
23
24+#if !MIN_VERSION_base(4,8,0) && !MIN_VERSION_QuickCheck(2,8,3)
25+import Numeric.Natural
26+#endif
27+
24-- "System" types.
28-- "System" types.
25
29
26instance Arbitrary DotNetTime where
30instance Arbitrary DotNetTime where
@@ -145,3 +149,8 @@ instance Arbitrary Version where
145makeVersion :: [Int] -> Version
149makeVersion :: [Int] -> Version
146makeVersion b = Version b []
150makeVersion b = Version b []
147#endif
151#endif
152+
153+#if !MIN_VERSION_base(4,8,0) && !MIN_VERSION_QuickCheck(2,8,3)
154+instance Arbitrary Natural where
155+ arbitrary = fromInteger . abs <$> arbitrary
156+#endif
tests/Properties.hs+2
@@ -12,6 +12,7 @@ import Data.Int (Int8)
12import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
12import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
13 ZonedTime)
13 ZonedTime)
14import Data.Version (Version)
14import Data.Version (Version)
15+import Numeric.Natural (Natural)
15import Encoders
16import Encoders
16import Instances ()
17import Instances ()
17import Test.Framework (Test, testGroup)
18import Test.Framework (Test, testGroup)
@@ -139,6 +140,7 @@ tests = testGroup "properties" [
139 , testProperty "ZonedTime" $ roundTripEq (undefined :: ZonedTime)
140 , testProperty "ZonedTime" $ roundTripEq (undefined :: ZonedTime)
140 , testProperty "NominalDiffTime" $ roundTripEq (undefined :: NominalDiffTime)
141 , testProperty "NominalDiffTime" $ roundTripEq (undefined :: NominalDiffTime)
141 , testProperty "Version" $ roundTripEq (undefined :: Version)
142 , testProperty "Version" $ roundTripEq (undefined :: Version)
143+ , testProperty "Natural" $ roundTripEq (undefined :: Natural)
142 , testGroup "ghcGenerics" [
144 , testGroup "ghcGenerics" [
143 testProperty "OneConstructor" $ roundTripEq OneConstructor
145 testProperty "OneConstructor" $ roundTripEq OneConstructor
144 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
146 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)