Skip to content
Snippets Groups Projects
Commit e2e4fa4c authored by André Bargull's avatar André Bargull
Browse files

Replace runTestCase with assert helpers [test/built-ins/Array/prototype/filter]

parent 354b7cc1
Branches
No related tags found
No related merge requests found
Showing
with 43 additions and 139 deletions
......@@ -4,13 +4,8 @@
/*---
es5id: 15.4.4.20-0-1
description: Array.prototype.filter must exist as a function
includes: [runTestCase.js]
---*/
function testcase() {
var f = Array.prototype.filter;
if (typeof(f) === "function") {
return true;
}
}
runTestCase(testcase);
assert.sameValue(typeof(f), "function", 'typeof(f)');
......@@ -4,12 +4,6 @@
/*---
es5id: 15.4.4.20-0-2
description: Array.prototype.filter.length must be 1
includes: [runTestCase.js]
---*/
function testcase() {
if (Array.prototype.filter.length === 1) {
return true;
}
}
runTestCase(testcase);
assert.sameValue(Array.prototype.filter.length, 1, 'Array.prototype.filter.length');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-1-11
description: Array.prototype.filter applied to Date object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof Date;
}
......@@ -19,6 +16,4 @@ function testcase() {
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === 1;
}
runTestCase(testcase);
assert.sameValue(newArr[0], 1, 'newArr[0]');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-1-12
description: Array.prototype.filter applied to RegExp object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof RegExp;
}
......@@ -18,6 +15,5 @@ function testcase() {
obj[1] = true;
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === true;
}
runTestCase(testcase);
assert.sameValue(newArr[0], true, 'newArr[0]');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-1-14
description: Array.prototype.filter applied to Error object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof Error;
}
......@@ -19,6 +16,4 @@ function testcase() {
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === 1;
}
runTestCase(testcase);
assert.sameValue(newArr[0], 1, 'newArr[0]');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-1-15
description: Array.prototype.filter applied to the Arguments object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return '[object Arguments]' === Object.prototype.toString.call(obj);
}
......@@ -19,6 +16,5 @@ function testcase() {
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === "a" && newArr[1] === "b";
}
runTestCase(testcase);
assert.sameValue(newArr[0], "a", 'newArr[0]');
assert.sameValue(newArr[1], "b", 'newArr[1]');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-1-4
description: Array.prototype.filter applied to Boolean Object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof Boolean;
}
......@@ -20,6 +17,5 @@ function testcase() {
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === 11 && newArr[1] === 12;
}
runTestCase(testcase);
assert.sameValue(newArr[0], 11, 'newArr[0]');
assert.sameValue(newArr[1], 12, 'newArr[1]');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-1-6
description: Array.prototype.filter applied to Number object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof Number;
}
......@@ -19,6 +16,6 @@ function testcase() {
obj[1] = 12;
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === 11 && newArr[1] === 12;
}
runTestCase(testcase);
assert.sameValue(newArr[0], 11, 'newArr[0]');
assert.sameValue(newArr[1], 12, 'newArr[1]');
......@@ -4,17 +4,12 @@
/*---
es5id: 15.4.4.20-1-7
description: Array.prototype.filter applied to string primitive
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof String;
}
var newArr = Array.prototype.filter.call("abc", callbackfn);
return newArr[0] === "a";
}
runTestCase(testcase);
assert.sameValue(newArr[0], "a", 'newArr[0]');
......@@ -4,10 +4,8 @@
/*---
es5id: 15.4.4.20-1-8
description: Array.prototype.filter applied to String object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof String;
}
......@@ -15,6 +13,4 @@ function testcase() {
var obj = new String("abc");
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === "a";
}
runTestCase(testcase);
assert.sameValue(newArr[0], "a", 'newArr[0]');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-1-9
description: Array.prototype.filter applied to Function object
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj instanceof Function;
}
......@@ -21,6 +18,5 @@ function testcase() {
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr[0] === 11 && newArr[1] === 9;
}
runTestCase(testcase);
assert.sameValue(newArr[0], 11, 'newArr[0]');
assert.sameValue(newArr[1], 9, 'newArr[1]');
......@@ -6,25 +6,17 @@ es5id: 15.4.4.20-10-1
description: >
Array.prototype.filter doesn't mutate the Array on which it is
called on
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj)
{
return true;
}
var srcArr = [1,2,3,4,5];
srcArr.filter(callbackfn);
if(srcArr[0] === 1 &&
srcArr[1] === 2 &&
srcArr[2] === 3 &&
srcArr[3] === 4 &&
srcArr[4] === 5)
{
return true;
}
}
runTestCase(testcase);
assert.sameValue(srcArr[0], 1, 'srcArr[0]');
assert.sameValue(srcArr[1], 2, 'srcArr[1]');
assert.sameValue(srcArr[2], 3, 'srcArr[2]');
assert.sameValue(srcArr[3], 4, 'srcArr[3]');
assert.sameValue(srcArr[4], 5, 'srcArr[4]');
......@@ -6,11 +6,8 @@ es5id: 15.4.4.20-10-2
description: >
Array.prototype.filter returns new Array with length equal to
number of true returned by callbackfn
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj)
{
if(val % 2)
......@@ -20,13 +17,8 @@ function testcase() {
}
var srcArr = [1,2,3,4,5];
var resArr = srcArr.filter(callbackfn);
if(resArr.length === 3 &&
resArr[0] === 1 &&
resArr[1] === 3 &&
resArr[2] === 5)
{
return true;
}
}
runTestCase(testcase);
assert.sameValue(resArr.length, 3, 'resArr.length');
assert.sameValue(resArr[0], 1, 'resArr[0]');
assert.sameValue(resArr[1], 3, 'resArr[1]');
assert.sameValue(resArr[2], 5, 'resArr[2]');
......@@ -4,10 +4,8 @@
/*---
es5id: 15.4.4.20-10-3
description: Array.prototype.filter - subclassed array when length is reduced
includes: [runTestCase.js]
---*/
function testcase() {
foo.prototype = new Array(1, 2, 3);
function foo() {}
var f = new foo();
......@@ -16,9 +14,6 @@ function testcase() {
function cb(){return true;}
var a = f.filter(cb);
if (Array.isArray(a) &&
a.length === 1) {
return true;
}
}
runTestCase(testcase);
assert(Array.isArray(a), 'Array.isArray(a) !== true');
assert.sameValue(a.length, 1, 'a.length');
......@@ -4,11 +4,8 @@
/*---
es5id: 15.4.4.20-10-4
description: Array.prototype.filter doesn't visit expandos
includes: [runTestCase.js]
---*/
function testcase() {
var callCnt = 0;
function callbackfn(val, idx, obj)
{
......@@ -19,10 +16,5 @@ function testcase() {
srcArr[true] = 11;
var resArr = srcArr.filter(callbackfn);
if(callCnt == 5)
{
return true;
}
}
runTestCase(testcase);
assert.sameValue(callCnt, 5, 'callCnt');
......@@ -6,11 +6,8 @@ es5id: 15.4.4.20-2-1
description: >
Array.prototype.filter applied to Array-like object, 'length' is
own data property
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj.length === 2;
}
......@@ -24,6 +21,4 @@ function testcase() {
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr.length === 2;
}
runTestCase(testcase);
assert.sameValue(newArr.length, 2, 'newArr.length');
......@@ -6,11 +6,8 @@ es5id: 15.4.4.20-2-10
description: >
Array.prototype.filter applied to Array-like object, 'length' is
inherited accessor property
includes: [runTestCase.js]
---*/
function testcase() {
function callbackfn(val, idx, obj) {
return obj.length === 2;
}
......@@ -33,6 +30,5 @@ function testcase() {
child[2] = 9;
var newArr = Array.prototype.filter.call(child, callbackfn);
return newArr.length === 2;
}
runTestCase(testcase);
assert.sameValue(newArr.length, 2, 'newArr.length');
......@@ -6,11 +6,8 @@ es5id: 15.4.4.20-2-11
description: >
Array.prototype.filter applied to Array-like object, 'length' is
own accessor property without a get function
includes: [runTestCase.js]
---*/
function testcase() {
var accessed = false;
function callbackfn(val, idx, obj) {
accessed = true;
......@@ -27,6 +24,6 @@ function testcase() {
});
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr.length === 0 && !accessed;
}
runTestCase(testcase);
assert.sameValue(newArr.length, 0, 'newArr.length');
assert.sameValue(accessed, false, 'accessed');
......@@ -6,11 +6,8 @@ es5id: 15.4.4.20-2-13
description: >
Array.prototype.filter applied to the Array-like object that
'length' is inherited accessor property without a get function
includes: [runTestCase.js]
---*/
function testcase() {
var accessed = false;
function callbackfn(val, idx, obj) {
accessed = true;
......@@ -31,6 +28,6 @@ function testcase() {
child[1] = 12;
var newArr = Array.prototype.filter.call(child, callbackfn);
return newArr.length === 0 && !accessed;
}
runTestCase(testcase);
assert.sameValue(newArr.length, 0, 'newArr.length');
assert.sameValue(accessed, false, 'accessed');
......@@ -6,11 +6,8 @@ es5id: 15.4.4.20-2-14
description: >
Array.prototype.filter applied to the Array-like object that
'length property doesn't exist
includes: [runTestCase.js]
---*/
function testcase() {
var accessed = false;
function callbackfn(val, idx, obj) {
accessed = true;
......@@ -20,6 +17,6 @@ function testcase() {
var obj = { 0: 11, 1: 12 };
var newArr = Array.prototype.filter.call(obj, callbackfn);
return newArr.length === 0 && !accessed;
}
runTestCase(testcase);
assert.sameValue(newArr.length, 0, 'newArr.length');
assert.sameValue(accessed, false, 'accessed');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment