From 7cc3ef5fa1feec8087618c899441a11052f84c48 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Wed, 28 Feb 2024 14:59:28 -0500 Subject: builtin_match_signatures (#1) Co-authored-by: Lizzy Hunt Reviewed-on: https://git.simponic.xyz/simponic/cps-interpreter/pulls/1 Co-authored-by: Elizabeth Hunt Co-committed-by: Elizabeth Hunt --- test/parser.spec.ts | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'test/parser.spec.ts') diff --git a/test/parser.spec.ts b/test/parser.spec.ts index e174383..07353b8 100644 --- a/test/parser.spec.ts +++ b/test/parser.spec.ts @@ -2,6 +2,44 @@ import { expect, test } from 'bun:test'; import { TestPrograms } from './programs'; import { peggyParse } from '@/parser'; -test('Primitive Operations', async () => { - const ast = peggyParse(await TestPrograms.AddOneThree); +test('primitive operation', async () => { + const [operation] = peggyParse(await TestPrograms.AddOneThree); + const { primitiveOperation } = operation; + + expect(primitiveOperation).toEqual({ + opr: '+', + operands: [{ real: 1 }, { int: 3 }], + resultBindings: [{ name: 'result' }], + continuations: [], + }); +}); + +test('primitive operation with continuation', async () => { + const [operation] = peggyParse(await TestPrograms.PrimopScope); + const { primitiveOperation } = operation; + + const continuation = { + primitiveOperation: { + opr: '-', + operands: [{ real: 1 }, { name: 'result' }], + resultBindings: [{ name: 'result' }], + continuations: [ + { + primitiveOperation: { + opr: '+', + operands: [{ name: 'result' }, { real: 0 }], + resultBindings: [], + continuations: [], + }, + }, + ], + }, + }; + + expect(primitiveOperation).toEqual({ + opr: '+', + operands: [{ real: 1 }, { int: 3 }], + resultBindings: [{ name: 'result' }], + continuations: [continuation], + }); }); -- cgit v1.2.3-70-g09d2