cps-interpreter/test/parser.spec.ts

46 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2024-02-23 19:27:16 -05:00
import { expect, test } from 'bun:test';
import { TestPrograms } from './programs';
import { peggyParse } from '@/parser';
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],
});
2024-02-23 19:27:16 -05:00
});