summaryrefslogtreecommitdiff
path: root/test/parser.spec.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-02-28 14:59:28 -0500
committersimponic <elizabeth.hunt@simponic.xyz>2024-02-28 14:59:28 -0500
commit7cc3ef5fa1feec8087618c899441a11052f84c48 (patch)
tree6d65d585fcf61e9cee7193dfb2af4d719074f732 /test/parser.spec.ts
parentc8336ee48791f00378a35e463e2962f4c856beb2 (diff)
downloadcps-interpreter-7cc3ef5fa1feec8087618c899441a11052f84c48.tar.gz
cps-interpreter-7cc3ef5fa1feec8087618c899441a11052f84c48.zip
builtin_match_signatures (#1)
Co-authored-by: Lizzy Hunt <lizzy.hunt@usu.edu> Reviewed-on: https://git.simponic.xyz/simponic/cps-interpreter/pulls/1 Co-authored-by: Elizabeth Hunt <elizabeth.hunt@simponic.xyz> Co-committed-by: Elizabeth Hunt <elizabeth.hunt@simponic.xyz>
Diffstat (limited to 'test/parser.spec.ts')
-rw-r--r--test/parser.spec.ts42
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],
+ });
});