Skip to content

Commit 1dba060

Browse files
committed
clean up tests
1 parent 7cb97ad commit 1dba060

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

test/translation/__snapshots__/transformation.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Luau Transformation (luauSpecificTransformations) 1`] = `
3+
exports[`Luau-specific Transformation (luauSpecificTransformations) 1`] = `
44
"t = if true then "is true" else "is false"
55
while false do
66
continue

test/translation/transformation.spec.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,32 @@ import { annotationDeprecated } from "../../src/transformation/utils/diagnostics
55
import { couldNotResolveRequire } from "../../src/transpilation/diagnostics";
66
import * as util from "../util";
77

8-
const targetSpecs: Array<[string, tstl.LuaTarget | undefined, string]> = [
9-
["", undefined, "./transformation"],
10-
["Luau ", tstl.LuaTarget.Luau, "./transformation/luau"],
11-
];
8+
const fixturesPath = path.join(__dirname, "./transformation");
9+
const fixtures = fs
10+
.readdirSync(fixturesPath)
11+
.filter(f => path.extname(f) === ".ts")
12+
.sort()
13+
.map(f => [path.parse(f).name, fs.readFileSync(path.join(fixturesPath, f), "utf8")]);
1214

13-
for (const [name, luaTarget, targetDir] of targetSpecs) {
14-
const fixturesPath = path.join(__dirname, targetDir);
15-
const fixtures = fs
16-
.readdirSync(fixturesPath)
17-
.filter(f => path.extname(f) === ".ts")
18-
.sort()
19-
.map(f => [path.parse(f).name, fs.readFileSync(path.join(fixturesPath, f), "utf8")]);
15+
test.each(fixtures)("Transformation (%s)", (_name, content) => {
16+
util.testModule(content)
17+
.setOptions({ luaLibImport: tstl.LuaLibImportKind.Require })
18+
.ignoreDiagnostics([annotationDeprecated.code, couldNotResolveRequire.code])
19+
.disableSemanticCheck()
20+
.expectLuaToMatchSnapshot();
21+
});
2022

21-
test.each(fixtures)(`${name}Transformation (%s)`, (_name, content) => {
22-
util.testModule(content)
23-
.setOptions({
24-
luaLibImport: tstl.LuaLibImportKind.Require,
25-
luaTarget,
26-
})
27-
.ignoreDiagnostics([annotationDeprecated.code, couldNotResolveRequire.code])
28-
.disableSemanticCheck()
29-
.expectLuaToMatchSnapshot();
30-
});
31-
}
23+
const luauFixturesPath = path.join(fixturesPath, "luau");
24+
const luauFixtures = fs
25+
.readdirSync(luauFixturesPath)
26+
.filter(f => path.extname(f) === ".ts")
27+
.sort()
28+
.map(f => [path.parse(f).name, fs.readFileSync(path.join(luauFixturesPath, f), "utf8")]);
29+
30+
test.each(luauFixtures)("Luau-specific Transformation (%s)", (_name, content) => {
31+
util.testModule(content)
32+
.setOptions({ luaLibImport: tstl.LuaLibImportKind.Require, luaTarget: tstl.LuaTarget.Luau })
33+
.ignoreDiagnostics([annotationDeprecated.code, couldNotResolveRequire.code])
34+
.disableSemanticCheck()
35+
.expectLuaToMatchSnapshot();
36+
});

test/unit/builtins/array.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,7 @@ test("new Array()", () => {
907907
const arr = new Array();
908908
arr.push(1,2,3);
909909
return arr;
910-
`
911-
.debug()
912-
.expectToMatchJsResult();
910+
`.expectToMatchJsResult();
913911
});
914912

915913
test("new Array<T>()", () => {

test/unit/loops.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ for (const testCase of [
545545
const expectContinueGotoLabel: util.TapCallback = builder =>
546546
expect(builder.getMainLuaCodeChunk()).toMatch("::__continue2::");
547547

548+
const expectContinueStatement: util.TapCallback = builder =>
549+
expect(builder.getMainLuaCodeChunk()).toMatch("continue;");
550+
548551
util.testEachVersion(`loop continue (${testCase})`, () => util.testModule(testCase), {
549552
[tstl.LuaTarget.Universal]: expectContinueVariable,
550553
[tstl.LuaTarget.Lua50]: expectContinueVariable,
@@ -553,7 +556,7 @@ for (const testCase of [
553556
[tstl.LuaTarget.Lua53]: expectContinueGotoLabel,
554557
[tstl.LuaTarget.Lua54]: expectContinueGotoLabel,
555558
[tstl.LuaTarget.LuaJIT]: expectContinueGotoLabel,
556-
[tstl.LuaTarget.Luau]: () => undefined, // TODO: This is N/A.
559+
[tstl.LuaTarget.Luau]: () => expectContinueStatement,
557560
});
558561
}
559562

0 commit comments

Comments
 (0)