Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Twiddler a = Twiddler {}
- class Twiddle a where
- encodingToTerm ∷ Version → Encoding → Term
- toTwiddler ∷ Twiddle a ⇒ Version → a → Gen (Twiddler a)
- toTerm ∷ EncCBOR a ⇒ Version → a → Term
- twiddleInvariantProp ∷ ∀ a. Twiddle a ⇒ Version → a → Gen Property
- emptyOrNothing ∷ ∀ t b. (Foldable t, Twiddle (t Void), Monoid (t Void), Twiddle (t b)) ⇒ Version → t b → Gen (Maybe Term)
- twiddleStrictMaybe ∷ Twiddle a ⇒ Version → StrictMaybe a → Gen (Maybe Term)
Documentation
Twiddler | |
|
class Twiddle a where Source #
Introducing random variations into the CBOR encoding of a value while preserving the round-trip properties.
For any value `x :: a`, where a
derives Twiddle
, and for any version
of the decoder, the following property must hold:
>>> fmap ((== x) . encodingToTerm version . encCBOR) (twiddle x)
Nothing
twiddle ∷ Version → a → Gen Term Source #
Given a value of type a
, generates a CBOR Term
that can contain
slight variations without changing the semantics. After encoding and
decoding the Term
, we should get back the original value that was being
twiddled.
In addition to varying the low-level CBOR tokens, twiddle
can also
be used to introduce higher level variations. For example if the schema
of a value allows a field to be either an empty list or absent
entirely, and both are interpreted the same way, then twiddle
can be used to randomly pick either of these representations.
Instances
Twiddle Void Source # | |
Twiddle Int64 Source # | |
Twiddle ByteString Source # | |
Defined in Test.Cardano.Ledger.Binary.Twiddle | |
Twiddle Term Source # | |
Twiddle Text Source # | |
Twiddle Integer Source # | |
Twiddle Bool Source # | |
Twiddle Double Source # | |
Twiddle Float Source # | |
Twiddle Int Source # | |
Twiddle a ⇒ Twiddle (StrictSeq a) Source # | |
Twiddle a ⇒ Twiddle (Seq a) Source # | |
Twiddle a ⇒ Twiddle (Set a) Source # | |
Twiddle a ⇒ Twiddle [a] Source # | |
(Twiddle k, Twiddle v) ⇒ Twiddle (Map k v) Source # | |
toTwiddler ∷ Twiddle a ⇒ Version → a → Gen (Twiddler a) Source #
Wraps an arbitrary value into a Twiddler
twiddleInvariantProp ∷ ∀ a. Twiddle a ⇒ Version → a → Gen Property Source #
Function for testing the invariant of a Twiddle
instance. For a correct
implementation, this property should always hold.
emptyOrNothing ∷ ∀ t b. (Foldable t, Twiddle (t Void), Monoid (t Void), Twiddle (t b)) ⇒ Version → t b → Gen (Maybe Term) Source #
Optional containers have two "empty" representations. One of
them is to return an empty container and the other is to omit the field.
This utility function randomly picks one of these representations, where
omission is represented by Nothing
and empty container is returned with
Just
. These values can then be easily concatenated with catMaybes
.
twiddleStrictMaybe ∷ Twiddle a ⇒ Version → StrictMaybe a → Gen (Maybe Term) Source #
Utility function for twiddling optional fields. It works similarly to
the twiddle method of StrictMaybe, but lifts the Maybe constructor out from
the term so it can be easily concatenated with catMaybes
.