Skip to content

Commit 9312a0c

Browse files
committed
Use inline snapshots for simple tests
1 parent 54aa5c2 commit 9312a0c

20 files changed

+112
-53
lines changed

test/unit/__snapshots__/conditionals.spec.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ function ____exports.__main(self)
99
end
1010
return ____exports"
1111
`;
12-
13-
exports[`switch not allowed in 5.1: diagnostics 1`] = `"main.ts(2,9): error TSTL: Switch statements is/are not supported for target Lua 5.1."`;

test/unit/__snapshots__/loops.spec.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ end
1010
return ____exports"
1111
`;
1212

13-
exports[`forin[Array]: diagnostics 1`] = `"main.ts(3,9): error TSTL: Iterating over arrays with 'for ... in' is not allowed."`;
14-
1513
exports[`forof object destructuring ({"initializer": "{a, b}", "vars": "let a: string, b: string;"}): code 1`] = `
1614
"local a
1715
local b

test/unit/builtins/__snapshots__/loading.spec.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ ____exports.__result = Math.unknownProperty
66
return ____exports"
77
`;
88

9-
exports[`Unknown builtin property access: diagnostics 1`] = `"main.ts(1,25): error TSTL: Math.unknownProperty is unsupported."`;
10-
119
exports[`Unknown builtin property function call: code 1`] = `
1210
"local ____exports = {}
1311
____exports.__result = ({}):unknownFunction()
1412
return ____exports"
1513
`;
16-
17-
exports[`Unknown builtin property function call: diagnostics 1`] = `"main.ts(1,25): error TSTL: array.unknownFunction is unsupported."`;

test/unit/builtins/loading.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ test("lualib should not include tstl header", () => {
3939

4040
describe("Unknown builtin property", () => {
4141
test("access", () => {
42-
util.testExpression`Math.unknownProperty`.disableSemanticCheck().expectDiagnosticsToMatchSnapshot();
42+
util.testExpression`Math.unknownProperty`
43+
.disableSemanticCheck()
44+
.expectDiagnostics(m =>
45+
m.toMatchInlineSnapshot(`"main.ts(1,25): error TSTL: Math.unknownProperty is unsupported."`)
46+
);
4347
});
4448

4549
test("function call", () => {
46-
util.testExpression`[].unknownFunction()`.disableSemanticCheck().expectDiagnosticsToMatchSnapshot();
50+
util.testExpression`[].unknownFunction()`
51+
.disableSemanticCheck()
52+
.expectDiagnostics(m =>
53+
m.toMatchInlineSnapshot(`"main.ts(1,25): error TSTL: array.unknownFunction is unsupported."`)
54+
);
4755
});
4856
});

test/unit/bundle.spec.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ test("LuaLibImportKind.Inline generates a warning", () => {
9090
result.push(3);
9191
`
9292
.setOptions({ luaLibImport: LuaLibImportKind.Inline })
93-
.expectDiagnosticsToMatchSnapshot(true)
93+
.expectDiagnostics(
94+
m =>
95+
m.toMatchInlineSnapshot(
96+
`"warning TSTL: Using 'luaBundle' with 'luaLibImport: \\"inline\\"' might generate duplicate code. It is recommended to use 'luaLibImport: \\"require\\"'"`
97+
),
98+
true
99+
)
94100
.expectToEqual({ result: [1, 2, 3] });
95101
});
96102

@@ -113,9 +119,22 @@ test("cyclic imports", () => {
113119
});
114120

115121
test("no entry point", () => {
116-
util.testBundle``.setOptions({ luaBundleEntry: undefined }).expectDiagnosticsToMatchSnapshot(true);
122+
util.testBundle``
123+
.setOptions({ luaBundleEntry: undefined })
124+
.expectDiagnostics(
125+
m => m.toMatchInlineSnapshot(`"error TSTL: 'luaBundleEntry' is required when 'luaBundle' is enabled."`),
126+
true
127+
);
117128
});
118129

119130
test("luaEntry doesn't exist", () => {
120-
util.testBundle``.setEntryPoint("entry.ts").expectDiagnosticsToMatchSnapshot(true);
131+
util.testBundle``
132+
.setEntryPoint("entry.ts")
133+
.expectDiagnostics(
134+
m =>
135+
m.toMatchInlineSnapshot(
136+
`"error TSTL: Could not find bundle entry point 'entry.ts'. It should be a file in the project."`
137+
),
138+
true
139+
);
121140
});

test/unit/classes/__snapshots__/classes.spec.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ exports[`super without class: code 1`] = `
55
____exports.__result = ____.____constructor(self)
66
return ____exports"
77
`;
8-
9-
exports[`super without class: diagnostics 1`] = `"main.ts(1,25): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors."`;

test/unit/classes/__snapshots__/decorators.spec.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ function ____exports.__main(self)
1414
end
1515
return ____exports"
1616
`;
17-
18-
exports[`Throws error if decorator function has void context: diagnostics 1`] = `"main.ts(4,9): error TSTL: Decorator function cannot have 'this: void'."`;

test/unit/classes/classes.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ test("Subclass constructor across merged namespace", () => {
237237
});
238238

239239
test("super without class", () => {
240-
util.testExpression`super()`.expectDiagnosticsToMatchSnapshot();
240+
util.testExpression`super()`.expectDiagnostics(m =>
241+
m.toMatchInlineSnapshot(
242+
`"main.ts(1,25): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors."`
243+
)
244+
);
241245
});
242246

243247
test("super in unnamed class", () => {

test/unit/classes/decorators.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ test("Throws error if decorator function has void context", () => {
108108
109109
@decorator
110110
class TestClass {}
111-
`.expectDiagnosticsToMatchSnapshot();
111+
`.expectDiagnostics(m =>
112+
m.toMatchInlineSnapshot(`"main.ts(4,9): error TSTL: Decorator function cannot have 'this: void'."`)
113+
);
112114
});
113115

114116
test("Exported class decorator", () => {

test/unit/conditionals.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ test("switch not allowed in 5.1", () => {
315315
switch ("abc") {}
316316
`
317317
.setOptions({ luaTarget: tstl.LuaTarget.Lua51 })
318-
.expectDiagnosticsToMatchSnapshot();
318+
.expectDiagnostics(m =>
319+
m.toMatchInlineSnapshot(
320+
`"main.ts(2,9): error TSTL: Switch statements is/are not supported for target Lua 5.1."`
321+
)
322+
);
319323
});
320324

321325
test.each([

0 commit comments

Comments
 (0)