compare-array-arraylike.js (1102B)
1 // Copyright (C) 2021 Rick Waldron. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: > 6 Accepts spreadable arguments 7 includes: [compareArray.js] 8 ---*/ 9 10 function checkFormatOfAssertionMessage(func, errorMessage) { 11 var caught = false; 12 try { 13 func(); 14 } catch (error) { 15 caught = true; 16 assert.sameValue(error.constructor, Test262Error); 17 assert.sameValue(error.message, errorMessage); 18 } 19 20 assert(caught, `Expected ${func} to throw, but it didn't.`); 21 } 22 23 const fixture = { length: 3, 0: 0, 1: 'a', 2: undefined}; 24 25 assert.compareArray(fixture, [0, 'a', undefined]); 26 assert.compareArray([0, 'a', undefined], fixture); 27 28 checkFormatOfAssertionMessage(() => { 29 assert.compareArray(fixture, [], 'fixture and []'); 30 }, 'Actual [0, a, undefined] and expected [] should have the same contents. fixture and []'); 31 32 checkFormatOfAssertionMessage(() => { 33 assert.compareArray([], fixture, '[] and fixture'); 34 }, 'Actual [] and expected [0, a, undefined] should have the same contents. [] and fixture'); 35 36 reportCompare(0, 0);