Update and expand tests for isFinite

This commit is contained in:
Leonardo Balter 2016-06-30 12:57:00 -03:00 committed by Mike Pennisi
parent 96c4e7730b
commit 81f22800fa
21 changed files with 417 additions and 215 deletions

View File

@ -1,70 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: >
isFinite applies ToNumber to its argument, then return false if the
result is NaN, +Infinity, -Infinity, and otherwise return true
es5id: 15.1.2.5_A1_T1
description: Checking all primitive
---*/
// CHECK#1
if (!(isFinite(NaN) === false)) {
$ERROR('#1: NaN === Not-a-Finite. Actual: ' + (NaN));
}
// CHECK#2
if (!(isFinite(Number.NaN) === false)) {
$ERROR('#2: Number.NaN === Not-a-Finite. Actual: ' + (Number.NaN));
}
// CHECK#3
if (!(isFinite(Number(void 0)) === false)) {
$ERROR('#3: Number(void 0) === Not-a-Finite. Actual: ' + (Number(void 0)));
}
// CHECK#4
if (!(isFinite(void 0) === false)) {
$ERROR('#4: void 0 === Not-a-Finite. Actual: ' + (void 0));
}
// CHECK#5
if (!(isFinite("string") === false)) {
$ERROR('#5: "string" === Not-a-Finite. Actual: ' + ("string"));
}
// CHECK#6
if (isFinite(Number.POSITIVE_INFINITY) !== false) {
$ERROR('#6: Number.POSITIVE_INFINITY === Not-a-Finite. Actual: ' + (Number.POSITIVE_INFINITY));
}
// CHECK#7
if (isFinite(Number.NEGATIVE_INFINITY) !== false) {
$ERROR('#7: Number.NEGATIVE_INFINITY === Not-a-Finite. Actual: ' + (Number.NEGATIVE_INFINITY));
}
// CHECK#8
if (isFinite(Number.MAX_VALUE) === false) {
$ERROR('#8: Number.MAX_VALUE !== Not-a-Finite');
}
// CHECK#9
if (isFinite(Number.MIN_VALUE) === false) {
$ERROR('#9: Number.MIN_VALUE !== Not-a-Finite');
}
// CHECK#10
if (isFinite(-0) === false) {
$ERROR('#10: -0 !== Not-a-Finite');
}
// CHECK#11
if (isFinite(false) === false) {
$ERROR('#11: false !== Not-a-Finite');
}
// CHECK#12
if (isFinite("1") === false) {
$ERROR('#12: "1" !== Not-a-Finite');
}

View File

@ -1,40 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: >
isFinite applies ToNumber to its argument, then return false if the
result is NaN, +Infinity, -Infinity, and otherwise return true
es5id: 15.1.2.5_A1_T2
description: Checking all object
---*/
// CHECK#1
if (!(isFinite({}) === false)) {
$ERROR('#1: {} === Not-a-Finite. Actual: ' + ({}));
}
// CHECK#2
if (!(isFinite(new String("string")) === false)) {
$ERROR('#2: new String("string") === Not-a-Finite. Actual: ' + (new String("string")));
}
// CHECK#3
if (isFinite(new String("1")) === false) {
$ERROR('#3: new String("1") === Not-a-Finite. Actual: ' + (new String("1")));
}
// CHECK#4
if (isFinite(new Number(1)) === false) {
$ERROR('#4: new Number(1) !== Not-a-Finite');
}
// CHECK#5
if (!(isFinite(new Number(NaN)) === false)) {
$ERROR('#5: new Number(NaN) === Not-a-Finite. Actual: ' + (new Number(NaN)));
}
// CHECK#6
if (isFinite(new Boolean(true)) === false) {
$ERROR('#6: new Boolean(true) !== Not-a-Finite');
}

View File

@ -1,25 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of isFinite has the attribute DontEnum
es5id: 15.1.2.5_A2.1
description: Checking use propertyIsEnumerable, for-in
---*/
//CHECK#1
if (isFinite.propertyIsEnumerable('length') !== false) {
$ERROR('#1: isFinite.propertyIsEnumerable(\'length\') === false. Actual: ' + (isFinite.propertyIsEnumerable('length')));
}
//CHECK#2
var result = true;
for (var p in isFinite){
if (p === "length") {
result = false;
}
}
if (result !== true) {
$ERROR('#2: result = true; for (p in isFinite) { if (p === "length") result = false; } result === true;');
}

View File

@ -1,25 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of isFinite does not have the attribute DontDelete
es5id: 15.1.2.5_A2.2
description: Checking use hasOwnProperty, delete
---*/
//CHECK#1
if (isFinite.hasOwnProperty('length') !== true) {
$ERROR('#1: isFinite.hasOwnProperty(\'length\') === true. Actual: ' + (isFinite.hasOwnProperty('length')));
}
delete isFinite.length;
//CHECK#2
if (isFinite.hasOwnProperty('length') !== false) {
$ERROR('#2: delete isFinite.length; isFinite.hasOwnProperty(\'length\') === false. Actual: ' + (isFinite.hasOwnProperty('length')));
}
//CHECK#3
if (isFinite.length === undefined) {
$ERROR('#3: delete isFinite.length; isFinite.length !== undefined');
}

