| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cardano.Ledger.Huddle.Gen
Synopsis
- module Test.QuickCheck.GenT
- module Codec.CBOR.Cuddle.CDDL.Custom.Core
- module Codec.CBOR.Cuddle.CDDL.Custom.Generator
- data Term
- data RuleTerm
- newtype Name = Name {}
- genRule ∷ ∀ (rule ∷ Symbol) era. HuddleRule rule era ⇒ CBORGen Term
- generateFromName ∷ HasCallStack ⇒ Name → CBORGen Term
- generateFromGRef ∷ HasCallStack ⇒ GRef → CBORGen RuleTerm
- genArrayTerm ∷ [Term] → CBORGen Term
- genBytesTerm ∷ ByteString → CBORGen Term
- genStringTerm ∷ Text → CBORGen Term
- genMapTerm ∷ [(Term, Term)] → CBORGen Term
- unwrapSingleOrError ∷ RuleTerm → Term
- module Codec.CBOR.Cuddle.CDDL.Custom.Validator
- validateFromName ∷ HasCallStack ⇒ Name → Term → Validator ()
- validateFromGRef ∷ HasCallStack ⇒ GRef → Term → Validator ()
- validateInt ∷ Term → Validator Integer
- validateUInt ∷ Term → Validator Integer
- validateNInt ∷ Term → Validator Integer
- validateArrayTerm ∷ Term → Validator [Term]
- validateBytesTerm ∷ Term → Validator ByteString
- validateStringTerm ∷ Term → Validator Text
- validateMapTerm ∷ Term → Validator [(Term, Term)]
- unwrapSingle ∷ RuleTerm → Validator Term
- arbitrary ∷ ∀ a m. (MonadGen m, Arbitrary a) ⇒ m a
- scale ∷ MonadGen m ⇒ (Int → Int) → m a → m a
- shuffle ∷ MonadGen m ⇒ [a] → m [a]
- module Test.AntiGen
- antiVectorOfUnique ∷ Eq a ⇒ Int → AntiGen a → AntiGen (Maybe [a])
- antiVectorOfUniqueBy ∷ (a → a → Bool) → Int → AntiGen a → AntiGen (Maybe [a])
- antiVectorOfUniqueOn ∷ Eq b ⇒ (a → b) → Int → AntiGen a → AntiGen (Maybe [a])
MonadGen
module Test.QuickCheck.GenT
Custom core
Term generators
A general CBOR term, which can be used to serialise or deserialise arbitrary CBOR terms for interoperability or debugging. This type is essentially a direct reflection of the CBOR abstract syntax tree as a Haskell data type.
The Term type also comes with a Serialise instance, so you can
easily use to directly decode any arbitrary
CBOR value into Haskell with ease, and likewise with decode :: Decoder Termencode.
Since: cborg-0.2.0.0
Constructors
| TInt !Int | |
| TInteger !Integer | |
| TBytes !ByteString | |
| TBytesI !ByteString | |
| TString !Text | |
| TStringI !Text | |
| TList ![Term] | |
| TListI ![Term] | |
| TMap ![(Term, Term)] | |
| TMapI ![(Term, Term)] | |
| TTagged !Word64 !Term | |
| TBool !Bool | |
| TNull | |
| TSimple !Word8 | |
| THalf !Float | |
| TFloat !Float | |
| TDouble !Double |
A name can consist of any of the characters from the set {A to
Z, "a" to "z", "0" to "9", "_", "-", "", ".", "$"}, starting
with an alphabetic character (including "", "_", "$") and ending
in such a character or a digit.
- Names are case sensitive.
- It is preferred style to start a name with a lowercase letter.
- The hyphen is preferred over the underscore (except in a "bareword" (Section 3.5.1), where the semantics may actually require an underscore).
- The period may be useful for larger specifications, to express some module structure (as in "tcp.throughput" vs. "udp.throughput").
- A number of names are predefined in the CDDL prelude, as listed in Appendix D.
- Rule names (types or groups) do not appear in the actual CBOR encoding, but names used as "barewords" in member keys do.
Instances
genRule ∷ ∀ (rule ∷ Symbol) era. HuddleRule rule era ⇒ CBORGen Term Source #
A function for generating a term from a rule. The HuddleRule constraint
ensures that the rule is actually defined in that era.
generateFromName ∷ HasCallStack ⇒ Name → CBORGen Term Source #
Generate a CBOR Term corresponding to a top-level name.
Since we apply this to a monomorphised CTree, the names must be monomorphic terms in the original CDDL.
This will throw an error if the generated item does not correspond to a single CBOR term (e.g. if the name resolves to a group, which cannot be generated outside a context).
generateFromGRef ∷ HasCallStack ⇒ GRef → CBORGen RuleTerm Source #
Generate a RuleTerm for the type bound to the given generic
parameter at the enclosing rule. Use this from inside a custom generator
attached to a generic rule.
Term validators
validateFromName ∷ HasCallStack ⇒ Name → Term → Validator () Source #
Validate a CBOR Term against a top-level rule from inside a custom
validator.
validateFromGRef ∷ HasCallStack ⇒ GRef → Term → Validator () Source #
Validate a CBOR Term against the type bound to the given generic
parameter at the enclosing rule. Use this from inside a custom validator
attached to a generic rule.
Lifted generators
Antigen
module Test.AntiGen
antiVectorOfUnique ∷ Eq a ⇒ Int → AntiGen a → AntiGen (Maybe [a]) Source #
Generate a list of n pairwise-distinct elements. Returns Nothing if
the underlying generator could not produce enough distinct elements within
the per-element retry budget.
antiVectorOfUniqueBy ∷ (a → a → Bool) → Int → AntiGen a → AntiGen (Maybe [a]) Source #
Like antiVectorOfUnique, but takes a user-supplied equivalence relation.
antiVectorOfUniqueOn ∷ Eq b ⇒ (a → b) → Int → AntiGen a → AntiGen (Maybe [a]) Source #
Like antiVectorOfUnique, but compares elements by a key projection.