From cd34466ceb552977518ce60af10efad6f06ce69b Mon Sep 17 00:00:00 2001 From: byakuren-hijiri <159621697+byakuren-hijiri@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:52:45 -0300 Subject: [PATCH] feat(store): add a mock context constructor needed for tests (#184) Used in the fuzzer implementation: issue #133 --- src/grammar/store.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/grammar/store.ts b/src/grammar/store.ts index fc1f95798..f1c187fe1 100644 --- a/src/grammar/store.ts +++ b/src/grammar/store.ts @@ -42,4 +42,19 @@ export function openContext(ctx: CompilerContext, } ctx = store.set(ctx, 'types', { sources, funcSources, functions, constants, types }); return ctx; -} \ No newline at end of file +} + +// 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; +}