Update aeson example

This commit is contained in:
lyxia 2016-05-03 12:34:02 +02:00
parent e52dda0ab1
commit 43d5c14691
2 changed files with 10 additions and 8 deletions

View File

@ -8,8 +8,8 @@ import qualified Data.Text as Text
import Test.QuickCheck
import Data.Random.Generics
genValue :: Int -> Gen Value
genValue = pointedGeneratorWith aliases asGen
instance Arbitrary Value where
arbitrary = sized $ pointedGeneratorWith aliases asGen
aliases :: [Alias Gen]
aliases =
@ -17,8 +17,10 @@ aliases =
, alias $ return . (Vector.fromList :: [Value] -> _)
, alias $ \ () -> fmap (realToFrac :: Double -> Scientific) arbitrary
, alias $ return . Text.pack
, alias $ \ ~[()] -> arbitrary :: Gen String
, alias $ (const arbitrary :: [()] -> Gen String)
]
main :: IO ()
main = sample (sized genValue)
main = do
sample (arbitrary :: Gen Value)
quickCheck $ \(v :: Value) -> (decode . encode) v === Just v

View File

@ -3,9 +3,9 @@ version: 0
build-type: Simple
cabal-version: >=1.10
executable aeson
executable aeson-example
main-is: aeson.hs
ghc-options: -Wall
ghc-options: -Wall -fno-warn-partial-type-signatures
build-depends:
aeson,
base,
@ -17,7 +17,7 @@ executable aeson
generic-random
default-language: Haskell2010
executable functions
executable functions-example
main-is: functions.hs
ghc-options: -Wall
build-depends:
@ -26,7 +26,7 @@ executable functions
generic-random
default-language: Haskell2010
executable positive-ints
executable positive-ints-example
main-is: positive-ints.hs
ghc-options: -Wall
build-depends: