@hegeldev/hegel
    Preparing search index...

    Class PrettyPrinter

    The write surface of a failure report, laid out by the engine: a group either fits on the current line, every break point in it rendering as its separator, or breaks, every break point starting a new line at the group's indentation.

    A generators.PrintableGenerator receives one in doDrawAndPrint, positioned where the value goes, and so do printWith callbacks and prettyPrint methods. PrettyPrinter.noop discards everything, and a Document gives one to print into outside a test.

    Index

    Methods

    • Emit open and indent the group's break points indent columns further.

      Parameters

      • indent: number
      • open: string

      Returns void

    • A break point: sep (by default a space) when the enclosing group fits on one line, else a newline at the group's indentation.

      Parameters

      • sep: string = " "

      Returns void

    • A comment at the end of the current line, printed as // text. It breaks every group open around it.

      Parameters

      • text: string

      Returns void

    • A printer for a hole in the document at the current position, which can be written to later: what it prints appears here, laid out as if it had been printed inline. This is how a value whose description is only known once the test uses it (a stub function recording its calls, say) prints. Writes to it do nothing once the test case is over, or when a speculative region around its position was aborted.

      Returns PrettyPrinter

    • Close the group beginGroup opened, emitting close.

      Parameters

      • close: string

      Returns void

    • beginGroup, then body (given this printer), then endGroup. Returns what body returns.

      Type Parameters

      • R

      Parameters

      • indent: number
      • open: string
      • close: string
      • body: (printer: PrettyPrinter) => R

      Returns R

    • A newline at the current indentation.

      Returns void

    • Text printed only when the enclosing group breaks, such as a trailing comma.

      Parameters

      • text: string

      Returns void

    • A one-line representation the engine recovers the bracket structure of, so that it wraps like a value printed structurally.

      Parameters

      • text: string

      Returns void

    • The separator between two items of a group: , and a break point.

      Returns void

    • Print items between open and close the way built-in containers print: on one line, separated by , , when they fit, and otherwise one item per line, indented four columns, each followed by a comma, with close on a line of its own. (Rust's seq aligns broken items under open instead; write that layout with group and separator.)

      Type Parameters

      • T

      Parameters

      • open: string
      • close: string
      • items: Iterable<T>
      • print: (printer: PrettyPrinter, item: T) => void

      Returns void

    • Shift the indentation of later break points by delta columns.

      Parameters

      • delta: number

      Returns void

    • Whether printing to this printer produces output: false for noop, for a deferred region that has died, and once the test case it belongs to is over. Use it to skip work whose only purpose is to be printed.

      Returns boolean

    • Open a speculative region: output printed from now on is held back until Speculation.commit keeps it or Speculation.abort discards it. A generator that may retract a draw (a filter's rejected attempt, a duplicate element) prints each attempt speculatively:

      const speculation = printer.speculate();
      try {
      const value = tc.drawAndPrint(source, printer);
      if (accepted(value)) speculation.commit();
      } finally {
      speculation.abort();
      }

      Returns Speculation

    • Literal text. A newline in it starts a new line, as hardBreak does.

      Parameters

      • text: string

      Returns void

    • Print value as JavaScript syntax: strings double-quoted with JSON escapes, bigints with their n suffix, -0 kept, and arrays, plain objects, Maps, Sets, typed arrays and Dates as the expressions that construct them. Instances of other classes print through their prettyPrint method, or else as their class name and own enumerable properties, and a value that contains itself prints the repeated reference as [Circular].

      Parameters

      • value: unknown

      Returns void

    • A printer that discards everything printed to it. A generator drawing silently draws through its printing path with this printer, so that both paths make the same choices.

      Returns PrettyPrinter