Skip to content

Commit

Permalink
chore(docs): Added docstring to testing util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasBoda committed Apr 18, 2024
1 parent e41e21a commit 52b7cfd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 75 deletions.
71 changes: 0 additions & 71 deletions tests/utils/test-code-builder.ts

This file was deleted.

40 changes: 36 additions & 4 deletions tests/utils/test-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends RuntimeValue>(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<T extends ParserValue>(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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 52b7cfd

Please sign in to comment.