Skip to content

Commit

Permalink
Issue #102 Fixed Number.toString method
Browse files Browse the repository at this point in the history
  • Loading branch information
ilich committed Dec 31, 2013
1 parent a64dabd commit c12c924
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Src/IronJS/Native.Number.fs
Expand Up @@ -62,18 +62,22 @@ module internal Number =
| _ ->
let digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let mutable result = ""
let mutable isNegative = false
let mutable number = bigint (int64 number)
if number < bigint.Zero then
result <- "-"
isNegative <- true
number <- -number
if number = bigint.Zero then "0"
else
let radix = bigint radix
while number > bigint.Zero do
let digit = int (number % radix)
number <- number / radix
result <- result + digits.[digit].ToString()
result
result <- digits.[digit].ToString() + result
if isNegative then
"-" + result
else
result

///
let private toLocaleString (f:FO) (this:CO) =
Expand Down
@@ -0,0 +1,20 @@
/**
* @name: S8.5_A8;
* @section: 8.5, 7.8.3;
* @assertion: Number.toString(16) should return valid number
* @description: https://github.com/fholm/IronJS/issues/102
*/

var n = 9999;
var n16 = n.toString(16)

if (n16 !== "270F") {
$ERROR("#1: Number.toString(16) should return valid number. Expected 270F, but have " + n16);
}

n = -9999;
n16 = n.toString(16)

if (n16 !== "-270F") {
$ERROR("#2: Number.toString(16) should return valid number. Expected -270F, but have " + n16);
}
Expand Up @@ -165,5 +165,15 @@ public void GloballyDefinedVariableNaNHasNotBeenAlteredByProgramExecution(string
{
RunFile(file);
}

[Test]
[Category("Sputnik Conformance")]
[Category("ECMA 7.8.3")]
[Category("ECMA 8.5")]
[TestCase("S8.5_A15.js", Description = "Number.toString(16) should return valid number")]
public void ToStringBase16IsCorrect(string file)
{
RunFile(file);
}
}
}

0 comments on commit c12c924

Please sign in to comment.