@hegeldev/hegel
    Preparing search index...

    Class Generator<T>Abstract

    Base class for all generators: an immutable description of how to draw a value of type T from a TestCase. The same generator can be drawn from any number of times, in any number of tests.

    A Generator draws silently, with TestCase.drawSilent. To be drawn with TestCase.draw, which prints what it drew when a test fails, a generator must be a PrintableGenerator. Every built-in generator is one whenever its components are; a hand-written Generator becomes one with printWith or printAsValue.

    Type Parameters

    • T

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Draw a value from tc, printing nothing. A generator drawing from other generators draws them with their own doDraw, or with TestCase.drawSilent.

      Parameters

      Returns T

    • Only keep values that satisfy the predicate. A draw tries the engine's number of values (3) and rejects the test case if none satisfies it. It prints as this generator does, printing only the accepted value.

      Parameters

      • predicate: (value: T) => boolean

      Returns Generator<T>

    • Generate a value, then use it to choose another generator. The first value is not printed; the result prints as the chosen generator does, so it is printable when f returns printable generators.

      Type Parameters

      • U

      Parameters

      Returns PrintableGenerator<U>

    • Generate a value, then use it to choose another generator. The first value is not printed; the result prints as the chosen generator does, so it is printable when f returns printable generators.

      Type Parameters

      • U

      Parameters

      Returns Generator<U>

    • Print each drawn value by calling print with the value and the printer positioned where it goes: the way to give a generator whose values have no useful JavaScript representation (a function, a handle) a printed form, or to print a value differently from how it prints as a value. The generator keeps this one's label and schema.

      Parameters

      Returns PrintableGenerator<T>

      const digits = integers({ minValue: 0, maxValue: 9 }).printWith((d, p) => p.text(`Digit(${d})`));