null_embedded_string_toDouble.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // Number tests for issue https://github.com/Microsoft/ChakraCore/issues/5038
  6. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  7. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  8. }
  9. let tests =
  10. [
  11. {
  12. name: 'Converting "\\x00" to Number should return NaN',
  13. body: function () {
  14. let arr_tests = [Number("\x00"), Number(" \x00"), -" \x00", +"\x00", +" \n\x00"];
  15. arr_tests.forEach(function (num, index) {
  16. assert.areEqual("number", typeof (num), "Element at index " + index + " has wrong type.");
  17. assert.isTrue(Number.isNaN(num), "Element at index " + index + " is " + num + ". It should be NaN.");
  18. });
  19. }
  20. },
  21. {
  22. name: "Converting empty strings or whitespace-only strings to Number should return 0",
  23. body: function () {
  24. let arr_tests = [Number(""), Number(" "), +"", -"", +" ",
  25. +"\t\n\r\v\f\xa0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff"];
  26. arr_tests.forEach(function (num, index) {
  27. assert.areEqual("number", typeof (num), "Element at index " + index + " has wrong type.");
  28. assert.areEqual(0, num, "Element at index " + index + " is " + num + ". It should be 0.");
  29. });
  30. }
  31. }
  32. ];
  33. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });