From 55c00566b0c4870d4c4409ab3e93aacf74f8d081 Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Wed, 28 Feb 2024 15:06:00 -0700 Subject: identity function, repl upgrade --- test/interpreter.spec.ts | 13 +++++++++---- test/programs/application.cps | 1 + test/programs/index.ts | 13 ++++++++----- test/programs/string-equal.cps | 2 +- test/programs/string-unequal.cps | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 test/programs/application.cps (limited to 'test') diff --git a/test/interpreter.spec.ts b/test/interpreter.spec.ts index 49b741e..6d3189a 100644 --- a/test/interpreter.spec.ts +++ b/test/interpreter.spec.ts @@ -25,18 +25,23 @@ test('Branching', async () => { expect(result).toEqual({ type: 'real', value: 2 }); }); -/* test('String equality', async () => { const ast = peggyParse(await TestPrograms.StringEquality); const result = await evaluate(ast, testingLogger); - expect(result).toEqual({ type: 'int', value: 1 }); + expect(result).toEqual({ type: 'bool', value: 1 }); }); test('String inequality', async () => { const ast = peggyParse(await TestPrograms.StringInEquality); const result = await evaluate(ast, testingLogger); - expect(result).toEqual({ type: 'int', value: 0 }); + expect(result).toEqual({ type: 'bool', value: 0 }); +}); + +test('Application of identity function', async () => { + const ast = peggyParse(await TestPrograms.Application); + + const result = await evaluate(ast, testingLogger); + expect(result).toEqual({ type: 'int', value: 3 }); }); -*/ diff --git a/test/programs/application.cps b/test/programs/application.cps new file mode 100644 index 0000000..169329e --- /dev/null +++ b/test/programs/application.cps @@ -0,0 +1 @@ +PRIMOP(+, [INT 1, INT 2], [result], [APP(LABEL id, [VAR result])]) \ No newline at end of file diff --git a/test/programs/index.ts b/test/programs/index.ts index 864169f..fae3b59 100644 --- a/test/programs/index.ts +++ b/test/programs/index.ts @@ -2,18 +2,21 @@ import { join } from 'path'; export namespace TestPrograms { export const AddOneThree = Bun.file( - join(import.meta.dir + '/add-1-3.cps'), + join(import.meta.dir, 'add-1-3.cps'), ).text(); export const PrimopScope = Bun.file( - join(import.meta.dir + '/primop-scope.cps'), + join(import.meta.dir, 'primop-scope.cps'), ).text(); export const Branching = Bun.file( - join(import.meta.dir + '/branching.cps'), + join(import.meta.dir, 'branching.cps'), ).text(); export const StringEquality = Bun.file( - join(import.meta.dir + '/string-equal.cps'), + join(import.meta.dir, 'string-equal.cps'), ).text(); export const StringInEquality = Bun.file( - join(import.meta.dir + '/string-unequal.cps'), + join(import.meta.dir, 'string-unequal.cps'), + ).text(); + export const Application = Bun.file( + join(import.meta.dir, 'application.cps'), ).text(); } diff --git a/test/programs/string-equal.cps b/test/programs/string-equal.cps index ea49b22..5a32526 100644 --- a/test/programs/string-equal.cps +++ b/test/programs/string-equal.cps @@ -1 +1 @@ -PRIMOP(==, ["asdf", "asdf"], [result], []) \ No newline at end of file +PRIMOP(==, [STRING "asdf", STRING "asdf"], [result], []) \ No newline at end of file diff --git a/test/programs/string-unequal.cps b/test/programs/string-unequal.cps index ccd278e..79ee7cf 100644 --- a/test/programs/string-unequal.cps +++ b/test/programs/string-unequal.cps @@ -1 +1 @@ -PRIMOP(==, ["asdfasdf", "asdf"], [result], []) +PRIMOP(==, [STRING "asdfasdf", STRING "asdf"], [result], []) -- cgit v1.2.3-70-g09d2