Skip to content

Commit

Permalink
feat(store): add a mock context constructor needed for tests (#184)
Browse files Browse the repository at this point in the history
Used in the fuzzer implementation: issue #133
  • Loading branch information
byakuren-hijiri authored Mar 22, 2024
1 parent 7c8fd86 commit cd34466
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/grammar/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,19 @@ export function openContext(ctx: CompilerContext,
}
ctx = store.set(ctx, 'types', { sources, funcSources, functions, constants, types });
return ctx;
}
}

// Creates a mock context with the given AST elements needed for testing
// purposes
export function openMockContext(
ctx: CompilerContext,
types: ASTType[],
functions: (ASTNativeFunction|ASTFunction)[],
constants: ASTConstant[],
) {
const sources: {code: string, path: string}[] = [];
const funcSources: {code: string, path: string}[] = [];
ctx = store.set(ctx, 'types',
{sources, funcSources, functions, constants, types});
return ctx;
}

0 comments on commit cd34466

Please sign in to comment.