Skip to content

Commit 223b814

Browse files
committed
replace @noself call-signature snapshot tests with runtime argc probes
1 parent a624d0d commit 223b814

2 files changed

Lines changed: 30 additions & 44 deletions

File tree

test/unit/functions/__snapshots__/noSelfAnnotation.spec.ts.snap

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
exports[`@noSelf on declared function removes context argument 1`] = `"myFunction()"`;
44

5-
exports[`@noSelf on interface with call signature removes context argument 1`] = `
6-
"func = function()
7-
end
8-
func()"
9-
`;
10-
115
exports[`@noSelf on method inside class declaration removes context argument 1`] = `"holder.myMethod()"`;
126

137
exports[`@noSelf on method inside interface declaration removes context argument 1`] = `"holder.myMethod()"`;
@@ -16,18 +10,6 @@ exports[`@noSelf on method inside namespace declaration removes context argument
1610

1711
exports[`@noSelf on parent class declaration removes context argument 1`] = `"holder.myMethod()"`;
1812

19-
exports[`@noSelf on parent interface applies to property with interface call-signature type 1`] = `
20-
"demo = {func = function()
21-
end}
22-
demo.func()"
23-
`;
24-
25-
exports[`@noSelf on parent interface applies to property with type-literal call signature 1`] = `
26-
"demo = {func = function()
27-
end}
28-
demo.func()"
29-
`;
30-
3113
exports[`@noSelf on parent interface declaration removes context argument 1`] = `"holder.myMethod()"`;
3214

3315
exports[`@noSelf on parent namespace declaration removes context argument 1`] = `"MyNamespace.myMethod()"`;

test/unit/functions/noSelfAnnotation.spec.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,47 @@ test("@noSelf on static class methods with string key access", () => {
6666
});
6767

6868
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1661
69-
test("@noSelf on interface with call signature removes context argument", () => {
69+
// A Lua-side function observes the actual argc, so a missing @noSelf would
70+
// surface as a phantom leading nil (argc 2 instead of 1).
71+
const argcProbeHeader = `
72+
function probe(...)
73+
return select("#", ...)
74+
end
75+
`;
76+
77+
test("@noSelf on interface call signature: Lua probe sees correct argc", () => {
7078
util.testModule`
7179
/** @noSelf */
72-
interface CallSignature {
73-
(): void;
74-
}
75-
const func: CallSignature = () => {};
76-
func();
77-
`.expectLuaToMatchSnapshot();
80+
interface Probe { (a: string): number; }
81+
declare const probe: Probe;
82+
export const result = probe("hi");
83+
`
84+
.setLuaHeader(argcProbeHeader)
85+
.expectToEqual({ result: 1 });
7886
});
7987

80-
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1661
81-
test("@noSelf on parent interface applies to property with interface call-signature type", () => {
88+
test("@noSelf parent interface, property typed by call-signature interface: Lua probe sees correct argc", () => {
8289
util.testModule`
8390
/** @noSelf */
84-
interface CallSignature {
85-
(): void;
86-
}
91+
interface CallSignature { (a: string): number; }
8792
/** @noSelf */
88-
interface DemoType {
89-
func: CallSignature;
90-
}
91-
const demo: DemoType = { func: () => {} };
92-
demo.func();
93-
`.expectLuaToMatchSnapshot();
93+
interface Holder { fn: CallSignature; }
94+
declare const holder: Holder;
95+
export const result = holder.fn("hi");
96+
`
97+
.setLuaHeader(`${argcProbeHeader}\nholder = { fn = probe }`)
98+
.expectToEqual({ result: 1 });
9499
});
95100

96-
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1661
97-
test("@noSelf on parent interface applies to property with type-literal call signature", () => {
101+
test("@noSelf parent interface, property typed by type-literal call signature: Lua probe sees correct argc", () => {
98102
util.testModule`
99103
/** @noSelf */
100-
interface DemoType {
101-
func: { (): void };
102-
}
103-
const demo: DemoType = { func: () => {} };
104-
demo.func();
105-
`.expectLuaToMatchSnapshot();
104+
interface Holder { fn: { (a: string): number }; }
105+
declare const holder: Holder;
106+
export const result = holder.fn("hi");
107+
`
108+
.setLuaHeader(`${argcProbeHeader}\nholder = { fn = probe }`)
109+
.expectToEqual({ result: 1 });
106110
});
107111

108112
// additional coverage for https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1292

0 commit comments

Comments
 (0)