View File

@ -1,16 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of isFinite has the attribute ReadOnly
es5id: 15.1.2.5_A2.3
description: Checking if varying the length property fails
includes: [propertyHelper.js]
---*/
//CHECK#1
var x = isFinite.length;
verifyNotWritable(isFinite, "length", null, Infinity);
if (isFinite.length !== x) {
$ERROR('#1: x = isFinite.length; isFinite.length = Infinity; isFinite.length === x. Actual: ' + (isFinite.length));
}

View File

@ -1,13 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of isFinite is 1
es5id: 15.1.2.5_A2.4
description: isFinite.length === 1
---*/
//CHECK#1
if (isFinite.length !== 1) {
$ERROR('#1: isFinite.length === 1. Actual: ' + (isFinite.length));
}

View File

@ -1,25 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The isFinite property has the attribute DontEnum
es5id: 15.1.2.5_A2.5
description: Checking use propertyIsEnumerable, for-in
---*/
//CHECK#1
if (this.propertyIsEnumerable('isFinite') !== false) {
$ERROR('#1: this.propertyIsEnumerable(\'isFinite\') === false. Actual: ' + (this.propertyIsEnumerable('isFinite')));
}
//CHECK#2
var result = true;
for (var p in this){
if (p === "isFinite") {
result = false;
}
}
if (result !== true) {
$ERROR('#2: result = true; for (p in this) { if (p === "isFinite") result = false; } result === true;');
}

View File

@ -4,7 +4,7 @@
/*---
info: The isFinite property has not prototype property
es5id: 15.1.2.5_A2.6
description: Checking isFinit.prototype
description: Checking isFinite.prototype
---*/
//CHECK#1

View File

@ -0,0 +1,16 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
The length property of isFinite is 1
includes: [propertyHelper.js]
---*/
assert.sameValue(isFinite.length, 1, "The value of `isFinite.length` is `1`");
verifyNotEnumerable(isFinite, "length");
verifyNotWritable(isFinite, "length");
verifyConfigurable(isFinite, "length");

View File

@ -0,0 +1,14 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Property descriptor for isFinite
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(this, "isFinite");
verifyWritable(this, "isFinite");
verifyConfigurable(this, "isFinite");

View File

