MCPcopy Create free account
hub / github.com/nodejs/node / assert_array_equals

Function assert_array_equals

deps/v8/test/wasm-js/third_party/testharness.js:1231–1285  ·  view source on GitHub ↗
(actual, expected, description)

Source from the content-addressed store, hash-verified

1229 expose(assert_object_equals, "assert_object_equals");
1230
1231 function assert_array_equals(actual, expected, description)
1232 {
1233 const max_array_length = 20;
1234 function shorten_array(arr, offset = 0) {
1235 // Make ", …" only show up when it would likely reduce the length, not accounting for
1236 // fonts.
1237 if (arr.length < max_array_length + 2) {
1238 return arr;
1239 }
1240 // By default we want half the elements after the offset and half before
1241 // But if that takes us past the end of the array, we have more before, and
1242 // if it takes us before the start we have more after.
1243 const length_after_offset = Math.floor(max_array_length / 2);
1244 let upper_bound = Math.min(length_after_offset + offset, arr.length);
1245 const lower_bound = Math.max(upper_bound - max_array_length, 0);
1246
1247 if (lower_bound === 0) {
1248 upper_bound = max_array_length;
1249 }
1250
1251 const output = arr.slice(lower_bound, upper_bound);
1252 if (lower_bound > 0) {
1253 output.beginEllipsis = true;
1254 }
1255 if (upper_bound < arr.length) {
1256 output.endEllipsis = true;
1257 }
1258 return output;
1259 }
1260
1261 assert(typeof actual === "object" && actual !== null && "length" in actual,
1262 "assert_array_equals", description,
1263 "value is ${actual}, expected array",
1264 {actual:actual});
1265 assert(actual.length === expected.length,
1266 "assert_array_equals", description,
1267 "lengths differ, expected array ${expected} length ${expectedLength}, got ${actual} length ${actualLength}",
1268 {expected:shorten_array(expected, expected.length - 1), expectedLength:expected.length,
1269 actual:shorten_array(actual, actual.length - 1), actualLength:actual.length
1270 });
1271
1272 for (var i = 0; i < actual.length; i++) {
1273 assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),
1274 "assert_array_equals", description,
1275 "expected property ${i} to be ${expected} but was ${actual} (expected array ${arrayExpected} got ${arrayActual})",
1276 {i:i, expected:expected.hasOwnProperty(i) ? "present" : "missing",
1277 actual:actual.hasOwnProperty(i) ? "present" : "missing",
1278 arrayExpected:shorten_array(expected, i), arrayActual:shorten_array(actual, i)});
1279 assert(same_value(expected[i], actual[i]),
1280 "assert_array_equals", description,
1281 "expected property ${i} to be ${expected} but got ${actual} (expected array ${arrayExpected} got ${arrayActual})",
1282 {i:i, expected:expected[i], actual:actual[i],
1283 arrayExpected:shorten_array(expected, i), arrayActual:shorten_array(actual, i)});
1284 }
1285 }
1286 expose(assert_array_equals, "assert_array_equals");
1287
1288 function assert_array_approx_equals(actual, expected, epsilon, description)

Callers

nothing calls this directly

Calls 4

assertFunction · 0.70
shorten_arrayFunction · 0.70
same_valueFunction · 0.70
hasOwnPropertyMethod · 0.45

Tested by

no test coverage detected