compare-array-arguments.js (1122B)
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 const fixture = [0, 'a', undefined]; 11 12 function checkFormatOfAssertionMessage(func, errorMessage) { 13 var caught = false; 14 try { 15 func(); 16 } catch (error) { 17 caught = true; 18 assert.sameValue(error.constructor, Test262Error); 19 assert.sameValue(error.message, errorMessage); 20 } 21 22 assert(caught, `Expected ${func} to throw, but it didn't.`); 23 } 24 25 function f() { 26 assert.compareArray(arguments, fixture); 27 assert.compareArray(fixture, arguments); 28 29 checkFormatOfAssertionMessage(() => { 30 assert.compareArray(arguments, [], 'arguments and []'); 31 }, 'Actual [0, a, undefined] and expected [] should have the same contents. arguments and []'); 32 33 checkFormatOfAssertionMessage(() => { 34 assert.compareArray([], arguments, '[] and arguments'); 35 }, 'Actual [] and expected [0, a, undefined] should have the same contents. [] and arguments'); 36 } 37 38 f(...fixture); 39 40 reportCompare(0, 0);