diff --git a/tests/utils/test-code-builder.ts b/tests/utils/test-code-builder.ts deleted file mode 100644 index 5311e73..0000000 --- a/tests/utils/test-code-builder.ts +++ /dev/null @@ -1,71 +0,0 @@ - -interface TestAgent { - identifier: string; - count: string; -} - -interface TestVariable { - identifier: string; - value: string; - default?: string; -} - -export class TestCodeBuilder { - - private sourceCode: string = ""; - - private _agent: TestAgent = { identifier: "entity", count: "10" }; - private _properties: TestVariable[] = []; - private _consts: TestVariable[] = []; - private _defines: TestVariable[] = []; - - public agent(identifier: string, count: string): TestCodeBuilder { - this._agent = { identifier, count }; - return this; - } - - public property(identifier: string, value: string, defaultValue?: string): TestCodeBuilder { - this._properties.push({ identifier, value, default: defaultValue }); - return this; - } - - public const(identifier: string, value: string): TestCodeBuilder { - this._consts.push({ identifier, value }); - return this; - } - - public define(identifier: string, value: string): TestCodeBuilder { - this._defines.push({ identifier, value }); - return this; - } - - public build(): string { - for (const declaration of this._defines) { - this.sourceCode += `define ${declaration.identifier} = ${declaration.value};\n`; - } - - this.sourceCode += "\n"; - - this.sourceCode += `agent ${this._agent.identifier} ${this._agent.count} {\n`; - - for (const declaration of this._consts) { - this.sourceCode += ` const ${declaration.identifier} = ${declaration.value};\n`; - } - - this.sourceCode += "\n"; - - for (const declaration of this._properties) { - this.sourceCode += ` property ${declaration.identifier}`; - - if (declaration.default) { - this.sourceCode += `: ${declaration.default}`; - } - - this.sourceCode += ` = ${declaration.value};\n`; - } - - this.sourceCode += "}"; - - return this.sourceCode; - } -} \ No newline at end of file diff --git a/tests/utils/test-support.ts b/tests/utils/test-support.ts index 0b280bf..fccfa64 100644 --- a/tests/utils/test-support.ts +++ b/tests/utils/test-support.ts @@ -3,21 +3,38 @@ import { DefineDeclaration, NodeType, ObjectDeclaration, ParserValue, Program, R export class TestSupport { - // runtime - + /** + * Expects the given generic runtime value to be of the given type + * + * @param value generic runtime value to assert + * @param type expected type of the runtime value + * @returns runtime value of the given type + */ public static expectValue(value: RuntimeValue | undefined, type: ValueType): T { expect(value).toBeDefined(); expect(value!.type).toBe(type); return value! as T; } - // parser - + /** + * Expects the given generic AST node to be of the given type + * + * @param node generic AST node to assert + * @param type expected type of the AST node + * @returns AST node of the given type + */ public static expectNode(node: ParserValue, type: NodeType): T { expect(node.type).toBe(type); return node as T; } + /** + * Expects an object declaration with the given identifier to be present in the given program AST node + * + * @param program program AST node to search the object declaration in + * @param identifier identifier of the object declaration to find + * @returns object declaration AST node + */ public static expectAgentDeclaration(program: Program, identifier: string): ObjectDeclaration { expect(program.body.length).not.toBe(0); @@ -34,6 +51,14 @@ export class TestSupport { return agentDeclaration!; } + /** + * Expects an variable declaration with the given identifier to be present in the given program AST node in an object declaration with the given identifier + * + * @param program program AST node to search the variable declaration in + * @param agentIdentifier identifier of the object declaration AST node to search in + * @param identifier identifier of the variable declaration to find + * @returns variable declaration AST node + */ public static expectPropertyDeclaration(program: Program, agentIdentifier: string, identifier: string): VariableDeclaration { const agentDeclaration = TestSupport.expectAgentDeclaration(program, agentIdentifier); @@ -48,6 +73,13 @@ export class TestSupport { return propertyDeclaration!; } + /** + * Expects a define declaration with the given identifier to be present in the given program AST node + * + * @param program program AST node to search the define declaration in + * @param identifier identifier of the define declaration to find + * @returns define declaration AST node + */ public static expectDefineDeclaration(program: Program, identifier: string): DefineDeclaration { expect(program.body.length).not.toBe(0);