mirror of https://github.com/tc39/test262.git
Add tests for Number.isSafeInteger
This commit is contained in:
parent
3685e6b7b3
commit
4492b8032b
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 20.1.2.5
|
||||
esid: sec-number.issafeinteger
|
||||
description: >
|
||||
Return false if argument is not Number
|
||||
info: |
|
||||
Number.isSafeInteger ( number )
|
||||
|
||||
1. If Type(number) is not Number, return false.
|
||||
[...]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Number.isSafeInteger("1"), false, "string");
|
||||
assert.sameValue(Number.isSafeInteger([1]), false, "[1]");
|
||||
assert.sameValue(Number.isSafeInteger(new Number(42)), false, "Number object");
|
||||
assert.sameValue(Number.isSafeInteger(false), false, "false");
|
||||
assert.sameValue(Number.isSafeInteger(true), false, "true");
|
||||
assert.sameValue(Number.isSafeInteger(undefined), false, "undefined");
|
||||
assert.sameValue(Number.isSafeInteger(null), false, "null");
|
||||
assert.sameValue(Number.isSafeInteger(Symbol("1")), false, "symbol");
|
||||
assert.sameValue(Number.isSafeInteger(), false, "no arg");
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (c) 2016 The V8 Project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 20.1.2.5
|
||||
esid: sec-number.issafeinteger
|
||||
description: >
|
||||
Return false if argument is an Infinity value
|
||||
info: |
|
||||
Number.isSafeInteger ( number )
|
||||
|
||||
[...]
|
||||
2. If number is NaN, +∞, or -∞, return false.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Number.isSafeInteger(Infinity), false, "Infinity");
|
||||
assert.sameValue(Number.isSafeInteger(-Infinity), false, "-Infinity");
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2016 The V8 Project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 20.1.2.5
|
||||
esid: sec-number.issafeinteger
|
||||
description: >
|
||||
Return false if argument is NaN
|
||||
info: |
|
||||
Number.isSafeInteger ( number )
|
||||
|
||||
[...]
|
||||
2. If number is NaN, +∞, or -∞, return false.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Number.isSafeInteger(NaN), false);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) 2016 The V8 Project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 20.1.2.5
|
||||
esid: sec-number.issafeinteger
|
||||
description: >
|
||||
Return false if argument is not an integer
|
||||
info: |
|
||||
Number.isSafeInteger ( number )
|
||||
|
||||
[...]
|
||||
3. Let integer be ToInteger(number).
|
||||
4. If integer is not equal to number, return false.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Number.isSafeInteger(1.1), false, "1.1");
|
||||
assert.sameValue(Number.isSafeInteger(0.000001), false, "0.000001");
|
||||
assert.sameValue(Number.isSafeInteger(-0.000001), false, "-0.000001");
|
||||
assert.sameValue(Number.isSafeInteger(11e-1), false, "11e-1");
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) 2016 The V8 Project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 20.1.2.5
|
||||
esid: sec-number.issafeinteger
|
||||
description: >
|
||||
Return false if argument is not a safe integer
|
||||
info: |
|
||||
Number.isSafeInteger ( number )
|
||||
|
||||
[...]
|
||||
3. Let integer be ToInteger(number).
|
||||
4. If integer is not equal to number, return false.
|
||||
5. If abs(integer) ≤ 2**53-1, return true.
|
||||
6. Otherwise, return false.
|
||||
---*/
|
||||
|
||||
assert.sameValue(Number.isSafeInteger(9007199254740992), false, "2**53");
|
||||
assert.sameValue(Number.isSafeInteger(-9007199254740992), false, "-(2**53)");
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 20.1.2.5
|
||||
esid: sec-number.issafeinteger
|
||||
description: >
|
||||
"isSafeInteger" property of Number
|
||||
info: >
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
Every other data property described in clauses 18 through 26 and in Annex B.2
|
||||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(Number, "isSafeInteger");
|
||||
verifyWritable(Number, "isSafeInteger");
|
||||
verifyConfigurable(Number, "isSafeInteger");
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2016 The V8 Project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 20.1.2.5
|
||||
esid: sec-number.issafeinteger
|
||||
description: >
|
||||
Return true if argument is a safe integer
|
||||
info: |
|
||||
Number.isSafeInteger ( number )
|
||||
|
||||
[...]
|
||||
3. Let integer be ToInteger(number).
|
||||
4. If integer is not equal to number, return false.
|
||||
5. If abs(integer) ≤ 2**53-1, return true.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Number.isInteger(1), true, "1");
|
||||
assert.sameValue(Number.isInteger(-0), true, "-0");
|
||||
assert.sameValue(Number.isInteger(0), true, "0");
|
||||
assert.sameValue(Number.isInteger(-1), true, "-1");
|
||||
assert.sameValue(Number.isInteger(9007199254740991), true, "9007199254740991");
|
||||
assert.sameValue(Number.isInteger(-9007199254740991), true, "-9007199254740991");
|
Loading…
Reference in New Issue