@@ -116,13 +116,19 @@ export class ExpressionTests {
116116 @TestCase ( "a<<=b" , "a=a<<b" )
117117 @TestCase ( "a>>b" , "a>>b" )
118118 @TestCase ( "a>>=b" , "a=a>>b" )
119- @TestCase ( "a>>>b" , "a>>>b" )
120- @TestCase ( "a>>>=b" , "a=a>>>b" )
121119 @Test ( "Bitop [5.3]" )
122120 public bitOperatorOverride53 ( input : string , lua : string ) {
123121 Expect ( util . transpileString ( input , { luaTarget : "5.3" , dontRequireLuaLib : true } ) ) . toBe ( lua ) ;
124122 }
125123
124+ @TestCase ( "a>>>b" )
125+ @TestCase ( "a>>>=b" )
126+ @Test ( "Unsupported bitop 5.3" )
127+ public bitOperatorOverride53Unsupported ( input : string ) {
128+ Expect ( ( ) => util . transpileString ( input , { luaTarget : "5.3" , dontRequireLuaLib : true } ) )
129+ . toThrowError ( Error , "Bitwise operator >>> not supported" ) ;
130+ }
131+
126132 @TestCase ( "1+1" , "1+1" )
127133 @TestCase ( "-1+1" , "-1+1" )
128134 @TestCase ( "1*30+4" , "(1*30)+4" )
@@ -281,4 +287,119 @@ export class ExpressionTests {
281287 // Assert
282288 Expect ( result ) . toBe ( expected ) ;
283289 }
290+
291+ // ====================================
292+ // Test expected errors
293+ // ====================================
294+
295+ @Test ( "Unknown unary postfix error" )
296+ public unknownUnaryPostfixError ( ) {
297+ const transpiler = util . makeTestTranspiler ( ) ;
298+
299+ const mockExpression : any = {
300+ operand : ts . createLiteral ( false ) ,
301+ operator : ts . SyntaxKind . AsteriskToken ,
302+ } ;
303+
304+ Expect ( ( ) => transpiler . transpilePostfixUnaryExpression ( mockExpression as ts . PostfixUnaryExpression ) )
305+ . toThrowError ( Error , "Unsupported unary postfix: AsteriskToken" ) ;
306+ }
307+
308+ @Test ( "Unknown unary postfix error" )
309+ public unknownUnaryPrefixError ( ) {
310+ const transpiler = util . makeTestTranspiler ( ) ;
311+
312+ const mockExpression : any = {
313+ operand : ts . createLiteral ( false ) ,
314+ operator : ts . SyntaxKind . AsteriskToken ,
315+ } ;
316+
317+ Expect ( ( ) => transpiler . transpilePrefixUnaryExpression ( mockExpression as ts . PrefixUnaryExpression ) )
318+ . toThrowError ( Error , "Unsupported unary prefix: AsteriskToken" ) ;
319+ }
320+
321+ @Test ( "Incompatible fromCodePoint expression error" )
322+ public incompatibleFromCodePointExpression ( ) {
323+ const transpiler = util . makeTestTranspiler ( LuaTarget . LuaJIT ) ;
324+
325+ const identifier = ts . createIdentifier ( "fromCodePoint" ) ;
326+ Expect ( ( ) => transpiler . transpileStringExpression ( identifier ) )
327+ . toThrowError ( Error , "Unsupported string property fromCodePoint is only supported for lua 5.3." ) ;
328+ }
329+
330+ @Test ( "Unknown string expression error" )
331+ public unknownStringExpression ( ) {
332+ const transpiler = util . makeTestTranspiler ( LuaTarget . LuaJIT ) ;
333+
334+ const identifier = ts . createIdentifier ( "abcd" ) ;
335+ Expect ( ( ) => transpiler . transpileStringExpression ( identifier ) )
336+ . toThrowError ( Error , "Unsupported string property abcd." ) ;
337+ }
338+
339+ @Test ( "Unsupported array function error" )
340+ public unsupportedArrayFunctionError ( ) {
341+ const transpiler = util . makeTestTranspiler ( ) ;
342+
343+ const mockNode : any = {
344+ arguments : [ ] ,
345+ caller : ts . createLiteral ( false ) ,
346+ expression : { name : ts . createIdentifier ( "unknownFunction" ) , expression : ts . createLiteral ( false ) } ,
347+ } ;
348+
349+ Expect ( ( ) => transpiler . transpileArrayCallExpression ( mockNode as ts . CallExpression ) )
350+ . toThrowError ( Error , "Unsupported array function: unknownFunction" ) ;
351+ }
352+
353+ @Test ( "Unsupported array property error" )
354+ public unsupportedArrayPropertyError ( ) {
355+ const transpiler = util . makeTestTranspiler ( ) ;
356+
357+ const mockNode : any = {
358+ name : ts . createIdentifier ( "unknownProperty" ) ,
359+ } ;
360+
361+ Expect ( ( ) => transpiler . transpileArrayProperty ( mockNode as ts . PropertyAccessExpression ) )
362+ . toThrowError ( Error , "Unsupported array property: unknownProperty" ) ;
363+ }
364+
365+ @Test ( "Unsupported math property error" )
366+ public unsupportedMathPropertyError ( ) {
367+ const transpiler = util . makeTestTranspiler ( ) ;
368+
369+ Expect ( ( ) => transpiler . transpileMathExpression ( ts . createIdentifier ( "unknownProperty" ) ) )
370+ . toThrowError ( Error , "Unsupported math property: unknownProperty." ) ;
371+ }
372+
373+ @Test ( "Unsupported variable declaration type error" )
374+ public unsupportedVariableDeclarationType ( ) {
375+ const transpiler = util . makeTestTranspiler ( ) ;
376+
377+ const mockNode : any = { name : ts . createLiteral ( false ) } ;
378+
379+ Expect ( ( ) => transpiler . transpileVariableDeclaration ( mockNode as ts . VariableDeclaration ) )
380+ . toThrowError ( Error , "Unsupported variable declaration type: FalseKeyword" ) ;
381+ }
382+
383+ @Test ( "Class without name error" )
384+ public classWithoutNameError ( ) {
385+ const transpiler = util . makeTestTranspiler ( ) ;
386+
387+ Expect ( ( ) => transpiler . transpileClass ( { } as ts . ClassDeclaration ) )
388+ . toThrowError ( Error , "Unexpected Error: Node has no Name" ) ;
389+ }
390+
391+ @Test ( "Unsupported object literal element error" )
392+ public unsupportedObjectLiteralElementError ( ) {
393+ const transpiler = util . makeTestTranspiler ( ) ;
394+
395+ const mockObject : any = {
396+ properties : [ {
397+ kind : ts . SyntaxKind . FalseKeyword ,
398+ name : ts . createIdentifier ( "testProperty" ) ,
399+ } ] ,
400+ } ;
401+
402+ Expect ( ( ) => transpiler . transpileObjectLiteral ( mockObject as ts . ObjectLiteralExpression ) )
403+ . toThrowError ( Error , "Encountered unsupported object literal element: FalseKeyword." ) ;
404+ }
284405}
0 commit comments