{-# LANGUAGE ScopedTypeVariables #-}
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 a -> Spec
roundtripSpecs proxy :: Proxy a
proxy = Proxy a -> Maybe String -> Spec
forall a.
(Typeable a, Arbitrary a, ToJSON a, FromJSON a) =>
Proxy a -> Maybe String -> Spec
genericAesonRoundtripWithNote Proxy a
proxy Maybe String
forall a. Maybe a
Nothing
genericAesonRoundtripWithNote :: forall a .
(Typeable a, Arbitrary a, ToJSON a, FromJSON a) =>
Proxy a -> Maybe String -> Spec
genericAesonRoundtripWithNote :: Proxy a -> Maybe String -> Spec
genericAesonRoundtripWithNote proxy :: Proxy a
proxy mNote :: Maybe String
mNote = do
let typeIdentifier :: String
typeIdentifier = TypeRep -> String
forall a. Show a => a -> String
show (Proxy a -> TypeRep
forall k (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep Proxy a
proxy)
()
result <- Proxy a -> Maybe String -> String -> Spec
forall a.
(Arbitrary a, ToJSON a, FromJSON a) =>
Proxy a -> Maybe String -> String -> Spec
genericAesonRoundtripWithNotePlain Proxy a
proxy Maybe String
mNote String
typeIdentifier
() -> Spec
forall (m :: * -> *) a. Monad m => a -> m a
return ()
result
genericAesonRoundtripWithNotePlain :: forall a .
(Arbitrary a, ToJSON a, FromJSON a) =>
Proxy a -> Maybe String -> String -> Spec
genericAesonRoundtripWithNotePlain :: Proxy a -> Maybe String -> String -> Spec
genericAesonRoundtripWithNotePlain _ mNote :: Maybe String
mNote typeIdentifier :: String
typeIdentifier = do
let note :: String
note = String -> (String -> String) -> Maybe String -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe "" (" " String -> String -> String
forall a. [a] -> [a] -> [a]
++) Maybe String
mNote
checkAesonEncodingEquality' :: JsonShow a -> Bool
checkAesonEncodingEquality' :: JsonShow a -> Bool
checkAesonEncodingEquality' = JsonShow a -> Bool
forall a. (ToJSON a, FromJSON a) => JsonShow a -> Bool
checkAesonEncodingEquality
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe ("JSON encoding of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
addBrackets (String
typeIdentifier) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
note) (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$
String -> (JsonShow a -> Bool) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop "allows to encode values with aeson and read them back"
(JsonShow a -> Bool
checkAesonEncodingEquality' )