Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tointlmathematicalvalue tests #3772

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-tointlmathematicalvalue
description: Tests exponent limits
features: [Intl.NumberFormat-v3]
---*/

const nf = Intl.NumberFormat();

Copy link
Contributor

@sffc sffc Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR currently tests only the Number path. Please also test the String path.

Please test the following inputs (and, for additional coverage, the negative versions of each):

// Values that should *not* overflow to ∞:
Number.MAX_VALUE
String(Number.MAX_VALUE)
Number.MAX_VALUE / 2
String(Number.MAX_VALUE / 2)
1e308
"1e308"
"1" + Array(308).fill("0").join("")
Array(309).fill("1").join("")

// Values that should overflow to ∞:
Number.MAX_VALUE * 2
1e309
"1e309"
"1" + Array(309).fill("0").join("")
Array(310).fill("1").join("")

// Values that should *not* underflow to 0:
// Note: Please set the rounding strategy to maximumSignificantDigits: 10
Number.MIN_VALUE
String(Number.MIN_VALUE)
Number.MIN_VALUE * 2
String(Number.MIN_VALUE * 2)
1e-324
"1e-324"
"1.1111111111111111111e-324" // should round to 10 significant digits
"0." + Array(323).fill("0").join("") + "1"
"0." + Array(323).fill("0").join("") + Array(30).fill("1").join("") // should round to 10 significant digits

// Values that should underflow to zero:
Number.MIN_VALUE / 2
1e-325
"1e-325"
"1.1111111111111111111e-325"
"0." + Array(324).fill("0").join("") + "1"
"0." + Array(324).fill("0").join("") + Array(30).fill("1").join("")

assert(nf.format(-100e306).length > 411 ,"Should output -100,000,000...");
assert.sameValue(nf.format(-100e307), "-∞", "Should output -∞");
assert.sameValue(nf.format(-100e309), "-∞", "Should output -∞");
assert.sameValue(nf.format(-100e310), "-∞", "Should output -∞");

assert.sameValue(nf.format(-100e-306), "-0", "Should output -0");
assert.sameValue(nf.format(-100e-309), "-0", "Should output -0");
assert.sameValue(nf.format(-100e-310), "-0", "Should output -0");

assert(nf.format(100e306).length > 411 ,"Should output 100,000,000...");
assert.sameValue(nf.format(100e307), "∞", "Should output ∞");
assert.sameValue(nf.format(100e309), "∞", "Should output ∞");
assert.sameValue(nf.format(100e310), "∞", "Should output ∞");

assert.sameValue(nf.format(100e-308), "0", "Should output 0");
assert.sameValue(nf.format(100e-309), "0", "Should output 0");
assert.sameValue(nf.format(100e-310), "0", "Should output 0");

assert.sameValue(nf.format(Number.MAX_VALUE * -2), "-∞", "Should output -∞");
assert.sameValue(nf.format(Number.MAX_VALUE * 2), "∞", "Should output ∞");
assert.sameValue(nf.format(Number.MIN_VALUE * -2), "-0", "Should output -0");
assert.sameValue(nf.format(Number.MIN_VALUE * 2), "0", "Should output 0");