module Test.Aeson.Internal.RoundtripSpecs where
import Data.Aeson as Aeson hiding (encode)
import Data.Typeable
import Test.Aeson.Internal.Utils
import Test.Hspec
import Test.QuickCheck
import Test.Hspec.QuickCheck
roundtripSpecs :: forall a .
(Typeable a, Arbitrary a, ToJSON a, FromJSON a) =>
Proxy a -> Spec
roundtripSpecs proxy = genericAesonRoundtripWithNote proxy Nothing
genericAesonRoundtripWithNote :: forall a .
(Typeable a, Arbitrary a, ToJSON a, FromJSON a) =>
Proxy a -> Maybe String -> Spec
genericAesonRoundtripWithNote proxy mNote = do
let typeIdentifier = show (typeRep proxy)
result <- genericAesonRoundtripWithNotePlain proxy mNote typeIdentifier
return result
genericAesonRoundtripWithNotePlain :: forall a .
(Arbitrary a, ToJSON a, FromJSON a) =>
Proxy a -> Maybe String -> String -> Spec
genericAesonRoundtripWithNotePlain _ mNote typeIdentifier = do
let note = maybe "" (" " ++) mNote
checkAesonEncodingEquality' :: JsonShow a -> Bool
checkAesonEncodingEquality' = checkAesonEncodingEquality
describe ("JSON encoding of " ++ addBrackets (typeIdentifier) ++ note) $
prop "allows to encode values with aeson and read them back"
(checkAesonEncodingEquality' )