HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Modulehspec-golden-aeson-0.9.0.0Haskell2010

Test.Aeson.GenericSpecs

This package provides tools for testing Aeson serialization.

  • Test that ToJSON and FromJSON instances are isomorphic.

  • Alert you when unexpected changes in Aeson serialization occur.

  • Record JSON formatting of Haskell types.

  • 3 types
  • 11 values

Arbitrary testing

3 declarations
valuegoldenSpecs
  1. :: (Typeable a, Arbitrary a, ToJSON a, FromJSON a)
  2. => Settings
  3. -> Proxy a
  4. -> Spec
#

Tests to ensure that JSON encoding has not unintentionally changed. This could be caused by the following:

  • A type's instances of ToJSON or FromJSON have changed.

  • Selectors have been edited, added or deleted.

  • You have changed version of Aeson the way Aeson serialization has changed works.

If you run this function and the golden files do not exist, it will create them for each constructor. It they do exist, it will compare with golden file if it exists. Golden file encodes json format of a type. It is recommended that you put the golden files under revision control to help monitor changes.

ToADTArbitrary testing

5 declarations
valuegoldenADTSpecs
  1. :: (ToADTArbitrary a, Eq a, Show a, ToJSON a, FromJSON a)
  2. => Settings
  3. -> Proxy a
  4. -> Spec
#

Tests to ensure that JSON encoding has not unintentionally changed. This could be caused by the following:

  • A type's instances of ToJSON or FromJSON have changed.

  • Selectors have been edited, added or deleted.

  • You have changed version of Aeson the way Aeson serialization has changed works.

If you run this function and the golden files do not exist, it will create them for each constructor. It they do exist, it will compare with golden file if it exists. Golden file encodes json format of a type. It is recommended that you put the golden files under revision control to help monitor changes.

A roundtrip test to check whether values of all of constructors of the given type can be successfully converted to JSON and back to a Haskell value.

roundtripADTSpecs will

  • create random values for each constructor using ToADTArbitrary,

  • convert them into JSON using ToJSON,

  • read them back into Haskell using FromJSON and

  • make sure that the result is the same as the value it started with using Eq.

Make Files

1 declaration

Util

4 declarations
datadata Settings
#

Constructors

re-exports

1 declaration
datadata Proxy (t :: k)
#

Proxy is a type that holds no data, but has a phantom parameter of arbitrary type (or even kind). Its use is to provide type information, even though there is no value available of that type (or it may be too costly to create one).

Historically, Proxy :: Proxy a is a safer alternative to the undefined :: a idiom.

Example1 expression
Proxy :: Proxy (Void, Int -> Int)Proxy

Proxy can even hold types of higher kinds,

Example1 expression
Proxy :: Proxy EitherProxy
Example1 expression
Proxy :: Proxy FunctorProxy
Example1 expression
Proxy :: Proxy complicatedStructureProxy
Instances62Generic1, FoldableWithIndex, FunctorWithIndex, TraversableWithIndex, RepeatWithIndex, SemialignWithIndex, …