cps-interpreter/test/signature_match.spec.ts
2024-02-28 10:52:40 -07:00

42 lines
968 B
TypeScript

import { expect, test } from 'bun:test';
import { TestPrograms } from './programs';
import { peggyParse } from '@/parser';
import {
evaluate,
type DenotableFunctionSignature,
matchSignature,
} from '@/interpreter';
import { testingLogger } from './logger';
test('matches simple signatures', async () => {
const simpleSignature: DenotableFunctionSignature[] = [
{
arguments: ['int'],
return: 'int',
},
];
expect(matchSignature(['int'], simpleSignature)).toEqual(simpleSignature[0]);
});
test('finds first match', async () => {
const simpleSignature: DenotableFunctionSignature[] = [
{
arguments: ['int', 'int'],
return: 'int',
},
{
arguments: [['int', 'real'], 'int'],
return: 'real',
},
];
expect(matchSignature(['int', 'int'], simpleSignature)).toEqual(
simpleSignature[0],
);
expect(matchSignature(['real', 'int'], simpleSignature)).toEqual(
simpleSignature[1],
);
});