cardano-binary-test-1.4.0.2: Test helpers from cardano-binary exposed to other packages
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Cardano.Binary.Helpers.GoldenRoundTrip

Description

Golden and round-trip testing of FromCBOR and ToCBOR instances

Synopsis

Documentation

goldenTestCBOR ∷ ∀ a. (FromCBOR a, ToCBOR a, Eq a, Show a, HasCallStack) ⇒ a → FilePathProperty Source #

Check that the encode and decode function of the Bi instances work as expected w.r.t. the give reference data, this is, given a value x::a, and a file path fp:

  • The encoded data should coincide with the contents of the fp.
  • Decoding fp should give as a result x

goldenTestCBORExplicit Source #

Arguments

∷ ∀ a. (Eq a, Show a, HasCallStack) 
Text

Label for error reporting when decoding.

→ (a → Encoding) 
→ (∀ s. Decoder s a) 
→ a 
FilePath 
Property 

Variant of goldenTestBi using custom encode and decode functions.

This is required for the encode/decode golden-tests for types that do no have a Bi instance.

goldenTestExplicit ∷ ∀ a. (Eq a, Show a, HasCallStack) ⇒ (a → ByteString) → (ByteStringEither DecoderError a) → a → FilePathProperty Source #

roundTripsCBORShow ∷ (FromCBOR a, ToCBOR a, Eq a, MonadTest m, Show a, HasCallStack) ⇒ a → m () Source #

Round trip test a value (any instance of FromCBOR, ToCBOR, and Show classes) by serializing it to a ByteString and back again and that also has a Show instance. If the a type has both Show and Buildable instances, it's best to use this version.

roundTripsCBORBuildable ∷ (FromCBOR a, ToCBOR a, Eq a, MonadTest m, Buildable a, HasCallStack) ⇒ a → m () Source #

Round trip (via ByteString) any instance of the FromCBOR and ToCBOR class that also has a Buildable instance.

compareHexDump ∷ (MonadTest m, HasCallStack) ⇒ HexDump → HexDump → m () Source #

A custom version of (===) for HexDumps to get prettier diffs