mirror of
https://github.com/tc39/test262.git
synced 2025-09-26 11:38:50 +02:00
Prefer assert.compareArray to compare arrays
This commit is contained in:
parent
0426d82c35
commit
8145995ec1
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
/*---
|
||||
includes: [compareArray.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
@ -11,22 +12,6 @@ description: |
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
function arrayEvery(arr, fun)
|
||||
{
|
||||
return Array.prototype.every.call(arr, fun);
|
||||
}
|
||||
|
||||
function arraysEqual(a1, a2)
|
||||
{
|
||||
return a1.length === a2.length &&
|
||||
arrayEvery(a1, function(v, i) { return v === a2[i]; });
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* NON-STRICT ARGUMENTS *
|
||||
************************/
|
||||
@ -35,16 +20,16 @@ var obj = {};
|
||||
|
||||
function noargs() { return arguments; }
|
||||
|
||||
assert.sameValue(arraysEqual(noargs(), []), true);
|
||||
assert.sameValue(arraysEqual(noargs(1), [1]), true);
|
||||
assert.sameValue(arraysEqual(noargs(2, obj, 8), [2, obj, 8]), true);
|
||||
assert.compareArray(noargs(), []);
|
||||
assert.compareArray(noargs(1), [1]);
|
||||
assert.compareArray(noargs(2, obj, 8), [2, obj, 8]);
|
||||
|
||||
function args(a) { return arguments; }
|
||||
|
||||
assert.sameValue(arraysEqual(args(), []), true);
|
||||
assert.sameValue(arraysEqual(args(1), [1]), true);
|
||||
assert.sameValue(arraysEqual(args(1, obj), [1, obj]), true);
|
||||
assert.sameValue(arraysEqual(args("foopy"), ["foopy"]), true);
|
||||
assert.compareArray(args(), []);
|
||||
assert.compareArray(args(1), [1]);
|
||||
assert.compareArray(args(1, obj), [1, obj]);
|
||||
assert.compareArray(args("foopy"), ["foopy"]);
|
||||
|
||||
function assign(a)
|
||||
{
|
||||
@ -52,7 +37,7 @@ function assign(a)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(assign(1), [17]), true);
|
||||
assert.compareArray(assign(1), [17]);
|
||||
|
||||
function getLaterAssign(a)
|
||||
{
|
||||
@ -61,7 +46,7 @@ function getLaterAssign(a)
|
||||
return o;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(getLaterAssign(1), [17]), true);
|
||||
assert.compareArray(getLaterAssign(1), [17]);
|
||||
|
||||
function assignElementGetParameter(a)
|
||||
{
|
||||
@ -123,9 +108,9 @@ function strictNoargs()
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNoargs(), []), true);
|
||||
assert.sameValue(arraysEqual(strictNoargs(1), [1]), true);
|
||||
assert.sameValue(arraysEqual(strictNoargs(1, obj), [1, obj]), true);
|
||||
assert.compareArray(strictNoargs(), []);
|
||||
assert.compareArray(strictNoargs(1), [1]);
|
||||
assert.compareArray(strictNoargs(1, obj), [1, obj]);
|
||||
|
||||
function strictArgs(a)
|
||||
{
|
||||
@ -133,9 +118,9 @@ function strictArgs(a)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictArgs(), []), true);
|
||||
assert.sameValue(arraysEqual(strictArgs(1), [1]), true);
|
||||
assert.sameValue(arraysEqual(strictArgs(1, obj), [1, obj]), true);
|
||||
assert.compareArray(strictArgs(), []);
|
||||
assert.compareArray(strictArgs(1), [1]);
|
||||
assert.compareArray(strictArgs(1, obj), [1, obj]);
|
||||
|
||||
function strictAssign(a)
|
||||
{
|
||||
@ -144,9 +129,9 @@ function strictAssign(a)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictAssign(), []), true);
|
||||
assert.sameValue(arraysEqual(strictAssign(1), [1]), true);
|
||||
assert.sameValue(arraysEqual(strictAssign(1, obj), [1, obj]), true);
|
||||
assert.compareArray(strictAssign(), []);
|
||||
assert.compareArray(strictAssign(1), [1]);
|
||||
assert.compareArray(strictAssign(1, obj), [1, obj]);
|
||||
|
||||
var upper;
|
||||
function strictAssignAfter(a)
|
||||
@ -157,9 +142,9 @@ function strictAssignAfter(a)
|
||||
return upper;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictAssignAfter(), []), true);
|
||||
assert.sameValue(arraysEqual(strictAssignAfter(17), [17]), true);
|
||||
assert.sameValue(arraysEqual(strictAssignAfter(obj), [obj]), true);
|
||||
assert.compareArray(strictAssignAfter(), []);
|
||||
assert.compareArray(strictAssignAfter(17), [17]);
|
||||
assert.compareArray(strictAssignAfter(obj), [obj]);
|
||||
|
||||
function strictMaybeAssignOuterParam(p)
|
||||
{
|
||||
@ -168,9 +153,9 @@ function strictMaybeAssignOuterParam(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictMaybeAssignOuterParam(), []), true);
|
||||
assert.sameValue(arraysEqual(strictMaybeAssignOuterParam(42), [42]), true);
|
||||
assert.sameValue(arraysEqual(strictMaybeAssignOuterParam(obj), [obj]), true);
|
||||
assert.compareArray(strictMaybeAssignOuterParam(), []);
|
||||
assert.compareArray(strictMaybeAssignOuterParam(42), [42]);
|
||||
assert.compareArray(strictMaybeAssignOuterParam(obj), [obj]);
|
||||
|
||||
function strictAssignOuterParam(p)
|
||||
{
|
||||
@ -180,9 +165,9 @@ function strictAssignOuterParam(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictAssignOuterParam(), []), true);
|
||||
assert.sameValue(arraysEqual(strictAssignOuterParam(17), [17]), true);
|
||||
assert.sameValue(arraysEqual(strictAssignOuterParam(obj), [obj]), true);
|
||||
assert.compareArray(strictAssignOuterParam(), []);
|
||||
assert.compareArray(strictAssignOuterParam(17), [17]);
|
||||
assert.compareArray(strictAssignOuterParam(obj), [obj]);
|
||||
|
||||
function strictAssignOuterParamPSYCH(p)
|
||||
{
|
||||
@ -192,9 +177,9 @@ function strictAssignOuterParamPSYCH(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictAssignOuterParamPSYCH(), []), true);
|
||||
assert.sameValue(arraysEqual(strictAssignOuterParamPSYCH(17), [17]), true);
|
||||
assert.sameValue(arraysEqual(strictAssignOuterParamPSYCH(obj), [obj]), true);
|
||||
assert.compareArray(strictAssignOuterParamPSYCH(), []);
|
||||
assert.compareArray(strictAssignOuterParamPSYCH(17), [17]);
|
||||
assert.compareArray(strictAssignOuterParamPSYCH(obj), [obj]);
|
||||
|
||||
function strictEval(code, p)
|
||||
{
|
||||
@ -203,12 +188,12 @@ function strictEval(code, p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictEval("1", 2), ["1", 2]), true);
|
||||
assert.sameValue(arraysEqual(strictEval("arguments"), ["arguments"]), true);
|
||||
assert.sameValue(arraysEqual(strictEval("p = 2"), ["p = 2"]), true);
|
||||
assert.sameValue(arraysEqual(strictEval("p = 2", 17), ["p = 2", 17]), true);
|
||||
assert.sameValue(arraysEqual(strictEval("arguments[0] = 17"), [17]), true);
|
||||
assert.sameValue(arraysEqual(strictEval("arguments[0] = 17", 42), [17, 42]), true);
|
||||
assert.compareArray(strictEval("1", 2), ["1", 2]);
|
||||
assert.compareArray(strictEval("arguments"), ["arguments"]);
|
||||
assert.compareArray(strictEval("p = 2"), ["p = 2"]);
|
||||
assert.compareArray(strictEval("p = 2", 17), ["p = 2", 17]);
|
||||
assert.compareArray(strictEval("arguments[0] = 17"), [17]);
|
||||
assert.compareArray(strictEval("arguments[0] = 17", 42), [17, 42]);
|
||||
|
||||
function strictMaybeNestedEval(code, p)
|
||||
{
|
||||
@ -217,10 +202,10 @@ function strictMaybeNestedEval(code, p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictMaybeNestedEval("1", 2), ["1", 2]), true);
|
||||
assert.sameValue(arraysEqual(strictMaybeNestedEval("arguments"), ["arguments"]), true);
|
||||
assert.sameValue(arraysEqual(strictMaybeNestedEval("p = 2"), ["p = 2"]), true);
|
||||
assert.sameValue(arraysEqual(strictMaybeNestedEval("p = 2", 17), ["p = 2", 17]), true);
|
||||
assert.compareArray(strictMaybeNestedEval("1", 2), ["1", 2]);
|
||||
assert.compareArray(strictMaybeNestedEval("arguments"), ["arguments"]);
|
||||
assert.compareArray(strictMaybeNestedEval("p = 2"), ["p = 2"]);
|
||||
assert.compareArray(strictMaybeNestedEval("p = 2", 17), ["p = 2", 17]);
|
||||
|
||||
function strictNestedEval(code, p)
|
||||
{
|
||||
@ -230,12 +215,12 @@ function strictNestedEval(code, p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedEval("1", 2), ["1", 2]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedEval("arguments"), ["arguments"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedEval("p = 2"), ["p = 2"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedEval("p = 2", 17), ["p = 2", 17]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedEval("arguments[0] = 17"), ["arguments[0] = 17"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedEval("arguments[0] = 17", 42), ["arguments[0] = 17", 42]), true);
|
||||
assert.compareArray(strictNestedEval("1", 2), ["1", 2]);
|
||||
assert.compareArray(strictNestedEval("arguments"), ["arguments"]);
|
||||
assert.compareArray(strictNestedEval("p = 2"), ["p = 2"]);
|
||||
assert.compareArray(strictNestedEval("p = 2", 17), ["p = 2", 17]);
|
||||
assert.compareArray(strictNestedEval("arguments[0] = 17"), ["arguments[0] = 17"]);
|
||||
assert.compareArray(strictNestedEval("arguments[0] = 17", 42), ["arguments[0] = 17", 42]);
|
||||
|
||||
function strictAssignArguments(a)
|
||||
{
|
||||
@ -307,10 +292,10 @@ function strictNestedAssignShadowVar(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowVar(), []), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowVar(99), [99]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowVar(""), [""]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowVar(obj), [obj]), true);
|
||||
assert.compareArray(strictNestedAssignShadowVar(), []);
|
||||
assert.compareArray(strictNestedAssignShadowVar(99), [99]);
|
||||
assert.compareArray(strictNestedAssignShadowVar(""), [""]);
|
||||
assert.compareArray(strictNestedAssignShadowVar(obj), [obj]);
|
||||
|
||||
function strictNestedAssignShadowCatch(p)
|
||||
{
|
||||
@ -329,10 +314,10 @@ function strictNestedAssignShadowCatch(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatch(), []), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatch(99), [99]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatch(""), [""]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatch(obj), [obj]), true);
|
||||
assert.compareArray(strictNestedAssignShadowCatch(), []);
|
||||
assert.compareArray(strictNestedAssignShadowCatch(99), [99]);
|
||||
assert.compareArray(strictNestedAssignShadowCatch(""), [""]);
|
||||
assert.compareArray(strictNestedAssignShadowCatch(obj), [obj]);
|
||||
|
||||
function strictNestedAssignShadowCatchCall(p)
|
||||
{
|
||||
@ -352,10 +337,10 @@ function strictNestedAssignShadowCatchCall(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatchCall(), []), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatchCall(99), [99]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatchCall(""), [""]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowCatchCall(obj), [obj]), true);
|
||||
assert.compareArray(strictNestedAssignShadowCatchCall(), []);
|
||||
assert.compareArray(strictNestedAssignShadowCatchCall(99), [99]);
|
||||
assert.compareArray(strictNestedAssignShadowCatchCall(""), [""]);
|
||||
assert.compareArray(strictNestedAssignShadowCatchCall(obj), [obj]);
|
||||
|
||||
function strictNestedAssignShadowFunction(p)
|
||||
{
|
||||
@ -368,10 +353,10 @@ function strictNestedAssignShadowFunction(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunction(), []), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunction(99), [99]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunction(""), [""]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunction(obj), [obj]), true);
|
||||
assert.compareArray(strictNestedAssignShadowFunction(), []);
|
||||
assert.compareArray(strictNestedAssignShadowFunction(99), [99]);
|
||||
assert.compareArray(strictNestedAssignShadowFunction(""), [""]);
|
||||
assert.compareArray(strictNestedAssignShadowFunction(obj), [obj]);
|
||||
|
||||
function strictNestedAssignShadowFunctionCall(p)
|
||||
{
|
||||
@ -384,10 +369,10 @@ function strictNestedAssignShadowFunctionCall(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionCall(), []), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionCall(99), [99]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionCall(""), [""]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionCall(obj), [obj]), true);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionCall(), []);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionCall(99), [99]);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionCall(""), [""]);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionCall(obj), [obj]);
|
||||
|
||||
function strictNestedShadowAndMaybeEval(code, p)
|
||||
{
|
||||
@ -396,12 +381,12 @@ function strictNestedShadowAndMaybeEval(code, p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndMaybeEval("1", 2), ["1", 2]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndMaybeEval("arguments"), ["arguments"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndMaybeEval("p = 2"), ["p = 2"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndMaybeEval("p = 2", 17), ["p = 2", 17]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndMaybeEval("arguments[0] = 17"), ["arguments[0] = 17"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndMaybeEval("arguments[0] = 17", 42), ["arguments[0] = 17", 42]), true);
|
||||
assert.compareArray(strictNestedShadowAndMaybeEval("1", 2), ["1", 2]);
|
||||
assert.compareArray(strictNestedShadowAndMaybeEval("arguments"), ["arguments"]);
|
||||
assert.compareArray(strictNestedShadowAndMaybeEval("p = 2"), ["p = 2"]);
|
||||
assert.compareArray(strictNestedShadowAndMaybeEval("p = 2", 17), ["p = 2", 17]);
|
||||
assert.compareArray(strictNestedShadowAndMaybeEval("arguments[0] = 17"), ["arguments[0] = 17"]);
|
||||
assert.compareArray(strictNestedShadowAndMaybeEval("arguments[0] = 17", 42), ["arguments[0] = 17", 42]);
|
||||
|
||||
function strictNestedShadowAndEval(code, p)
|
||||
{
|
||||
@ -410,12 +395,12 @@ function strictNestedShadowAndEval(code, p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndEval("1", 2), ["1", 2]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndEval("arguments"), ["arguments"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndEval("p = 2"), ["p = 2"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndEval("p = 2", 17), ["p = 2", 17]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndEval("arguments[0] = 17"), ["arguments[0] = 17"]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedShadowAndEval("arguments[0] = 17", 42), ["arguments[0] = 17", 42]), true);
|
||||
assert.compareArray(strictNestedShadowAndEval("1", 2), ["1", 2]);
|
||||
assert.compareArray(strictNestedShadowAndEval("arguments"), ["arguments"]);
|
||||
assert.compareArray(strictNestedShadowAndEval("p = 2"), ["p = 2"]);
|
||||
assert.compareArray(strictNestedShadowAndEval("p = 2", 17), ["p = 2", 17]);
|
||||
assert.compareArray(strictNestedShadowAndEval("arguments[0] = 17"), ["arguments[0] = 17"]);
|
||||
assert.compareArray(strictNestedShadowAndEval("arguments[0] = 17", 42), ["arguments[0] = 17", 42]);
|
||||
|
||||
function strictEvalContainsMutation(code)
|
||||
{
|
||||
@ -423,8 +408,8 @@ function strictEvalContainsMutation(code)
|
||||
return eval(code);
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictEvalContainsMutation("code = 17; arguments"), ["code = 17; arguments"]), true);
|
||||
assert.sameValue(arraysEqual(strictEvalContainsMutation("arguments[0] = 17; arguments"), [17]), true);
|
||||
assert.compareArray(strictEvalContainsMutation("code = 17; arguments"), ["code = 17; arguments"]);
|
||||
assert.compareArray(strictEvalContainsMutation("arguments[0] = 17; arguments"), [17]);
|
||||
assert.sameValue(strictEvalContainsMutation("arguments[0] = 17; code"), "arguments[0] = 17; code");
|
||||
|
||||
function strictNestedAssignShadowFunctionName(p)
|
||||
@ -439,7 +424,7 @@ function strictNestedAssignShadowFunctionName(p)
|
||||
return arguments;
|
||||
}
|
||||
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionName(), []), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionName(99), [99]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionName(""), [""]), true);
|
||||
assert.sameValue(arraysEqual(strictNestedAssignShadowFunctionName(obj), [obj]), true);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionName(), []);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionName(99), [99]);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionName(""), [""]);
|
||||
assert.compareArray(strictNestedAssignShadowFunctionName(obj), [obj]);
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
/*---
|
||||
includes: [compareArray.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
@ -11,31 +12,23 @@ description: |
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
function assertEqArr(a1, a2) {
|
||||
assert.sameValue(a1.length, a2.length);
|
||||
|
||||
for(var i=0; i<a1.length; i++) {
|
||||
assert.sameValue(a1[i], a2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var order = "";
|
||||
var o1 = { toString: function() { order += "b"; return "-"; }};
|
||||
var o2 = { valueOf: function() { order += "a"; return 1; }};
|
||||
var res = "xyz-xyz".split(o1, o2);
|
||||
|
||||
assert.sameValue(order, "ab");
|
||||
assertEqArr(res, ["xyz"]);
|
||||
assert.compareArray(res, ["xyz"]);
|
||||
|
||||
assertEqArr("".split(/.?/), []);
|
||||
assertEqArr("abc".split(/\b/), ["abc"]);
|
||||
assert.compareArray("".split(/.?/), []);
|
||||
assert.compareArray("abc".split(/\b/), ["abc"]);
|
||||
|
||||
assertEqArr("abc".split(/((()))./, 2), ["",""]);
|
||||
assertEqArr("abc".split(/((((()))))./, 9), ["","","","","","","","",""]);
|
||||
assert.compareArray("abc".split(/((()))./, 2), ["",""]);
|
||||
assert.compareArray("abc".split(/((((()))))./, 9), ["","","","","","","","",""]);
|
||||
|
||||
// from ES5 15.5.4.14
|
||||
assertEqArr("ab".split(/a*?/), ["a", "b"]);
|
||||
assertEqArr("ab".split(/a*/), ["", "b"]);
|
||||
assertEqArr("A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/),
|
||||
["A", undefined, "B", "bold", "/", "B", "and", undefined,
|
||||
"CODE", "coded", "/", "CODE", ""]);
|
||||
assert.compareArray("ab".split(/a*?/), ["a", "b"]);
|
||||
assert.compareArray("ab".split(/a*/), ["", "b"]);
|
||||
assert.compareArray("A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/),
|
||||
["A", undefined, "B", "bold", "/", "B", "and", undefined,
|
||||
"CODE", "coded", "/", "CODE", ""]);
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
/*---
|
||||
includes: [compareArray.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
@ -11,21 +12,14 @@ description: |
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
function assertEqArr(a1, a2) {
|
||||
assert.sameValue(a1.length, a2.length);
|
||||
|
||||
for(var i=0; i<a1.length; i++) {
|
||||
assert.sameValue(a1[i], a2[i]);
|
||||
}
|
||||
}
|
||||
var s = '--undefined--undefined--';
|
||||
|
||||
assertEqArr(s.split(undefined, undefined), [s]);
|
||||
assertEqArr(s.split(undefined, -1), [s]);
|
||||
assert.compareArray(s.split(undefined, undefined), [s]);
|
||||
assert.compareArray(s.split(undefined, -1), [s]);
|
||||
|
||||
assertEqArr(s.split(undefined, 1), [s]);
|
||||
assertEqArr(s.split("undefined", 1), ["--"]);
|
||||
assert.compareArray(s.split(undefined, 1), [s]);
|
||||
assert.compareArray(s.split("undefined", 1), ["--"]);
|
||||
|
||||
assertEqArr(s.split("-", 0), []);
|
||||
assertEqArr(s.split(undefined, 0), []);
|
||||
assertEqArr(s.split(s, 0), []);
|
||||
assert.compareArray(s.split("-", 0), []);
|
||||
assert.compareArray(s.split(undefined, 0), []);
|
||||
assert.compareArray(s.split(s, 0), []);
|
||||
|
@ -4,27 +4,13 @@
|
||||
*/
|
||||
|
||||
/*---
|
||||
includes: [compareArray.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
pending
|
||||
Object.keys(O)
|
||||
esid: pending
|
||||
---*/
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 307791;
|
||||
var summary = 'ES5 Object.keys(O)';
|
||||
var actual = '';
|
||||
var expect = '';
|
||||
|
||||
function arraysEqual(a1, a2)
|
||||
{
|
||||
return a1.length === a2.length &&
|
||||
a1.every(function(v, i) { return v === a2[i]; });
|
||||
}
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
assert.sameValue(Object.keys.length, 1);
|
||||
|
||||
@ -32,63 +18,39 @@ var o, keys;
|
||||
|
||||
o = { a: 3, b: 2 };
|
||||
keys = Object.keys(o);
|
||||
assert.sameValue(arraysEqual(keys, ["a", "b"]), true,
|
||||
"" + keys);
|
||||
assert.compareArray(keys, ["a", "b"]);
|
||||
|
||||
o = { get a() { return 17; }, b: 2 };
|
||||
keys = Object.keys(o),
|
||||
assert.sameValue(arraysEqual(keys, ["a", "b"]), true,
|
||||
"" + keys);
|
||||
assert.compareArray(keys, ["a", "b"]);
|
||||
|
||||
o = { __iterator__: function() { throw new Error("non-standard __iterator__ called?"); } };
|
||||
keys = Object.keys(o);
|
||||
assert.sameValue(arraysEqual(keys, ["__iterator__"]), true,
|
||||
"" + keys);
|
||||
assert.compareArray(keys, ["__iterator__"]);
|
||||
|
||||
o = { a: 1, b: 2 };
|
||||
delete o.a;
|
||||
o.a = 3;
|
||||
keys = Object.keys(o);
|
||||
assert.sameValue(arraysEqual(keys, ["b", "a"]), true,
|
||||
"" + keys);
|
||||
assert.compareArray(keys, ["b", "a"]);
|
||||
|
||||
o = [0, 1, 2];
|
||||
keys = Object.keys(o);
|
||||
assert.sameValue(arraysEqual(keys, ["0", "1", "2"]), true,
|
||||
"" + keys);
|
||||
assert.compareArray(keys, ["0", "1", "2"]);
|
||||
|
||||
o = /./.exec("abc");
|
||||
keys = Object.keys(o);
|
||||
assert.sameValue(arraysEqual(keys, ["0", "index", "input", "groups"]), true,
|
||||
"" + keys);
|
||||
assert.compareArray(keys, ["0", "index", "input", "groups"]);
|
||||
|
||||
o = { a: 1, b: 2, c: 3 };
|
||||
delete o.b;
|
||||
o.b = 5;
|
||||
keys = Object.keys(o);
|
||||
assert.sameValue(arraysEqual(keys, ["a", "c", "b"]), true,
|
||||
"" + keys);
|
||||
assert.compareArray(keys, ["a", "c", "b"]);
|
||||
|
||||
function f() { }
|
||||
f.prototype.p = 1;
|
||||
o = new f();
|
||||
o.g = 1;
|
||||
keys = Object.keys(o);
|
||||
assert.sameValue(arraysEqual(keys, ["g"]), true,
|
||||
"" + keys);
|
||||
|
||||
if (typeof Namespace !== "undefined" && typeof QName !== "undefined")
|
||||
{
|
||||
var o2 = {};
|
||||
var qn = new QName(new Namespace("foo"), "v");
|
||||
o2.f = 1;
|
||||
o2[qn] = 3;
|
||||
o2.baz = 4;
|
||||
var keys2 = Object.keys(o2);
|
||||
assert.sameValue(arraysEqual(keys2, ["f", "foo::v", "baz"]), true,
|
||||
"" + keys2);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
assert.sameValue(expect, actual, "Object.keys");
|
||||
assert.compareArray(keys, ["g"]);
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
/*---
|
||||
includes: [compareArray.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
@ -13,17 +14,12 @@ esid: pending
|
||||
|
||||
var a, names, expected;
|
||||
|
||||
function arraysEqual(a1, a2)
|
||||
{
|
||||
return a1.length === a2.length &&
|
||||
a1.every(function(v, i) { return v === a2[i]; });
|
||||
}
|
||||
|
||||
|
||||
a = [0, 1, 2];
|
||||
|
||||
names = Object.getOwnPropertyNames(a).sort();
|
||||
expected = ["0", "1", "2", "length"].sort();
|
||||
assert.compareArray(names, expected);
|
||||
|
||||
|
||||
a = [1, , , 7];
|
||||
a.p = 2;
|
||||
@ -31,11 +27,11 @@ Object.defineProperty(a, "q", { value: 42, enumerable: false });
|
||||
|
||||
names = Object.getOwnPropertyNames(a).sort();
|
||||
expected = ["0", "3", "p", "q", "length"].sort();
|
||||
assert.sameValue(arraysEqual(names, expected), true);
|
||||
assert.compareArray(names, expected);
|
||||
|
||||
|
||||
a = [];
|
||||
|
||||
names = Object.getOwnPropertyNames(a).sort();
|
||||
expected = ["length"];
|
||||
assert.sameValue(arraysEqual(names, expected), true);
|
||||
assert.compareArray(names, expected);
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
/*---
|
||||
includes: [compareArray.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
|
Loading…
x
Reference in New Issue
Block a user