Skip to content

Commit fac16d2

Browse files
committed
test: add a special case for modulo for 5.0
1 parent 2836859 commit fac16d2

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,12 @@ ____exports.__result = nil
572572
return ____exports"
573573
`;
574574
575+
exports[`Translated binary expressions basic numeric [5.0] ("15%3") 1`] = `
576+
"local ____exports = {}
577+
____exports.__result = __TS__Modulo(15, 3)
578+
return ____exports"
579+
`;
580+
575581
exports[`Unary expressions basic ("!a") 1`] = `
576582
"local ____exports = {}
577583
function ____exports.__main(self)

test/unit/expressions.spec.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,56 @@ test.each([
1818
util.testFunction(input).disableSemanticCheck().expectLuaToMatchSnapshot();
1919
});
2020

21-
test.each(["3+4", "5-2", "6*3", "6**3", "20/5", "15/10", "15%3"])("Binary expressions basic numeric (%p)", input => {
22-
util.testExpression(input).expectToMatchJsResult();
21+
const numericSupportedInAll = ["3+4", "5-2", "6*3", "6**3", "20/5", "15/10"];
22+
const translatedIn50 = ["15%3"];
23+
const allNumericOperators = [...numericSupportedInAll, ...translatedIn50];
24+
test.each(numericSupportedInAll)("Binary expressions basic numeric [5.0] (%p)", input => {
25+
util.testExpression(input)
26+
.setOptions({ luaTarget: tstl.LuaTarget.Lua50, luaLibImport: tstl.LuaLibImportKind.None })
27+
.disableSemanticCheck()
28+
.expectToMatchJsResult();
29+
});
30+
31+
test.each(translatedIn50)("Translated binary expressions basic numeric [5.0] (%p)", input => {
32+
util.testExpression(input)
33+
.setOptions({ luaTarget: tstl.LuaTarget.Lua50, luaLibImport: tstl.LuaLibImportKind.None })
34+
.disableSemanticCheck()
35+
.expectLuaToMatchSnapshot();
36+
});
37+
38+
test.each(allNumericOperators)("Binary expressions basic numeric [5.1] (%p)", input => {
39+
util.testExpression(input)
40+
.setOptions({ luaTarget: tstl.LuaTarget.Lua51, luaLibImport: tstl.LuaLibImportKind.None })
41+
.disableSemanticCheck()
42+
.expectToMatchJsResult();
43+
});
44+
45+
test.each(allNumericOperators)("Binary expressions basic numeric [JIT] (%p)", input => {
46+
util.testExpression(input)
47+
.setOptions({ luaTarget: tstl.LuaTarget.LuaJIT, luaLibImport: tstl.LuaLibImportKind.None })
48+
.disableSemanticCheck()
49+
.expectToMatchJsResult();
50+
});
51+
52+
test.each(allNumericOperators)("Binary expressions basic numeric [5.2] (%p)", input => {
53+
util.testExpression(input)
54+
.setOptions({ luaTarget: tstl.LuaTarget.Lua52, luaLibImport: tstl.LuaLibImportKind.None })
55+
.disableSemanticCheck()
56+
.expectToMatchJsResult();
57+
});
58+
59+
test.each(allNumericOperators)("Binary expressions basic numeric [5.3] (%p)", input => {
60+
util.testExpression(input)
61+
.setOptions({ luaTarget: tstl.LuaTarget.Lua53, luaLibImport: tstl.LuaLibImportKind.None })
62+
.disableSemanticCheck()
63+
.expectToMatchJsResult();
64+
});
65+
66+
test.each(allNumericOperators)("Binary expressions basic numeric [5.4] (%p)", input => {
67+
util.testExpression(input)
68+
.setOptions({ luaTarget: tstl.LuaTarget.Lua54, luaLibImport: tstl.LuaLibImportKind.None })
69+
.disableSemanticCheck()
70+
.expectToMatchJsResult();
2371
});
2472

2573
test.each(["1==1", "1===1", "1!=1", "1!==1", "1>1", "1>=1", "1<1", "1<=1", "1&&1", "1||1"])(
@@ -45,9 +93,9 @@ test.each(["a+=b", "a-=b", "a*=b", "a/=b", "a%=b", "a**=b"])("Binary expressions
4593
`.expectToMatchJsResult();
4694
});
4795

48-
const supportedInAll = ["~a", "a&b", "a&=b", "a|b", "a|=b", "a^b", "a^=b", "a<<b", "a<<=b", "a>>>b", "a>>>=b"];
96+
const binarySupportedInAll = ["~a", "a&b", "a&=b", "a|b", "a|=b", "a^b", "a^=b", "a<<b", "a<<=b", "a>>>b", "a>>>=b"];
4997
const unsupportedIn53And54 = ["a>>b", "a>>=b"];
50-
const allBinaryOperators = [...supportedInAll, ...unsupportedIn53And54];
98+
const allBinaryOperators = [...binarySupportedInAll, ...unsupportedIn53And54];
5199
test.each(allBinaryOperators)("Bitop [5.0] (%p)", input => {
52100
// Bit operations not supported in 5.0, expect an exception
53101
util.testExpression(input)
@@ -78,14 +126,14 @@ test.each(allBinaryOperators)("Bitop [5.2] (%p)", input => {
78126
.expectLuaToMatchSnapshot();
79127
});
80128

81-
test.each(supportedInAll)("Bitop [5.3] (%p)", input => {
129+
test.each(binarySupportedInAll)("Bitop [5.3] (%p)", input => {
82130
util.testExpression(input)
83131
.setOptions({ luaTarget: tstl.LuaTarget.Lua53, luaLibImport: tstl.LuaLibImportKind.None })
84132
.disableSemanticCheck()
85133
.expectLuaToMatchSnapshot();
86134
});
87135

88-
test.each(supportedInAll)("Bitop [5.4] (%p)", input => {
136+
test.each(binarySupportedInAll)("Bitop [5.4] (%p)", input => {
89137
util.testExpression(input)
90138
.setOptions({ luaTarget: tstl.LuaTarget.Lua54, luaLibImport: tstl.LuaLibImportKind.None })
91139
.disableSemanticCheck()

0 commit comments

Comments
 (0)