@hegeldev/hegel
    Preparing search index...

    Class PrintableGenerator<T>Abstract

    A generator that can print what it draws: drawn with TestCase.draw, it writes the value's representation to the report's printer as it draws it. A container prints element by element through its elements' generators, so an element's own printing shows up inside it.

    Implement doDrawAndPrint, drawing inner generators with TestCase.drawAndPrint so that they print in place, and leave doDraw to its default, which runs the same body with PrettyPrinter.noop: both must make exactly the same draws.

    class Pairs extends generators.PrintableGenerator<[number, number]> {
    doDrawAndPrint(tc: TestCase, p: PrettyPrinter): [number, number] {
    return p.group(5, "Pair(", ")", () => {
    const a = tc.drawAndPrint(generators.integers(), p);
    p.separator();
    const b = tc.drawAndPrint(generators.integers(), p);
    return [a, b];
    });
    }
    }

    Type Parameters

    • T

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • 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 PrintableGenerator<T>

    • 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})`));