1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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],
});
});
|