Add tests for Number printing precision ranges (#932)

These tests are against the needs-consensus pull request at
https://github.com/tc39/ecma262/pull/857
This commit is contained in:
Daniel Ehrenberg 2017-06-12 19:10:15 -04:00 committed by Leo Balter
parent c59afa3bd7
commit 0314c87b08
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,21 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-number.prototype.toexponential
description: Number.prototype.toExponential permits fractionDigits from 0 to 100
info: >
Number.prototype.toExponential ( fractionDigits )
...
8. If _p_ < 0 or _p_ > 100, throw a *RangeError* exception.
...
---*/
assert.sameValue((3).toExponential(0), "3e+0");
assert.throws(RangeError, () => (3).toExponential(0));
assert.sameValue((3).toExponential(100), "3.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+0");
assert.throws(RangeError, () => (3).toExponential(101));

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-number.prototype.tofixed
description: Number.prototype.toFixed permits fractionDigits from -20 to 100
info: >
Number.prototype.toFixed ( fractionDigits )
...
3. If _f_ < -20 or _f_ > 100, throw a *RangeError* exception.
...
---*/
assert.sameValue((3).toFixed(-20), "0");
assert.throws(RangeError, () => (3).toFixed(-21));
assert.sameValue((3).toFixed(100), "3.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
assert.throws(RangeError, () => (3).toFixed(101));

View File

@ -0,0 +1,21 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-number.prototype.toprecision
description: Number.prototype.toPrecision permits fractionDigits from 1 to 100
info: >
Number.prototype.toPrecision ( fractionDigits )
...
8. If _p_ < 1 or _p_ > 100, throw a *RangeError* exception.
...
---*/
assert.sameValue((3).toPrecision(1), "3");
assert.throws(RangeError, () => (3).toPrecision(0));
assert.throws(RangeError, () => (3).toPrecision(-10));
assert.sameValue((3).toPrecision(100), "3.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
assert.throws(RangeError, () => (3).toPrecision(101));