diff options
Diffstat (limited to 'test/parser.spec.ts')
-rw-r--r-- | test/parser.spec.ts | 42 |
1 files changed, 40 insertions, 2 deletions
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], + }); }); |