From ff367669b5667530ed550da582b8a904d50d3a1f Mon Sep 17 00:00:00 2001 From: Byakuren Hijiri Date: Fri, 22 Mar 2024 07:04:36 -0500 Subject: [PATCH] feat(store): add a mock context constructor needed for tests Used in the fuzzer implementation: #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; +}