UNPKG

@cowwoc/requirements

Version:

A fluent API for enforcing design contracts with automatic message generation.

103 lines (102 loc) 3.22 kB
import { type DiffWriter } from "../../internal.mjs"; /** * Base implementation for all diff writers. */ declare abstract class AbstractDiffWriter implements DiffWriter { /** * Maps each line number to its associated actual value. */ protected readonly lineToActualLine: Map<number, string>; /** * Maps each line number to its associated expected value. */ protected readonly lineToExpectedLine: Map<number, string>; /** * Maps each line number to an indication of whether the actual and expected values are equal. */ protected readonly lineToEqualLine: Map<number, boolean>; /** * A padding character used to align values vertically. */ private readonly paddingMarker; /** * The final list of lines in the actual value. */ private readonly actualLines; /** * The final list of lines in the expected value. */ private readonly expectedLines; /** * The final list that indicates which lines contain actual and expected values that are equal. */ private readonly equalLines; /** * The current line number of the actual value. */ protected actualLineNumber: number; /** * The current line number of the expected value. */ protected expectedLineNumber: number; /** * `true` if the writer has been flushed. */ protected flushed: boolean; /** * @param paddingMarker - a padding character used to align values vertically * @throws TypeError if `paddingMarker` is `undefined` or `null` * @throws RangeError if `paddingMarker` is empty */ protected constructor(paddingMarker: string); /** * Invoked before flushing the writer. */ protected abstract beforeFlush(): void; /** * Invoked after flushing the writer. */ protected abstract afterFlush(): void; getPaddingMarker(): string; /** * Adds a new line for the actual value. * * @param number - the line number to add */ protected addActualLine(number: number): void; /** * Adds a new line for the expected value. * * @param number - the line number to initialize */ protected addExpectedLine(number: number): void; /** * Splits text into one or more lines. * * @param text - some text * @param lineConsumer - consumes one line at a time * @throws IllegalStateError if the writer has already been flushed */ splitLines(text: string, lineConsumer: (line: string) => void): void; /** * Ends the current line. * * @throws IllegalStateError if the writer has already been flushed */ protected writeActualNewline(): void; /** * Ends the current line. * * @throws IllegalStateError if the writer has already been flushed */ writeExpectedNewline(): void; flush(): void; getActualLines(): string[]; getExpectedLines(): string[]; getEqualLines(): boolean[]; abstract getDiffLines(): string[]; abstract writeEqual(text: string): void; abstract writeDeleted(text: string): void; abstract writeInserted(text: string): void; } export { AbstractDiffWriter };