11import * as tstl from "../../src" ;
2- import { unsupportedForTarget } from "../../src/transformation/utils/diagnostics" ;
2+ import { unsupportedForTarget , unsupportedRightShiftOperator } from "../../src/transformation/utils/diagnostics" ;
33import * as util from "../util" ;
44
55test . each ( [
@@ -49,22 +49,9 @@ test.each(["a+=b", "a-=b", "a*=b", "a/=b", "a%=b", "a**=b"])("Binary expressions
4949 ` . expectToMatchJsResult ( ) ;
5050} ) ;
5151
52- const supportedInAll = [
53- "~a" ,
54- "a&b" ,
55- "a&=b" ,
56- "a|b" ,
57- "a|=b" ,
58- "a^b" ,
59- "a^=b" ,
60- "a<<b" ,
61- "a<<=b" ,
62- "a>>b" ,
63- "a>>=b" ,
64- "a>>>b" ,
65- "a>>>=b" ,
66- ] ;
67- const allBinaryOperators = supportedInAll ;
52+ const supportedInAll = [ "~a" , "a&b" , "a&=b" , "a|b" , "a|=b" , "a^b" , "a^=b" , "a<<b" , "a<<=b" , "a>>>b" , "a>>>=b" ] ;
53+ const unsupportedIn53And54 = [ "a>>b" , "a>>=b" ] ;
54+ const allBinaryOperators = [ ...supportedInAll , ...unsupportedIn53And54 ] ;
6855test . each ( allBinaryOperators ) ( "Bitop [5.0] (%p)" , input => {
6956 // Bit operations not supported in 5.0, expect an exception
7057 util . testExpression ( input )
@@ -116,6 +103,20 @@ test.each(supportedInAll)("Bitop [5.5] (%p)", input => {
116103 . expectLuaToMatchSnapshot ( ) ;
117104} ) ;
118105
106+ test . each ( unsupportedIn53And54 ) ( "Unsupported bitop 5.3 (%p)" , input => {
107+ util . testExpression ( input )
108+ . setOptions ( { luaTarget : tstl . LuaTarget . Lua53 , luaLibImport : tstl . LuaLibImportKind . None } )
109+ . disableSemanticCheck ( )
110+ . expectDiagnosticsToMatchSnapshot ( [ unsupportedRightShiftOperator . code ] ) ;
111+ } ) ;
112+
113+ test . each ( unsupportedIn53And54 ) ( "Unsupported bitop 5.4 (%p)" , input => {
114+ util . testExpression ( input )
115+ . setOptions ( { luaTarget : tstl . LuaTarget . Lua54 , luaLibImport : tstl . LuaLibImportKind . None } )
116+ . disableSemanticCheck ( )
117+ . expectDiagnosticsToMatchSnapshot ( [ unsupportedRightShiftOperator . code ] ) ;
118+ } ) ;
119+
119120// Execution tests: verify >>> produces correct results matching JS semantics
120121for ( const expression of [ "-5 >>> 0" , "-1 >>> 0" , "1 >>> 0" , "-1 >>> 16" , "255 >>> 4" ] ) {
121122 util . testEachVersion ( `Unsigned right shift execution (${ expression } )` , ( ) => util . testExpression ( expression ) , {
@@ -131,36 +132,6 @@ for (const expression of ["-5 >>> 0", "-1 >>> 0", "1 >>> 0", "-1 >>> 16", "255 >
131132 } ) ;
132133}
133134
134- // Execution tests: verify >> produces correct results matching JS semantics
135- for ( const expression of [
136- "-8 >> 1" ,
137- "-1 >> 0" ,
138- "-1 >> 16" ,
139- "0x7FFFFFFF >> 0" ,
140- "255 >> 4" ,
141- "5 >> 1" ,
142- "-1 >> 31" ,
143- "0x7FFFFFFF >> 31" ,
144- "0x80000000 >> 31" ,
145- "1 >> 31" ,
146- "-8 >> 32" ,
147- "1 >> 32" ,
148- "-8 >> 33" ,
149- "-1 >> 63" ,
150- ] ) {
151- util . testEachVersion ( `Signed right shift execution (${ expression } )` , ( ) => util . testExpression ( expression ) , {
152- [ tstl . LuaTarget . Universal ] : false ,
153- [ tstl . LuaTarget . Lua50 ] : false , // No bit library in WASM runtime
154- [ tstl . LuaTarget . Lua51 ] : false , // No bit library in WASM runtime
155- [ tstl . LuaTarget . Lua52 ] : false , // bit32.arshift returns uint32, not int32
156- [ tstl . LuaTarget . Lua53 ] : builder => builder . expectToMatchJsResult ( ) ,
157- [ tstl . LuaTarget . Lua54 ] : builder => builder . expectToMatchJsResult ( ) ,
158- [ tstl . LuaTarget . Lua55 ] : builder => builder . expectToMatchJsResult ( ) ,
159- [ tstl . LuaTarget . LuaJIT ] : false , // Can't execute LuaJIT in tests
160- [ tstl . LuaTarget . Luau ] : false ,
161- } ) ;
162- }
163-
164135for ( const code of [ "let a = -5; a >>>= 0; return a;" , "let a = -1; a >>>= 16; return a;" ] ) {
165136 util . testEachVersion ( `Unsigned right shift assignment execution (${ code } )` , ( ) => util . testFunction ( code ) , {
166137 [ tstl . LuaTarget . Universal ] : false ,
@@ -175,20 +146,6 @@ for (const code of ["let a = -5; a >>>= 0; return a;", "let a = -1; a >>>= 16; r
175146 } ) ;
176147}
177148
178- for ( const code of [ "let a = -8; a >>= 1; return a;" , "let a = -1; a >>= 16; return a;" ] ) {
179- util . testEachVersion ( `Signed right shift assignment execution (${ code } )` , ( ) => util . testFunction ( code ) , {
180- [ tstl . LuaTarget . Universal ] : false ,
181- [ tstl . LuaTarget . Lua50 ] : false , // No bit library in WASM runtime
182- [ tstl . LuaTarget . Lua51 ] : false , // No bit library in WASM runtime
183- [ tstl . LuaTarget . Lua52 ] : false , // bit32.arshift returns uint32, not int32
184- [ tstl . LuaTarget . Lua53 ] : builder => builder . expectToMatchJsResult ( ) ,
185- [ tstl . LuaTarget . Lua54 ] : builder => builder . expectToMatchJsResult ( ) ,
186- [ tstl . LuaTarget . Lua55 ] : builder => builder . expectToMatchJsResult ( ) ,
187- [ tstl . LuaTarget . LuaJIT ] : false , // Can't execute LuaJIT in tests
188- [ tstl . LuaTarget . Luau ] : false ,
189- } ) ;
190- }
191-
192149test . each ( [ "1+1" , "-1+1" , "1*30+4" , "1*(3+4)" , "1*(3+4*2)" , "10-(4+5)" ] ) (
193150 "Binary expressions ordering parentheses (%p)" ,
194151 input => {
0 commit comments