@ -1,11 +1,12 @@
use boa_macros ::js_str ;
use crate ::{
builtins ::Number , js_string , run_test_actions , value ::AbstractRelation , JsNativeErrorKind ,
TestAction ,
builtins ::Number , run_test_actions , value ::AbstractRelation , JsNativeErrorKind , TestAction ,
} ;
#[ test ]
fn integer_number_primitive_to_number_object ( ) {
run_test_actions ( [ TestAction ::assert_eq ( "(100).toString()" , js_string ! ( "100" ) ) ] ) ;
run_test_actions ( [ TestAction ::assert_eq ( "(100).toString()" , js_str ! ( "100" ) ) ] ) ;
}
#[ test ]
@ -25,136 +26,133 @@ fn call_number() {
#[ test ]
fn to_exponential ( ) {
run_test_actions ( [
TestAction ::assert_eq ( "Number().toExponential()" , js_string ! ( "0e+0" ) ) ,
TestAction ::assert_eq ( "Number(5).toExponential()" , js_string ! ( "5e+0" ) ) ,
TestAction ::assert_eq ( "Number(1.234).toExponential()" , js_string ! ( "1.234e+0" ) ) ,
TestAction ::assert_eq ( "Number(1234).toExponential()" , js_string ! ( "1.234e+3" ) ) ,
TestAction ::assert_eq ( "Number().toExponential()" , js_str ! ( "0e+0" ) ) ,
TestAction ::assert_eq ( "Number(5).toExponential()" , js_str ! ( "5e+0" ) ) ,
TestAction ::assert_eq ( "Number(1.234).toExponential()" , js_str ! ( "1.234e+0" ) ) ,
TestAction ::assert_eq ( "Number(1234).toExponential()" , js_str ! ( "1.234e+3" ) ) ,
TestAction ::assert_eq (
"Number('I am also not a number').toExponential()" ,
js_string ! ( "NaN" ) ,
js_str ! ( "NaN" ) ,
) ,
TestAction ::assert_eq ( "Number('1.23e+2').toExponential()" , js_string ! ( "1.23e+2" ) ) ,
TestAction ::assert_eq ( "Number('1.23e+2').toExponential()" , js_str ! ( "1.23e+2" ) ) ,
] ) ;
}
#[ test ]
fn to_fixed ( ) {
run_test_actions ( [
TestAction ::assert_eq ( "Number().toFixed()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number('3.456e+4').toFixed()" , js_string ! ( "34560" ) ) ,
TestAction ::assert_eq ( "Number('3.456e-4').toFixed()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(5).toFixed()" , js_string ! ( "5" ) ) ,
TestAction ::assert_eq (
"Number('I am also not a number').toFixed()" ,
js_string ! ( "NaN" ) ,
) ,
TestAction ::assert_eq ( "(1.35).toFixed(1)" , js_string ! ( "1.4" ) ) ,
TestAction ::assert_eq ( "Number().toFixed()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number('3.456e+4').toFixed()" , js_str ! ( "34560" ) ) ,
TestAction ::assert_eq ( "Number('3.456e-4').toFixed()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(5).toFixed()" , js_str ! ( "5" ) ) ,
TestAction ::assert_eq ( "Number('I am also not a number').toFixed()" , js_str ! ( "NaN" ) ) ,
TestAction ::assert_eq ( "(1.35).toFixed(1)" , js_str ! ( "1.4" ) ) ,
// Test cases from https://source.chromium.org/chromium/chromium/src/+/main:v8/test/mjsunit/number-tostring-func.js;l=157-240;drc=aa3518a0f37245ebe8f062dce97ee492e2a41652
TestAction ::assert_eq ( "(NaN).toFixed(2)" , js_string ! ( "NaN" ) ) ,
TestAction ::assert_eq ( "(1/0).toFixed(2)" , js_string ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "(-1/0).toFixed(2)" , js_string ! ( "-Infinity" ) ) ,
TestAction ::assert_eq ( "(NaN).toFixed(2)" , js_str ! ( "NaN" ) ) ,
TestAction ::assert_eq ( "(1/0).toFixed(2)" , js_str ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "(-1/0).toFixed(2)" , js_str ! ( "-Infinity" ) ) ,
TestAction ::assert_eq (
"(1111111111111111111111).toFixed(8)" ,
js_string ! ( "1.1111111111111111e+21" ) ,
) ,
TestAction ::assert_eq ( "(0.1).toFixed(1)" , js_string ! ( "0.1" ) ) ,
TestAction ::assert_eq ( "(0.1).toFixed(2)" , js_string ! ( "0.10" ) ) ,
TestAction ::assert_eq ( "(0.1).toFixed(3)" , js_string ! ( "0.100" ) ) ,
TestAction ::assert_eq ( "(0.01).toFixed(2)" , js_string ! ( "0.01" ) ) ,
TestAction ::assert_eq ( "(0.01).toFixed(3)" , js_string ! ( "0.010" ) ) ,
TestAction ::assert_eq ( "(0.01).toFixed(4)" , js_string ! ( "0.0100" ) ) ,
TestAction ::assert_eq ( "(0.001).toFixed(2)" , js_string ! ( "0.00" ) ) ,
TestAction ::assert_eq ( "(0.001).toFixed(3)" , js_string ! ( "0.001" ) ) ,
TestAction ::assert_eq ( "(0.001).toFixed(4)" , js_string ! ( "0.0010" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(4)" , js_string ! ( "1.0000" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(1)" , js_string ! ( "1.0" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(0)" , js_string ! ( "1" ) ) ,
TestAction ::assert_eq ( "(12).toFixed(0)" , js_string ! ( "12" ) ) ,
TestAction ::assert_eq ( "(1.1).toFixed(0)" , js_string ! ( "1" ) ) ,
TestAction ::assert_eq ( "(12.1).toFixed(0)" , js_string ! ( "12" ) ) ,
TestAction ::assert_eq ( "(1.12).toFixed(0)" , js_string ! ( "1" ) ) ,
TestAction ::assert_eq ( "(12.12).toFixed(0)" , js_string ! ( "12" ) ) ,
TestAction ::assert_eq ( "(0.0000006).toFixed(7)" , js_string ! ( "0.0000006" ) ) ,
TestAction ::assert_eq ( "(0.00000006).toFixed(8)" , js_string ! ( "0.00000006" ) ) ,
TestAction ::assert_eq ( "(0.00000006).toFixed(9)" , js_string ! ( "0.000000060" ) ) ,
TestAction ::assert_eq ( "(0.00000006).toFixed(10)" , js_string ! ( "0.0000000600" ) ) ,
TestAction ::assert_eq ( "(0).toFixed(0)" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "(0).toFixed(1)" , js_string ! ( "0.0" ) ) ,
TestAction ::assert_eq ( "(0).toFixed(2)" , js_string ! ( "0.00" ) ) ,
js_str ! ( "1.1111111111111111e+21" ) ,
) ,
TestAction ::assert_eq ( "(0.1).toFixed(1)" , js_str ! ( "0.1" ) ) ,
TestAction ::assert_eq ( "(0.1).toFixed(2)" , js_str ! ( "0.10" ) ) ,
TestAction ::assert_eq ( "(0.1).toFixed(3)" , js_str ! ( "0.100" ) ) ,
TestAction ::assert_eq ( "(0.01).toFixed(2)" , js_str ! ( "0.01" ) ) ,
TestAction ::assert_eq ( "(0.01).toFixed(3)" , js_str ! ( "0.010" ) ) ,
TestAction ::assert_eq ( "(0.01).toFixed(4)" , js_str ! ( "0.0100" ) ) ,
TestAction ::assert_eq ( "(0.001).toFixed(2)" , js_str ! ( "0.00" ) ) ,
TestAction ::assert_eq ( "(0.001).toFixed(3)" , js_str ! ( "0.001" ) ) ,
TestAction ::assert_eq ( "(0.001).toFixed(4)" , js_str ! ( "0.0010" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(4)" , js_str ! ( "1.0000" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(1)" , js_str ! ( "1.0" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(0)" , js_str ! ( "1" ) ) ,
TestAction ::assert_eq ( "(12).toFixed(0)" , js_str ! ( "12" ) ) ,
TestAction ::assert_eq ( "(1.1).toFixed(0)" , js_str ! ( "1" ) ) ,
TestAction ::assert_eq ( "(12.1).toFixed(0)" , js_str ! ( "12" ) ) ,
TestAction ::assert_eq ( "(1.12).toFixed(0)" , js_str ! ( "1" ) ) ,
TestAction ::assert_eq ( "(12.12).toFixed(0)" , js_str ! ( "12" ) ) ,
TestAction ::assert_eq ( "(0.0000006).toFixed(7)" , js_str ! ( "0.0000006" ) ) ,
TestAction ::assert_eq ( "(0.00000006).toFixed(8)" , js_str ! ( "0.00000006" ) ) ,
TestAction ::assert_eq ( "(0.00000006).toFixed(9)" , js_str ! ( "0.000000060" ) ) ,
TestAction ::assert_eq ( "(0.00000006).toFixed(10)" , js_str ! ( "0.0000000600" ) ) ,
TestAction ::assert_eq ( "(0).toFixed(0)" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "(0).toFixed(1)" , js_str ! ( "0.0" ) ) ,
TestAction ::assert_eq ( "(0).toFixed(2)" , js_str ! ( "0.00" ) ) ,
TestAction ::assert_eq (
"(-1111111111111111111111).toFixed(8)" ,
js_string ! ( "-1.1111111111111111e+21" ) ,
) ,
TestAction ::assert_eq ( "(-0.1).toFixed(1)" , js_string ! ( "-0.1" ) ) ,
TestAction ::assert_eq ( "(-0.1).toFixed(2)" , js_string ! ( "-0.10" ) ) ,
TestAction ::assert_eq ( "(-0.1).toFixed(3)" , js_string ! ( "-0.100" ) ) ,
TestAction ::assert_eq ( "(-0.01).toFixed(2)" , js_string ! ( "-0.01" ) ) ,
TestAction ::assert_eq ( "(-0.01).toFixed(3)" , js_string ! ( "-0.010" ) ) ,
TestAction ::assert_eq ( "(-0.01).toFixed(4)" , js_string ! ( "-0.0100" ) ) ,
TestAction ::assert_eq ( "(-0.001).toFixed(2)" , js_string ! ( "-0.00" ) ) ,
TestAction ::assert_eq ( "(-0.001).toFixed(3)" , js_string ! ( "-0.001" ) ) ,
TestAction ::assert_eq ( "(-0.001).toFixed(4)" , js_string ! ( "-0.0010" ) ) ,
TestAction ::assert_eq ( "(-1).toFixed(4)" , js_string ! ( "-1.0000" ) ) ,
TestAction ::assert_eq ( "(-1).toFixed(1)" , js_string ! ( "-1.0" ) ) ,
TestAction ::assert_eq ( "(-1).toFixed(0)" , js_string ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(-1.1).toFixed(0)" , js_string ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(-12.1).toFixed(0)" , js_string ! ( "-12" ) ) ,
TestAction ::assert_eq ( "(-1.12).toFixed(0)" , js_string ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(-12.12).toFixed(0)" , js_string ! ( "-12" ) ) ,
TestAction ::assert_eq ( "(-0.0000006).toFixed(7)" , js_string ! ( "-0.0000006" ) ) ,
TestAction ::assert_eq ( "(-0.00000006).toFixed(8)" , js_string ! ( "-0.00000006" ) ) ,
TestAction ::assert_eq ( "(-0.00000006).toFixed(9)" , js_string ! ( "-0.000000060" ) ) ,
TestAction ::assert_eq ( "(-0.00000006).toFixed(10)" , js_string ! ( "-0.0000000600" ) ) ,
TestAction ::assert_eq ( "(-0).toFixed(0)" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "(-0).toFixed(1)" , js_string ! ( "0.0" ) ) ,
TestAction ::assert_eq ( "(-0).toFixed(2)" , js_string ! ( "0.00" ) ) ,
TestAction ::assert_eq ( "(0.00001).toFixed(5)" , js_string ! ( "0.00001" ) ) ,
js_str ! ( "-1.1111111111111111e+21" ) ,
) ,
TestAction ::assert_eq ( "(-0.1).toFixed(1)" , js_str ! ( "-0.1" ) ) ,
TestAction ::assert_eq ( "(-0.1).toFixed(2)" , js_str ! ( "-0.10" ) ) ,
TestAction ::assert_eq ( "(-0.1).toFixed(3)" , js_str ! ( "-0.100" ) ) ,
TestAction ::assert_eq ( "(-0.01).toFixed(2)" , js_str ! ( "-0.01" ) ) ,
TestAction ::assert_eq ( "(-0.01).toFixed(3)" , js_str ! ( "-0.010" ) ) ,
TestAction ::assert_eq ( "(-0.01).toFixed(4)" , js_str ! ( "-0.0100" ) ) ,
TestAction ::assert_eq ( "(-0.001).toFixed(2)" , js_str ! ( "-0.00" ) ) ,
TestAction ::assert_eq ( "(-0.001).toFixed(3)" , js_str ! ( "-0.001" ) ) ,
TestAction ::assert_eq ( "(-0.001).toFixed(4)" , js_str ! ( "-0.0010" ) ) ,
TestAction ::assert_eq ( "(-1).toFixed(4)" , js_str ! ( "-1.0000" ) ) ,
TestAction ::assert_eq ( "(-1).toFixed(1)" , js_str ! ( "-1.0" ) ) ,
TestAction ::assert_eq ( "(-1).toFixed(0)" , js_str ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(-1.1).toFixed(0)" , js_str ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(-12.1).toFixed(0)" , js_str ! ( "-12" ) ) ,
TestAction ::assert_eq ( "(-1.12).toFixed(0)" , js_str ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(-12.12).toFixed(0)" , js_str ! ( "-12" ) ) ,
TestAction ::assert_eq ( "(-0.0000006).toFixed(7)" , js_str ! ( "-0.0000006" ) ) ,
TestAction ::assert_eq ( "(-0.00000006).toFixed(8)" , js_str ! ( "-0.00000006" ) ) ,
TestAction ::assert_eq ( "(-0.00000006).toFixed(9)" , js_str ! ( "-0.000000060" ) ) ,
TestAction ::assert_eq ( "(-0.00000006).toFixed(10)" , js_str ! ( "-0.0000000600" ) ) ,
TestAction ::assert_eq ( "(-0).toFixed(0)" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "(-0).toFixed(1)" , js_str ! ( "0.0" ) ) ,
TestAction ::assert_eq ( "(-0).toFixed(2)" , js_str ! ( "0.00" ) ) ,
TestAction ::assert_eq ( "(0.00001).toFixed(5)" , js_str ! ( "0.00001" ) ) ,
TestAction ::assert_eq (
"(0.0000000000000000001).toFixed(20)" ,
js_string ! ( "0.00000000000000000010" ) ,
js_str ! ( "0.00000000000000000010" ) ,
) ,
TestAction ::assert_eq ( "(0.00001).toFixed(17)" , js_string ! ( "0.00001000000000000" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(17)" , js_string ! ( "1.00000000000000000" ) ) ,
TestAction ::assert_eq ( "(0.00001).toFixed(17)" , js_str ! ( "0.00001000000000000" ) ) ,
TestAction ::assert_eq ( "(1).toFixed(17)" , js_str ! ( "1.00000000000000000" ) ) ,
TestAction ::assert_eq (
"(100000000000000128).toFixed(1)" ,
js_string ! ( "100000000000000128.0" ) ,
js_str ! ( "100000000000000128.0" ) ,
) ,
TestAction ::assert_eq (
"(10000000000000128).toFixed(2)" ,
js_string ! ( "10000000000000128.00" ) ,
js_str ! ( "10000000000000128.00" ) ,
) ,
TestAction ::assert_eq (
"(10000000000000128).toFixed(20)" ,
js_string ! ( "10000000000000128.00000000000000000000" ) ,
js_str ! ( "10000000000000128.00000000000000000000" ) ,
) ,
TestAction ::assert_eq ( "(-42).toFixed(3)" , js_string ! ( "-42.000" ) ) ,
TestAction ::assert_eq ( "(-42).toFixed(3)" , js_str ! ( "-42.000" ) ) ,
TestAction ::assert_eq (
"(-0.0000000000000000001).toFixed(20)" ,
js_string ! ( "-0.00000000000000000010" ) ,
js_str ! ( "-0.00000000000000000010" ) ,
) ,
TestAction ::assert_eq (
"(0.123123123123123).toFixed(20)" ,
js_string ! ( "0.12312312312312299889" ) ,
js_str ! ( "0.12312312312312299889" ) ,
) ,
TestAction ::assert_eq (
"(-1000000000000000128).toFixed()" ,
js_string ! ( "-1000000000000000128" ) ,
js_str ! ( "-1000000000000000128" ) ,
) ,
TestAction ::assert_eq ( "(0).toFixed()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "(0).toFixed()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq (
"(1000000000000000128).toFixed()" ,
js_string ! ( "1000000000000000128" ) ,
js_str ! ( "1000000000000000128" ) ,
) ,
TestAction ::assert_eq ( "(1000).toFixed()" , js_string ! ( "1000" ) ) ,
TestAction ::assert_eq ( "(0.00001).toFixed()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "(1000).toFixed()" , js_str ! ( "1000" ) ) ,
TestAction ::assert_eq ( "(0.00001).toFixed()" , js_str ! ( "0" ) ) ,
// Test that we round up even when the last digit generated is even.
// dtoa does not do this in its original form.
TestAction ::assert_eq ( "(0.5).toFixed(0)" , js_string ! ( "1" ) ) ,
TestAction ::assert_eq ( "(-0.5).toFixed(0)" , js_string ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(1.25).toFixed(1)" , js_string ! ( "1.3" ) ) ,
TestAction ::assert_eq ( "(0.5).toFixed(0)" , js_str ! ( "1" ) ) ,
TestAction ::assert_eq ( "(-0.5).toFixed(0)" , js_str ! ( "-1" ) ) ,
TestAction ::assert_eq ( "(1.25).toFixed(1)" , js_str ! ( "1.3" ) ) ,
// This is bizare, but Spidermonkey and KJS behave the same.
TestAction ::assert_eq ( "(234.2040).toFixed(4)" , js_string ! ( "234.2040" ) ) ,
TestAction ::assert_eq ( "(234.2040506).toFixed(4)" , js_string ! ( "234.2041" ) ) ,
TestAction ::assert_eq ( "(234.2040).toFixed(4)" , js_str ! ( "234.2040" ) ) ,
TestAction ::assert_eq ( "(234.2040506).toFixed(4)" , js_str ! ( "234.2041" ) ) ,
] ) ;
}
@ -162,8 +160,8 @@ fn to_fixed() {
#[ test ]
fn issue_2609 ( ) {
run_test_actions ( [
TestAction ::assert_eq ( "(1.25).toFixed(1)" , js_string ! ( "1.3" ) ) ,
TestAction ::assert_eq ( "(1.35).toFixed(1)" , js_string ! ( "1.4" ) ) ,
TestAction ::assert_eq ( "(1.25).toFixed(1)" , js_str ! ( "1.3" ) ) ,
TestAction ::assert_eq ( "(1.35).toFixed(1)" , js_str ! ( "1.4" ) ) ,
] ) ;
}
@ -172,10 +170,10 @@ fn to_locale_string() {
// TODO: We don't actually do any locale checking here
// To honor the spec we should print numbers according to user locale.
run_test_actions ( [
TestAction ::assert_eq ( "Number().toLocaleString()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(5).toLocaleString()" , js_string ! ( "5" ) ) ,
TestAction ::assert_eq ( "Number('345600').toLocaleString()" , js_string ! ( "345600" ) ) ,
TestAction ::assert_eq ( "Number(-25).toLocaleString()" , js_string ! ( "-25" ) ) ,
TestAction ::assert_eq ( "Number().toLocaleString()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(5).toLocaleString()" , js_str ! ( "5" ) ) ,
TestAction ::assert_eq ( "Number('345600').toLocaleString()" , js_str ! ( "345600" ) ) ,
TestAction ::assert_eq ( "Number(-25).toLocaleString()" , js_str ! ( "-25" ) ) ,
] ) ;
}
@ -183,21 +181,21 @@ fn to_locale_string() {
fn to_precision ( ) {
const ERROR : & str = "precision must be an integer at least 1 and no greater than 100" ;
run_test_actions ( [
TestAction ::assert_eq ( "(1/0).toPrecision(3)" , js_string ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "Number().toPrecision()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number().toPrecision(undefined)" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "(123456789).toPrecision(1)" , js_string ! ( "1e+8" ) ) ,
TestAction ::assert_eq ( "(123456789).toPrecision(4)" , js_string ! ( "1.235e+8" ) ) ,
TestAction ::assert_eq ( "(123456789).toPrecision(9)" , js_string ! ( "123456789" ) ) ,
TestAction ::assert_eq ( "(-123456789).toPrecision(4)" , js_string ! ( "-1.235e+8" ) ) ,
TestAction ::assert_eq ( "(1/0).toPrecision(3)" , js_str ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "Number().toPrecision()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number().toPrecision(undefined)" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "(123456789).toPrecision(1)" , js_str ! ( "1e+8" ) ) ,
TestAction ::assert_eq ( "(123456789).toPrecision(4)" , js_str ! ( "1.235e+8" ) ) ,
TestAction ::assert_eq ( "(123456789).toPrecision(9)" , js_str ! ( "123456789" ) ) ,
TestAction ::assert_eq ( "(-123456789).toPrecision(4)" , js_str ! ( "-1.235e+8" ) ) ,
TestAction ::assert_eq (
"(123456789).toPrecision(50)" ,
js_string ! ( "123456789.00000000000000000000000000000000000000000" ) ,
js_str ! ( "123456789.00000000000000000000000000000000000000000" ) ,
) ,
TestAction ::assert_eq ( "(0.1).toPrecision(4)" , js_string ! ( "0.1000" ) ) ,
TestAction ::assert_eq ( "(0.1).toPrecision(4)" , js_str ! ( "0.1000" ) ) ,
TestAction ::assert_eq (
"(1/3).toPrecision(60)" ,
js_string ! ( "0.333333333333333314829616256247390992939472198486328125000000" ) ,
js_str ! ( "0.333333333333333314829616256247390992939472198486328125000000" ) ,
) ,
TestAction ::assert_native_error ( "(1).toPrecision(101)" , JsNativeErrorKind ::Range , ERROR ) ,
TestAction ::assert_native_error ( "(1).toPrecision(0)" , JsNativeErrorKind ::Range , ERROR ) ,
@ -209,132 +207,126 @@ fn to_precision() {
#[ test ]
fn to_string ( ) {
run_test_actions ( [
TestAction ::assert_eq ( "Number(NaN).toString()" , js_string ! ( "NaN" ) ) ,
TestAction ::assert_eq ( "Number(1/0).toString()" , js_string ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "Number(-1/0).toString()" , js_string ! ( "-Infinity" ) ) ,
TestAction ::assert_eq ( "Number(0).toString()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(9).toString()" , js_string ! ( "9" ) ) ,
TestAction ::assert_eq ( "Number(90).toString()" , js_string ! ( "90" ) ) ,
TestAction ::assert_eq ( "Number(90.12).toString()" , js_string ! ( "90.12" ) ) ,
TestAction ::assert_eq ( "Number(0.1).toString()" , js_string ! ( "0.1" ) ) ,
TestAction ::assert_eq ( "Number(0.01).toString()" , js_string ! ( "0.01" ) ) ,
TestAction ::assert_eq ( "Number(0.0123).toString()" , js_string ! ( "0.0123" ) ) ,
TestAction ::assert_eq ( "Number(0.00001).toString()" , js_string ! ( "0.00001" ) ) ,
TestAction ::assert_eq ( "Number(0.000001).toString()" , js_string ! ( "0.000001" ) ) ,
TestAction ::assert_eq ( "Number(NaN).toString(16)" , js_string ! ( "NaN" ) ) ,
TestAction ::assert_eq ( "Number(1/0).toString(16)" , js_string ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "Number(-1/0).toString(16)" , js_string ! ( "-Infinity" ) ) ,
TestAction ::assert_eq ( "Number(0).toString(16)" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(9).toString(16)" , js_string ! ( "9" ) ) ,
TestAction ::assert_eq ( "Number(90).toString(16)" , js_string ! ( "5a" ) ) ,
TestAction ::assert_eq ( "Number(90.12).toString(16)" , js_string ! ( "5a.1eb851eb852" ) ) ,
TestAction ::assert_eq ( "Number(0.1).toString(16)" , js_string ! ( "0.1999999999999a" ) ) ,
TestAction ::assert_eq ( "Number(0.01).toString(16)" , js_string ! ( "0.028f5c28f5c28f6" ) ) ,
TestAction ::assert_eq (
"Number(0.0123).toString(16)" ,
js_string ! ( "0.032617c1bda511a" ) ,
) ,
TestAction ::assert_eq ( "Number(NaN).toString()" , js_str ! ( "NaN" ) ) ,
TestAction ::assert_eq ( "Number(1/0).toString()" , js_str ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "Number(-1/0).toString()" , js_str ! ( "-Infinity" ) ) ,
TestAction ::assert_eq ( "Number(0).toString()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(9).toString()" , js_str ! ( "9" ) ) ,
TestAction ::assert_eq ( "Number(90).toString()" , js_str ! ( "90" ) ) ,
TestAction ::assert_eq ( "Number(90.12).toString()" , js_str ! ( "90.12" ) ) ,
TestAction ::assert_eq ( "Number(0.1).toString()" , js_str ! ( "0.1" ) ) ,
TestAction ::assert_eq ( "Number(0.01).toString()" , js_str ! ( "0.01" ) ) ,
TestAction ::assert_eq ( "Number(0.0123).toString()" , js_str ! ( "0.0123" ) ) ,
TestAction ::assert_eq ( "Number(0.00001).toString()" , js_str ! ( "0.00001" ) ) ,
TestAction ::assert_eq ( "Number(0.000001).toString()" , js_str ! ( "0.000001" ) ) ,
TestAction ::assert_eq ( "Number(NaN).toString(16)" , js_str ! ( "NaN" ) ) ,
TestAction ::assert_eq ( "Number(1/0).toString(16)" , js_str ! ( "Infinity" ) ) ,
TestAction ::assert_eq ( "Number(-1/0).toString(16)" , js_str ! ( "-Infinity" ) ) ,
TestAction ::assert_eq ( "Number(0).toString(16)" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(9).toString(16)" , js_str ! ( "9" ) ) ,
TestAction ::assert_eq ( "Number(90).toString(16)" , js_str ! ( "5a" ) ) ,
TestAction ::assert_eq ( "Number(90.12).toString(16)" , js_str ! ( "5a.1eb851eb852" ) ) ,
TestAction ::assert_eq ( "Number(0.1).toString(16)" , js_str ! ( "0.1999999999999a" ) ) ,
TestAction ::assert_eq ( "Number(0.01).toString(16)" , js_str ! ( "0.028f5c28f5c28f6" ) ) ,
TestAction ::assert_eq ( "Number(0.0123).toString(16)" , js_str ! ( "0.032617c1bda511a" ) ) ,
TestAction ::assert_eq (
"Number(111111111111111111111).toString(16)" ,
js_string ! ( "605f9f6dd18bc8000" ) ,
js_str ! ( "605f9f6dd18bc8000" ) ,
) ,
TestAction ::assert_eq (
"Number(1111111111111111111111).toString(16)" ,
js_string ! ( "3c3bc3a4a2f75c0000" ) ,
js_str ! ( "3c3bc3a4a2f75c0000" ) ,
) ,
TestAction ::assert_eq (
"Number(11111111111111111111111).toString(16)" ,
js_string ! ( "25a55a46e5da9a00000" ) ,
js_str ! ( "25a55a46e5da9a00000" ) ,
) ,
TestAction ::assert_eq (
"Number(0.00001).toString(16)" ,
js_string ! ( "0.0000a7c5ac471b4788" ) ,
js_str ! ( "0.0000a7c5ac471b4788" ) ,
) ,
TestAction ::assert_eq (
"Number(0.000001).toString(16)" ,
js_string ! ( "0.000010c6f7a0b5ed8d" ) ,
js_str ! ( "0.000010c6f7a0b5ed8d" ) ,
) ,
TestAction ::assert_eq (
"Number(0.0000001).toString(16)" ,
js_string ! ( "0.000001ad7f29abcaf48" ) ,
js_str ! ( "0.000001ad7f29abcaf48" ) ,
) ,
TestAction ::assert_eq (
"Number(0.00000012).toString(16)" ,
js_string ! ( "0.000002036565348d256" ) ,
js_str ! ( "0.000002036565348d256" ) ,
) ,
TestAction ::assert_eq (
"Number(0.000000123).toString(16)" ,
js_string ! ( "0.0000021047ee22aa466" ) ,
js_str ! ( "0.0000021047ee22aa466" ) ,
) ,
TestAction ::assert_eq (
"Number(0.00000001).toString(16)" ,
js_string ! ( "0.0000002af31dc4611874" ) ,
js_str ! ( "0.0000002af31dc4611874" ) ,
) ,
TestAction ::assert_eq (
"Number(0.000000012).toString(16)" ,
js_string ! ( "0.000000338a23b87483be" ) ,
js_str ! ( "0.000000338a23b87483be" ) ,
) ,
TestAction ::assert_eq (
"Number(0.0000000123).toString(16)" ,
js_string ! ( "0.00000034d3fe36aaa0a2" ) ,
js_str ! ( "0.00000034d3fe36aaa0a2" ) ,
) ,
TestAction ::assert_eq ( "Number(-0).toString(16)" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(-9).toString(16)" , js_string ! ( "-9" ) ) ,
TestAction ::assert_eq ( "Number(-0).toString(16)" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "Number(-9).toString(16)" , js_str ! ( "-9" ) ) ,
//
TestAction ::assert_eq ( "Number(-90).toString(16)" , js_string ! ( "-5a" ) ) ,
TestAction ::assert_eq ( "Number(-90.12).toString(16)" , js_string ! ( "-5a.1eb851eb852" ) ) ,
TestAction ::assert_eq ( "Number(-0.1).toString(16)" , js_string ! ( "-0.1999999999999a" ) ) ,
TestAction ::assert_eq (
"Number(-0.01).toString(16)" ,
js_string ! ( "-0.028f5c28f5c28f6" ) ,
) ,
TestAction ::assert_eq ( "Number(-90).toString(16)" , js_str ! ( "-5a" ) ) ,
TestAction ::assert_eq ( "Number(-90.12).toString(16)" , js_str ! ( "-5a.1eb851eb852" ) ) ,
TestAction ::assert_eq ( "Number(-0.1).toString(16)" , js_str ! ( "-0.1999999999999a" ) ) ,
TestAction ::assert_eq ( "Number(-0.01).toString(16)" , js_str ! ( "-0.028f5c28f5c28f6" ) ) ,
TestAction ::assert_eq (
"Number(-0.0123).toString(16)" ,
js_string ! ( "-0.032617c1bda511a" ) ,
js_str ! ( "-0.032617c1bda511a" ) ,
) ,
TestAction ::assert_eq (
"Number(-111111111111111111111).toString(16)" ,
js_string ! ( "-605f9f6dd18bc8000" ) ,
js_str ! ( "-605f9f6dd18bc8000" ) ,
) ,
TestAction ::assert_eq (
"Number(-1111111111111111111111).toString(16)" ,
js_string ! ( "-3c3bc3a4a2f75c0000" ) ,
js_str ! ( "-3c3bc3a4a2f75c0000" ) ,
) ,
TestAction ::assert_eq (
"Number(-11111111111111111111111).toString(16)" ,
js_string ! ( "-25a55a46e5da9a00000" ) ,
js_str ! ( "-25a55a46e5da9a00000" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.00001).toString(16)" ,
js_string ! ( "-0.0000a7c5ac471b4788" ) ,
js_str ! ( "-0.0000a7c5ac471b4788" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.000001).toString(16)" ,
js_string ! ( "-0.000010c6f7a0b5ed8d" ) ,
js_str ! ( "-0.000010c6f7a0b5ed8d" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.0000001).toString(16)" ,
js_string ! ( "-0.000001ad7f29abcaf48" ) ,
js_str ! ( "-0.000001ad7f29abcaf48" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.00000012).toString(16)" ,
js_string ! ( "-0.000002036565348d256" ) ,
js_str ! ( "-0.000002036565348d256" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.000000123).toString(16)" ,
js_string ! ( "-0.0000021047ee22aa466" ) ,
js_str ! ( "-0.0000021047ee22aa466" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.00000001).toString(16)" ,
js_string ! ( "-0.0000002af31dc4611874" ) ,
js_str ! ( "-0.0000002af31dc4611874" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.000000012).toString(16)" ,
js_string ! ( "-0.000000338a23b87483be" ) ,
js_str ! ( "-0.000000338a23b87483be" ) ,
) ,
TestAction ::assert_eq (
"Number(-0.0000000123).toString(16)" ,
js_string ! ( "-0.00000034d3fe36aaa0a2" ) ,
js_str ! ( "-0.00000034d3fe36aaa0a2" ) ,
) ,
] ) ;
}
@ -342,26 +334,26 @@ fn to_string() {
#[ test ]
fn num_to_string_exponential ( ) {
run_test_actions ( [
TestAction ::assert_eq ( "(0).toString()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "(-0).toString()" , js_string ! ( "0" ) ) ,
TestAction ::assert_eq ( "(0).toString()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq ( "(-0).toString()" , js_str ! ( "0" ) ) ,
TestAction ::assert_eq (
"(111111111111111111111).toString()" ,
js_string ! ( "111111111111111110000" ) ,
js_str ! ( "111111111111111110000" ) ,
) ,
TestAction ::assert_eq (
"(1111111111111111111111).toString()" ,
js_string ! ( "1.1111111111111111e+21" ) ,
js_str ! ( "1.1111111111111111e+21" ) ,
) ,
TestAction ::assert_eq (
"(11111111111111111111111).toString()" ,
js_string ! ( "1.1111111111111111e+22" ) ,
) ,
TestAction ::assert_eq ( "(0.0000001).toString()" , js_string ! ( "1e-7" ) ) ,
TestAction ::assert_eq ( "(0.00000012).toString()" , js_string ! ( "1.2e-7" ) ) ,
TestAction ::assert_eq ( "(0.000000123).toString()" , js_string ! ( "1.23e-7" ) ) ,
TestAction ::assert_eq ( "(0.00000001).toString()" , js_string ! ( "1e-8" ) ) ,
TestAction ::assert_eq ( "(0.000000012).toString()" , js_string ! ( "1.2e-8" ) ) ,
TestAction ::assert_eq ( "(0.0000000123).toString()" , js_string ! ( "1.23e-8" ) ) ,
js_str ! ( "1.1111111111111111e+22" ) ,
) ,
TestAction ::assert_eq ( "(0.0000001).toString()" , js_str ! ( "1e-7" ) ) ,
TestAction ::assert_eq ( "(0.00000012).toString()" , js_str ! ( "1.2e-7" ) ) ,
TestAction ::assert_eq ( "(0.000000123).toString()" , js_str ! ( "1.23e-7" ) ) ,
TestAction ::assert_eq ( "(0.00000001).toString()" , js_str ! ( "1e-8" ) ) ,
TestAction ::assert_eq ( "(0.000000012).toString()" , js_str ! ( "1.2e-8" ) ) ,
TestAction ::assert_eq ( "(0.0000000123).toString()" , js_str ! ( "1.23e-8" ) ) ,
] ) ;
}
@ -642,11 +634,11 @@ fn issue_2717() {
run_test_actions ( [
TestAction ::assert_eq (
"(0.1600057092765239).toString(36)" ,
js_string ! ( "0.5rd85dm1ixq" ) ,
js_str ! ( "0.5rd85dm1ixq" ) ,
) ,
TestAction ::assert_eq (
"(0.23046743672210102).toString(36)" ,
js_string ! ( "0.8aoosla2phj" ) ,
js_str ! ( "0.8aoosla2phj" ) ,
) ,
] ) ;
}