From d39cf84965dffd11cab440f5a4efa1b16932ba73 Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Wed, 28 Feb 2024 13:41:53 -0700 Subject: branching --- test/interpreter.spec.ts | 7 +++++++ test/programs/branching.cps | 10 ++++++++++ test/programs/index.ts | 3 +++ test/signature_match.spec.ts | 4 ---- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/programs/branching.cps (limited to 'test') diff --git a/test/interpreter.spec.ts b/test/interpreter.spec.ts index fa74ef0..49b741e 100644 --- a/test/interpreter.spec.ts +++ b/test/interpreter.spec.ts @@ -18,6 +18,13 @@ test('Add (1 real) and (3 int) -> result => (real 1 - result) = -3 done with cor expect(result).toEqual({ type: 'real', value: -3 }); }); +test('Branching', async () => { + const ast = peggyParse(await TestPrograms.Branching); + + const result = await evaluate(ast, testingLogger); + expect(result).toEqual({ type: 'real', value: 2 }); +}); + /* test('String equality', async () => { const ast = peggyParse(await TestPrograms.StringEquality); diff --git a/test/programs/branching.cps b/test/programs/branching.cps new file mode 100644 index 0000000..f73704c --- /dev/null +++ b/test/programs/branching.cps @@ -0,0 +1,10 @@ +PRIMOP(>=, [REAL 0, REAL 1], [resultFalse], [ + PRIMOP(+, [REAL 2, REAL 4], [result], []), + PRIMOP(<=, [INT 1, REAL 1], [resultTrue], [ + PRIMOP(&&, [VAR resultTrue, VAR resultFalse], [fin], [ + PRIMOP(-, [REAL 1, REAL 1], [result], []), + PRIMOP(+, [REAL 1, REAL 1], [twoWhenFinIsFalse], []) + ]), + PRIMOP(-, [REAL 1, REAL 1], [result], []) + ]) +]) \ No newline at end of file diff --git a/test/programs/index.ts b/test/programs/index.ts index c8f3c85..864169f 100644 --- a/test/programs/index.ts +++ b/test/programs/index.ts @@ -7,6 +7,9 @@ export namespace TestPrograms { export const PrimopScope = Bun.file( join(import.meta.dir + '/primop-scope.cps'), ).text(); + export const Branching = Bun.file( + join(import.meta.dir + '/branching.cps'), + ).text(); export const StringEquality = Bun.file( join(import.meta.dir + '/string-equal.cps'), ).text(); diff --git a/test/signature_match.spec.ts b/test/signature_match.spec.ts index 10be880..02b8c89 100644 --- a/test/signature_match.spec.ts +++ b/test/signature_match.spec.ts @@ -1,13 +1,9 @@ import { expect, test } from 'bun:test'; -import { TestPrograms } from './programs'; -import { peggyParse } from '@/parser'; import { - evaluate, type DenotableFunctionSignature, denotableTypesEquivalent, matchSignature, } from '@/interpreter'; -import { testingLogger } from './logger'; test('simple denotable types are equivalent', () => { expect(denotableTypesEquivalent('int', 'int')).toBe(true); -- cgit v1.2.3-70-g09d2