Elizabeth Hunt
7cc3ef5fa1
Co-authored-by: Lizzy Hunt <lizzy.hunt@usu.edu> Reviewed-on: #1 Co-authored-by: Elizabeth Hunt <elizabeth.hunt@simponic.xyz> Co-committed-by: Elizabeth Hunt <elizabeth.hunt@simponic.xyz>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
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],
|
|
});
|
|
});
|