api-tools-0.9.0.0: DSL for generating API boilerplate and docs
Safe HaskellNone
LanguageHaskell2010

Data.API.Tools.JSONTests

Synopsis

Tools

jsonTestsTool :: Name -> APITool Source #

Tool to generate a list of JSON round-trip tests of type [(String, Property)] with the given name. This depends on jsonTool and quickCheckTool.

cborTestsTool :: Name -> APITool Source #

Tool to generate a list of CBOR round-trip tests of type [(String, Property)] with the given name. This depends on cborTool and quickCheckTool.

cborToJSONTestsTool :: Name -> Name -> APITool Source #

Tool to generate a list of CBOR-to-JSON conversion tests of type [(String, Property)]. The first name must be the API being tested, and the second should be the name of the declaration to be produced. This depends on cborTool, jsonTool and quickCheckTool.

jsonToCBORTestsTool :: Name -> Name -> APITool Source #

Tool to generate a list of JSON-to-CBOR conversion tests of type [(String, Property)]. The first name must be the API being tested, and the second should be the name of the declaration to be produced. This depends on cborTool, jsonTool and quickCheckTool.

jsonGenericValueTestsTool :: Name -> Name -> APITool Source #

Tool to generate a list of tests that the Value generic representation agrees with the type-specific JSON representation.

cborGenericValueTestsTool :: Name -> Name -> APITool Source #

Tool to generate a list of tests that the Value generic representation agrees with the type-specific CBOR representation.

Properties

prop_decodesTo :: forall a. (Eq a, FromJSONWithErrs a) => Value -> a -> Bool Source #

QuickCheck property that a Value decodes to an expected Haskell value, using fromJSONWithErrs

prop_decodesTo' :: forall a. (Eq a, FromJSONWithErrs a) => ParseFlags -> Value -> a -> Bool Source #

QuickCheck property that a Value decodes to an expected Haskell value, using fromJSONWithErrs' with the given ParseFlags

prop_resultsMatchRoundtrip :: forall a. (Eq a, ToJSON a, FromJSONWithErrs a) => a -> Bool Source #

QuickCheck property that Haskell values can be encoded with toJSON and decoded with fromJSONWithErrs to get the original value

prop_cborRoundtrip :: forall a. (Eq a, Serialise a) => a -> Bool Source #

QuickCheck property that CBOR decoding is a left inverse for encoding

prop_cborToJSON :: forall a. (Eq a, Serialise a, ToJSON a) => API -> TypeName -> a -> Result Source #

QuickCheck property that toJSON agrees with encoding to CBOR directly and then decoding using the schema-aware generic decoder. From this and prop_resultsMatchRoundtrip it follows that

fromJSONWithErrs . deserialiseJSONWithSchema . serialise == id

prop_jsonToCBOR :: forall a. (Eq a, Serialise a, ToJSON a) => API -> TypeName -> a -> Result Source #

QuickCheck property that direct encoding to CBOR agrees with conversion to JSON followed by the schema-aware generic encoder. From this and prop_cborRoundtrip it follows that

deserialise . serialiseJSONWithSchema . toJSON == id