summaryrefslogtreecommitdiff
path: root/test/interpreter.spec.ts
blob: 49b741ebc64696f5c8b20b168eb14abbf5af3037 (plain)
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
import { expect, test } from 'bun:test';
import { TestPrograms } from './programs';
import { peggyParse } from '@/parser';
import { evaluate } from '@/interpreter';
import { testingLogger } from './logger';

test('Add (1 real) and (3 int) => (4 real)', async () => {
  const ast = peggyParse(await TestPrograms.AddOneThree);

  const result = await evaluate(ast, testingLogger);
  expect(result).toEqual({ type: 'real', value: 4 });
});

test('Add (1 real) and (3 int) -> result => (real 1 - result) = -3 done with correct lexical scope', async () => {
  const ast = peggyParse(await TestPrograms.PrimopScope);

  const result = await evaluate(ast, testingLogger);
  expect(result).toEqual({ type: 'real', value: -3 });
});

test('Branching', async () => {
  const ast = peggyParse(await TestPrograms.Branching);

  const result = await evaluate(ast, testingLogger);
  expect(result).toEqual({ type: 'real', value: 2 });
});

/*
test('String equality', async () => {
  const ast = peggyParse(await TestPrograms.StringEquality);

  const result = await evaluate(ast, testingLogger);
  expect(result).toEqual({ type: 'int', value: 1 });
});

test('String inequality', async () => {
  const ast = peggyParse(await TestPrograms.StringInEquality);

  const result = await evaluate(ast, testingLogger);
  expect(result).toEqual({ type: 'int', value: 0 });
});
*/