@ -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.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Throws a TypeError if number is a Symbol
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
features: [Symbol]
---*/
var s = Symbol(1);
assert.throws(TypeError, function() {
isFinite(s);
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Return abrupt completion from ToNumber(number)
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
---*/
var obj1 = {
valueOf: function() {
throw new Test262Error();
}
};
var obj2 = {
toString: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
isFinite(obj1);
}, "valueOf");
assert.throws(Test262Error, function() {
isFinite(obj2);
}, "toString");

View File

@ -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.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Return false if number is NaN, Infinity or -Infinity
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
2. If num is NaN, +, or -, return false.
---*/
assert.sameValue(isFinite(NaN), false, "NaN");
assert.sameValue(isFinite(Infinity), false, "Infinity");
assert.sameValue(isFinite(-Infinity), false, "-Infinity");

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Return true if number is not NaN, Infinity or -Infinity
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
2. If num is NaN, +, or -, return false.
3. Otherwise, return true.
---*/
assert.sameValue(isFinite(0), true, "0");
assert.sameValue(isFinite(-0), true, "-0");
assert.sameValue(isFinite(Math.pow(2, 53)), true, "Math.pow(2, 53)");
assert.sameValue(isFinite(-Math.pow(2, 53)), true, "-Math.pow(2, 53)");
assert.sameValue(isFinite(1), true, "1");
assert.sameValue(isFinite(-1), true, "-1");
assert.sameValue(isFinite(0.000001), true, "0.000001");
assert.sameValue(isFinite(-0.000001), true, "-0.000001");
assert.sameValue(isFinite(1e42), true, "1e42");
assert.sameValue(isFinite(-1e42), true, "-1e42");

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
number argument is converted by ToNumber
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
2. If num is NaN, +, or -, return false.
3. Otherwise, return true.
---*/
assert.sameValue(isFinite("0"), true, "'0'");
assert.sameValue(isFinite(""), true, "the empty string");
assert.sameValue(isFinite("Infinity"), false, "'Infinity'");
assert.sameValue(isFinite("this is not a number"), false, "string");
assert.sameValue(isFinite(true), true, "true");
assert.sameValue(isFinite(false), true, "false");
assert.sameValue(isFinite([1]), true, "Object [1]");
assert.sameValue(isFinite([Infinity]), false, "Object [Infinity]");
assert.sameValue(isFinite([NaN]), false, "Object [NaN]");
assert.sameValue(isFinite(null), true, "null");
assert.sameValue(isFinite(undefined), false, "undefined");
assert.sameValue(isFinite(), false, "no arg");

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Return abrupt completion calling number.@@toPrimitive
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
ToPrimitive ( input [ , PreferredType ] )
[...]
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
5. If exoticToPrim is not undefined, then
a. Let result be ? Call(exoticToPrim, input, « hint »).
features: [Symbol.toPrimitive]
---*/
var obj = {};
obj[Symbol.toPrimitive] = function() {
throw new Test262Error();
};
assert.throws(Test262Error, function() {
isFinite(obj);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Return abrupt completion getting number.@@toPrimitive
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
ToPrimitive ( input [ , PreferredType ] )
[...]
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
features: [Symbol.toPrimitive]
---*/
var obj = Object.defineProperty({}, Symbol.toPrimitive, {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
isFinite(obj);
});

View File

@ -0,0 +1,53 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Throws a TypeError if number.@@toPrimitive is not null, undefined, or callable
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
ToPrimitive ( input [ , PreferredType ] )
[...]
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
GetMethod (V, P)
[...]
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
features: [Symbol.toPrimitive]
---*/
var obj = {};
obj[Symbol.toPrimitive] = 42;
assert.throws(TypeError, function() {
isFinite(obj);
}, "number");
obj[Symbol.toPrimitive] = "";
assert.throws(TypeError, function() {
isFinite(obj);
}, "string");
obj[Symbol.toPrimitive] = true;
assert.throws(TypeError, function() {
isFinite(obj);
}, "boolean");
obj[Symbol.toPrimitive] = Symbol.toPrimitive;
assert.throws(TypeError, function() {
isFinite(obj);
}, "symbol");
obj[Symbol.toPrimitive] = {};
assert.throws(TypeError, function() {
isFinite(obj);
}, "object");

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Throws a TypeError if the result of calling number.@@toPrimitive is an Object
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
ToPrimitive ( input [ , PreferredType ] )
[...]
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
5. If exoticToPrim is not undefined, then
a. Let result be ? Call(exoticToPrim, input, « hint »).
b. If Type(result) is not Object, return result.
c. Throw a TypeError exception.
features: [Symbol.toPrimitive]
---*/
var obj = {};
obj[Symbol.toPrimitive] = function() {
return [42];
};
assert.throws(TypeError, function() {
isFinite(obj);
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Throws a TypeError if the result of calling number.@@toPrimitive is a symbol
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
ToNumber ( argument )
1. Let primValue be ? ToPrimitive(argument, hint Number).
2. Return ? ToNumber(primValue).
ToPrimitive ( input [ , PreferredType ] )
[...]
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
5. If exoticToPrim is not undefined, then
a. Let result be ? Call(exoticToPrim, input, « hint »).
b. If Type(result) is not Object, return result.
features: [Symbol.toPrimitive]
---*/
var obj = {};
obj[Symbol.toPrimitive] = function() {
return Symbol.toPrimitive;
};
assert.throws(TypeError, function() {
isFinite(obj);
});

View File

@ -0,0 +1,81 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-isfinite-number
es6id: 18.2.2
description: >
Use non-object value returned from @@toPrimitive method
info: |
isFinite (number)
1. Let num be ? ToNumber(number).
ToPrimitive ( input [ , PreferredType ] )
[...]
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
5. If exoticToPrim is not undefined, then
a. Let result be ? Call(exoticToPrim, input, « hint »).
b. If Type(result) is not Object, return result.
features: [Symbol.toPrimitive]
---*/
var called = 0;
var obj = {
valueOf: function() {
called = NaN;
return Infinity;
},
toString: function() {
called = NaN;
return Infinity;
}
};
obj[Symbol.toPrimitive] = function() {
called += 1;
return 42;
};
assert.sameValue(isFinite(obj), true, "use returned value - number");
assert.sameValue(called, 1, "toPrimitive is called - number");
called = 0;
obj[Symbol.toPrimitive] = function() {
called += 1;
return "42";
};
assert.sameValue(isFinite(obj), true, "use returned value - string");
assert.sameValue(called, 1, "toPrimitive is called - string");
called = 0;
obj[Symbol.toPrimitive] = function() {
called += 1;
return true;
};
assert.sameValue(isFinite(obj), true, "use returned value - boolean true");
assert.sameValue(called, 1, "toPrimitive is called - boolean true");
called = 0;
obj[Symbol.toPrimitive] = function() {
called += 1;
return false;
};
assert.sameValue(isFinite(obj), true, "use returned value - boolean false");
assert.sameValue(called, 1, "toPrimitive is called - boolean false");
called = 0;
obj[Symbol.toPrimitive] = function() {
called += 1;
return Infinity;
};
assert.sameValue(isFinite(obj), false, "use returned value - Infinity");
assert.sameValue(called, 1, "toPrimitive is called - Infinity");
called = 0;
obj[Symbol.toPrimitive] = function() {
called += 1;
return -Infinity;
};
assert.sameValue(isFinite(obj), false, "use returned value - -Infinity");
assert.sameValue(called, 1, "toPrimitive is called - -Infinity");