@@ -69,6 +69,27 @@ test.each([
6969 util . testExpressionTemplate `(${ value } ).toString(2)` . expectToEqual ( luaNativeSpecialNumString ) ;
7070} ) ;
7171
72+ const toFixedFractions = [ undefined , 0 , 1 , 2 , Math . PI , 5 , 99 ] ;
73+ // 1.5, 1.25 and 1.125 fails as rounding differ
74+ const toFixedValues = [ - 1 , 0 , 1 , Math . PI , - 1.1234 , - 9.99e19 , 1e22 ] ;
75+ const toFixedPairs = toFixedValues . flatMap ( value => toFixedFractions . map ( frac => [ value , frac ] as const ) ) ;
76+ test . each ( toFixedPairs ) ( "(%p).toFixed(%p)" , ( value , frac ) => {
77+ util . testExpressionTemplate `(${ value } ).toFixed(${ frac } )` . expectToMatchJsResult ( ) ;
78+ } ) ;
79+
80+ test . each ( [
81+ [ NaN , "(0/0)" ] ,
82+ [ Infinity , "(1/0)" ] ,
83+ [ - Infinity , "(-(1/0))" ] ,
84+ ] ) ( "%p.toFixed(2)" , ( value , luaNativeSpecialNum ) => {
85+ // Need to get the actual lua tostring version of inf/nan
86+ // this is platform dependent so we can/should not hardcode it
87+ const luaNativeSpecialNumString = util . testExpression `${ luaNativeSpecialNum } .toString()` . getLuaExecutionResult ( ) ;
88+ // Cannot use expectToMatchJsResult because this actually wont be the same in JS in Lua
89+ // TODO fix this in lualib/NumberToString.ts
90+ util . testExpressionTemplate `(${ value } ).toFixed(2)` . expectToEqual ( luaNativeSpecialNumString ) ;
91+ } ) ;
92+
7293test . each ( cases ) ( "isNaN(%p)" , value => {
7394 util . testExpressionTemplate `isNaN(${ value } as any)` . expectToMatchJsResult ( ) ;
7495} ) ;
0 commit comments