mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
This reverts commit b690cb67be9b487eb10156c03e2c00869e88cc9d, reversing changes made to 50dd431dffe5cf86e9064a652d6b01dbbe542cf0. This is necessary because the reverted changeset reduced coverage by an unknown extent.
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
// Copyright (C) 2017 Ecma International. All rights reserved.
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
/*---
|
|
description: |
|
|
Compare the contents of two arrays
|
|
defines: [compareArray]
|
|
---*/
|
|
|
|
function compareArray(a, b) {
|
|
if (b.length !== a.length) {
|
|
return false;
|
|
}
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
|
if (!compareArray.isSameValue(b[i], a[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
compareArray.isSameValue = function(a, b) {
|
|
if (a === 0 && b === 0) return 1 / a === 1 / b;
|
|
if (a !== a && b !== b) return true;
|
|
|
|
return a === b;
|
|
};
|
|
|
|
compareArray.format = function(array) {
|
|
return `[${array.map(String).join(', ')}]`;
|
|
};
|
|
|
|
assert.compareArray = function(actual, expected, message) {
|
|
message = message === undefined ? '' : message;
|
|
assert(actual != null, `First argument shouldn't be nullish. ${message}`);
|
|
assert(expected != null, `Second argument shouldn't be nullish. ${message}`);
|
|
var format = compareArray.format;
|
|
assert(
|
|
compareArray(actual, expected),
|
|
`Expected ${format(actual)} and ${format(expected)} to have the same contents. ${message}`
|
|
);
|
|
};
|