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