UNPKG

harmonyc

Version:

Harmony Code - model-driven BDD for Vitest

206 lines (205 loc) 6.19 kB
export interface CodeGenerator { feature(feature: Feature): void; testGroup(group: TestGroup): void; test(test: Test): void; phrase(phrase: Phrase): void; step(action: Action, responses: Response[]): void; errorStep(action: Action, errorResponse: ErrorResponse): void; setVariable(action: SetVariable): void; saveToVariable(response: SaveToVariable): void; stringLiteral(text: string, opts: { withVariables: boolean; }): string; codeLiteral(src: string): string; stringParamDeclaration(index: number): string; variantParamDeclaration(index: number): string; } export interface Location { line: number; column: number; fileName: string; } export declare class Feature { name: string; root: Section; prelude: string; constructor(name: string); get tests(): Test[]; get testGroups(): (TestGroup | Test)[]; toCode(cg: CodeGenerator): void; } export declare abstract class Branch { parent?: Branch; children: Branch[]; isFork: boolean; isEnd: boolean; location?: Location; abstract get isEmpty(): boolean; constructor(children?: Branch[]); setFork(isFork: boolean): this; setFeature(feature: Feature): this; addChild<C extends Branch>(child: C, index?: number): C; get isLeaf(): boolean; get successors(): Branch[]; get nextNonForkAncestorSibling(): Branch | undefined; get nextSibling(): Branch | undefined; get siblingIndex(): number; toString(): string; replaceWith(newBranch: Branch): this; switch(_i: number): this; } export declare class Step extends Branch { action: Action; responses: Response[]; state?: State; constructor(action: Action, responses?: Response[], children?: Branch[], isFork?: boolean); get phrases(): Phrase[]; toCode(cg: CodeGenerator): void; setFeature(feature: Feature): this; headToString(): string; toString(): string; get isEmpty(): boolean; switch(i: number): this; } export declare class State { text: string; constructor(text?: string); } export declare class Label { text: string; constructor(text?: string); get isEmpty(): boolean; } export declare class Section extends Branch { label: Label; constructor(label?: Label, children?: Branch[], isFork?: boolean); toString(): string; get isEmpty(): boolean; } export declare abstract class Part { toSingleLineString(): string; } export declare class DummyKeyword extends Part { text: string; constructor(text?: string); toString(): string; } export declare class Word extends Part { text: string; constructor(text?: string); toString(): string; } export declare class Repeater extends Part { choices: Part[][]; constructor(choices: Part[][]); toString(): string; toSingleLineString(): string; } export declare class Switch extends Part { choices: Part[]; constructor(choices: Part[]); toString(): string; toSingleLineString(): string; } export declare class Router extends Part { choices: Repeater[]; constructor(choices: Repeater[]); toString(): string; toSingleLineString(): string; } export declare abstract class Arg extends Part { abstract toCode(cg: CodeGenerator): string; abstract toDeclaration(cg: CodeGenerator, index: number): string; } export declare class StringLiteral extends Arg { text: string; constructor(text?: string); toString(): string; toSingleLineString(): string; toCode(cg: CodeGenerator): string; toDeclaration(cg: CodeGenerator, index: number): string; } export declare class Docstring extends StringLiteral { toCode(cg: CodeGenerator): string; toString(): string; toSingleLineString(): string; } export declare class CodeLiteral extends Arg { src: string; constructor(src?: string); toString(): string; toCode(cg: CodeGenerator): string; toDeclaration(cg: CodeGenerator, index: number): string; } export declare abstract class Phrase { parts: Part[]; feature: Feature; location?: Location; abstract get kind(): string; constructor(parts: Part[]); setFeature(feature: Feature): this; get keyword(): "When" | "Then"; get args(): Arg[]; get isEmpty(): boolean; abstract toCode(cg: CodeGenerator): void; toString(): string; toSingleLineString(): string; switch(i: number): Phrase; } export declare class Action extends Phrase { kind: string; toCode(cg: CodeGenerator): void; } export declare class Response extends Phrase { saveToVariable?: SaveToVariable | undefined; kind: string; constructor(parts: Part[], saveToVariable?: SaveToVariable | undefined); get isEmpty(): boolean; toString(): string; toSingleLineString(): string; toCode(cg: CodeGenerator): void; } export declare class ErrorResponse extends Response { message: StringLiteral | undefined; constructor(message: StringLiteral | undefined); toCode(cg: CodeGenerator): void; } export declare class SetVariable extends Action { variableName: string; value: Arg; constructor(variableName: string, value: Arg); toCode(cg: CodeGenerator): void; } export declare class SaveToVariable extends Part { variableName: string; constructor(variableName: string); toCode(cg: CodeGenerator): void; toString(): string; get words(): string[]; } export declare class Precondition extends Branch { state: State; constructor(state?: string); get isEmpty(): boolean; } export declare function makeTests(root: Branch): Test[]; export declare class Test { branches: Branch[]; testNumber?: string; labels: string[]; constructor(branches: Branch[]); get steps(): Step[]; get last(): Step; get name(): string; toCode(cg: CodeGenerator): void; toString(): string; switch(j: number): Test; } export declare function makeGroups(tests: Test[]): (Test | TestGroup)[]; export declare class TestGroup { name: string; items: (Test | TestGroup)[]; constructor(name: string, items: (Test | TestGroup)[]); toString(): string; toCode(cg: CodeGenerator): void; }