@@ -108,29 +108,32 @@ test("numbers overflowing the float limit become math.huge", () => {
108108 util . testExpression `1e309` . expectToMatchJsResult ( ) ;
109109} ) ;
110110
111- describe . each ( [ "parseInt" , "parseFloat" ] ) ( "parse numbers with %s" , parseFunction => {
112- const numberStrings = [ "3" , "3.0" , "9" , "42" , "239810241" , "-20391" , "3.1415" , "2.7182" , "-34910.3" ] ;
111+ describe . each ( [ "parseInt" , "parseFloat" , "Number.parseInt" , "Number.parseFloat" ] ) (
112+ "parse numbers with %s" ,
113+ parseFunction => {
114+ const numberStrings = [ "3" , "3.0" , "9" , "42" , "239810241" , "-20391" , "3.1415" , "2.7182" , "-34910.3" ] ;
113115
114- test . each ( numberStrings ) ( "parses (%s)" , numberString => {
115- util . testExpression `${ parseFunction } ("${ numberString } ")` . expectToMatchJsResult ( ) ;
116- } ) ;
116+ test . each ( numberStrings ) ( "parses (%s)" , numberString => {
117+ util . testExpression `${ parseFunction } ("${ numberString } ")` . expectToMatchJsResult ( ) ;
118+ } ) ;
117119
118- test ( "empty string" , ( ) => {
119- util . testExpression `${ parseFunction } ("")` . expectToMatchJsResult ( ) ;
120- } ) ;
120+ test ( "empty string" , ( ) => {
121+ util . testExpression `${ parseFunction } ("")` . expectToMatchJsResult ( ) ;
122+ } ) ;
121123
122- test ( "invalid string" , ( ) => {
123- util . testExpression `${ parseFunction } ("bla")` . expectToMatchJsResult ( ) ;
124- } ) ;
124+ test ( "invalid string" , ( ) => {
125+ util . testExpression `${ parseFunction } ("bla")` . expectToMatchJsResult ( ) ;
126+ } ) ;
125127
126- test . each ( [ "1px" , "2300m" , "3,4" , "452adkfl" ] ) ( "trailing text (%s)" , numberString => {
127- util . testExpression `${ parseFunction } ("${ numberString } ")` . expectToMatchJsResult ( ) ;
128- } ) ;
128+ test . each ( [ "1px" , "2300m" , "3,4" , "452adkfl" ] ) ( "trailing text (%s)" , numberString => {
129+ util . testExpression `${ parseFunction } ("${ numberString } ")` . expectToMatchJsResult ( ) ;
130+ } ) ;
129131
130- test . each ( [ " 3" , " 4" , " -231" , " 1px" ] ) ( "leading whitespace (%s)" , numberString => {
131- util . testExpression `${ parseFunction } ("${ numberString } ")` . expectToMatchJsResult ( ) ;
132- } ) ;
133- } ) ;
132+ test . each ( [ " 3" , " 4" , " -231" , " 1px" ] ) ( "leading whitespace (%s)" , numberString => {
133+ util . testExpression `${ parseFunction } ("${ numberString } ")` . expectToMatchJsResult ( ) ;
134+ } ) ;
135+ }
136+ ) ;
134137
135138test . each ( [ "Infinity" , "-Infinity" , " -Infinity" ] ) ( "parseFloat handles Infinity" , numberString => {
136139 util . testExpression `parseFloat("${ numberString } ")` . expectToMatchJsResult ( ) ;
@@ -162,6 +165,36 @@ test.each([
162165 util . testExpression `parseInt("${ numberString } ", ${ base } )` . expectToMatchJsResult ( ) ;
163166} ) ;
164167
168+ test . each ( [ "Infinity" , "-Infinity" , " -Infinity" ] ) ( "Number.parseFloat handles Infinity" , numberString => {
169+ util . testExpression `Number.parseFloat("${ numberString } ")` . expectToMatchJsResult ( ) ;
170+ } ) ;
171+
172+ test . each ( [
173+ { numberString : "36" , base : 8 } ,
174+ { numberString : "-36" , base : 8 } ,
175+ { numberString : "100010101101" , base : 2 } ,
176+ { numberString : "-100010101101" , base : 2 } ,
177+ { numberString : "3F" , base : 16 } ,
178+ ] ) ( "Number.parseInt with base (%p)" , ( { numberString, base } ) => {
179+ util . testExpression `Number.parseInt("${ numberString } ", ${ base } )` . expectToMatchJsResult ( ) ;
180+ } ) ;
181+
182+ test . each ( [ "0x4A" , "-0x42" , "0X42" , " 0x391" , " -0x8F" ] ) ( "Number.parseInt detects hexadecimal" , numberString => {
183+ util . testExpression `Number.parseInt("${ numberString } ")` . expectToMatchJsResult ( ) ;
184+ } ) ;
185+
186+ test . each ( [ 1 , 37 , - 100 ] ) ( "Number.parseInt with invalid base (%p)" , base => {
187+ util . testExpression `Number.parseInt("11111", ${ base } )` . expectToMatchJsResult ( ) ;
188+ } ) ;
189+
190+ test . each ( [
191+ { numberString : "36px" , base : 8 } ,
192+ { numberString : "10001010110231" , base : 2 } ,
193+ { numberString : "3Fcolor" , base : 16 } ,
194+ ] ) ( "Number.parseInt with base and trailing text (%p)" , ( { numberString, base } ) => {
195+ util . testExpression `Number.parseInt("${ numberString } ", ${ base } )` . expectToMatchJsResult ( ) ;
196+ } ) ;
197+
165198// Issue #1218: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1218
166199test . each ( [ "42" , "undefined" ] ) ( "prototype call on nullable number (%p)" , value => {
167200 util . testFunction `
0 commit comments