From d362ef26db894ea52c6abd34489aa9efdbc0c89b Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 14 Jan 2023 13:22:39 +0530 Subject: chore: adds test cases + fixes Test effect scope --- src/eval-env/builtins.ts | 8 ++++---- src/eval-env/test.ts | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src/eval-env') diff --git a/src/eval-env/builtins.ts b/src/eval-env/builtins.ts index 669a005..35f8485 100644 --- a/src/eval-env/builtins.ts +++ b/src/eval-env/builtins.ts @@ -6,10 +6,10 @@ const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type => { const resultType = (() => { const baseTypes = fn ?.getBaseTypes() - .flatMap((t) => t.getSymbol()?.getName()) + .flatMap((t) => t.getSymbol()?.getName() ?? []) - if (baseTypes?.includes('Kind1')) { - const [_, resultNode] = ctx.createResult( + if (!!fn?.getProperty('return') || baseTypes?.includes('Kind1')) { + const [_key, resultNode] = ctx.createResult( `(${ctx.typeToString(fn)} & { input: ${val} })['return']` ) return resultNode @@ -53,7 +53,7 @@ const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type => { // TODO: Cleanup unwanted result node values if (!resultType) { - throw new Error('Fuck shit') + throw new Error('Couldnt get result for function application') } return resultType diff --git a/src/eval-env/test.ts b/src/eval-env/test.ts index 84ae138..4dd8c8d 100644 --- a/src/eval-env/test.ts +++ b/src/eval-env/test.ts @@ -2,7 +2,7 @@ import { Type } from 'ts-morph' import { Ctx } from '../types' export default (ctx: Ctx, args: Type[]) => ({ - Test: async () => { + Test: ctx.withScope(async () => { const [msg, effs] = args process.stdout.write(` - ${ctx.getTypeValue(msg)} `) @@ -13,12 +13,12 @@ export default (ctx: Ctx, args: Type[]) => ({ console.log('[✓]') } catch (e) { - console.log('[TEST FAILED]') + // console.log('[TEST FAILED]') throw e } return [] - }, + }), Assert: async () => { if (!ctx.getTypeValue(args[0])) { @@ -27,4 +27,15 @@ export default (ctx: Ctx, args: Type[]) => ({ return [] }, + + ShowAssertionError: async () => { + const [left, right] = args + console.log() + console.log(' | Assertion error:') + console.log(' | - Left: ', ctx.typeToString(left)) + console.log(' | - Right:', ctx.typeToString(right)) + console.log() + + return [] + }, }) -- cgit v1.3.1