Skip to content

Commit

Permalink
Update getCall test
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Sep 16, 2024
1 parent 7989990 commit 3189b4e
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/semantics/resolution/__tests__/get-call-fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,49 @@ describe("getCallFn", () => {
const point = new ObjectType({ name: "Vec", value: [], parentObj: vec });
const pointy = new ObjectType({ name: "Vec", value: [], parentObj: vec });

const objIdentifier = new MockIdentifier({ value: "hi", entity: point });
const objIdentifier = new MockIdentifier({ value: "hi", entity: pointy });

const candidate1 = new Fn({
name: fnName,
parameters: [new Parameter({ name: pName, type: vec })],
parameters: [new Parameter({ name: pName, type: point })],
});

const candidate2 = new Fn({
name: fnName,
parameters: [new Parameter({ name: pName, type: pointy })],
});

const call = new Call({
fnName,
args: new List({
value: [objIdentifier],
}),
});

call.resolveFns = vi.fn().mockReturnValue([candidate1, candidate2]);

expect(getCallFn(call)).toBe(candidate2);
});

test("subtypes are considered to overlap, and throws ambiguous error", () => {
const pName = new Identifier({ value: "arg1" });
const fnName = new Identifier({ value: "hi" });
const vec = new ObjectType({ name: "Vec", value: [] });
const point = new ObjectType({ name: "Vec", value: [], parentObj: vec });
const pointy = new ObjectType({ name: "Vec", value: [], parentObj: vec });

const objIdentifier = new MockIdentifier({ value: "hi", entity: pointy });

const candidate1 = new Fn({
name: fnName,
parameters: [new Parameter({ name: pName, type: point })],
});

const candidate2 = new Fn({
name: fnName,
parameters: [new Parameter({ name: pName, type: vec })],
});

const candidate3 = new Fn({
name: fnName,
parameters: [new Parameter({ name: pName, type: pointy })],
Expand All @@ -136,6 +167,8 @@ describe("getCallFn", () => {
.fn()
.mockReturnValue([candidate1, candidate2, candidate3]);

expect(getCallFn(call)).toBe(candidate2);
expect(() => getCallFn(call)).toThrowError(
`Ambiguous call ${JSON.stringify(call, null, 2)}`
);
});
});

0 comments on commit 3189b4e

Please sign in to comment.