Whitespace cleanups. CRLF => LF

This commit is contained in:
Leo Balter 2019-10-08 15:40:54 -04:00 committed by Rick Waldron
parent bb6ce7e435
commit d49777de27
17 changed files with 729 additions and 898 deletions

View File

@ -1,46 +1,20 @@
// Copyright 2019 Ron Buckton. All rights reserved. // Copyright 2019 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: | description: >
Compare two values structurally Compare two values structurally
defines: [assert.deepEqual] defines: [assert.deepEqual]
---*/ ---*/
// @ts-check
var deepEqual = (function () { var deepEqual = (function () {
/**
* @typedef {0} UNKNOWN
* @typedef {1} EQUAL
* @typedef {-1} NOT_EQUAL
* @typedef {Map<unknown, Map<unknown, EQUAL | NOT_EQUAL>>} ComparisonCache
*/
/** @type {EQUAL} */
var EQUAL = 1; var EQUAL = 1;
/** @type {NOT_EQUAL} */
var NOT_EQUAL = -1; var NOT_EQUAL = -1;
/** @type {UNKNOWN} */
var UNKNOWN = 0; var UNKNOWN = 0;
/**
* @template T
* @param {T} a
* @param {T} b
* @returns {boolean}
*/
function deepEqual(a, b) { function deepEqual(a, b) {
return compareEquality(a, b) === EQUAL; return compareEquality(a, b) === EQUAL;
} }
/**
* @param {unknown} a
* @param {unknown} b
* @param {ComparisonCache} [cache]
* @returns {EQUAL | NOT_EQUAL}
*/
function compareEquality(a, b, cache) { function compareEquality(a, b, cache) {
return compareIf(a, b, isOptional, compareOptionality) return compareIf(a, b, isOptional, compareOptionality)
|| compareIf(a, b, isPrimitiveEquatable, comparePrimitiveEquality) || compareIf(a, b, isPrimitiveEquatable, comparePrimitiveEquality)
@ -48,63 +22,36 @@ var deepEqual = (function () {
|| NOT_EQUAL; || NOT_EQUAL;
} }
/**
* @template T
* @param {unknown} a
* @param {unknown} b
* @param {(value: unknown) => value is T} test
* @param {(a: T, b: T, cache?: ComparisonCache) => EQUAL | NOT_EQUAL} compare
* @param {ComparisonCache} [cache]
* @returns {EQUAL | NOT_EQUAL | UNKNOWN}
*/
function compareIf(a, b, test, compare, cache) { function compareIf(a, b, test, compare, cache) {
return !test(a) return !test(a)
? !test(b) ? UNKNOWN : NOT_EQUAL ? !test(b) ? UNKNOWN : NOT_EQUAL
: !test(b) ? NOT_EQUAL : cacheComparison(a, b, compare, cache); : !test(b) ? NOT_EQUAL : cacheComparison(a, b, compare, cache);
} }
/**
* @returns {EQUAL | UNKNOWN}
*/
function tryCompareStrictEquality(a, b) { function tryCompareStrictEquality(a, b) {
return a === b ? EQUAL : UNKNOWN; return a === b ? EQUAL : UNKNOWN;
} }
/**
* @returns {NOT_EQUAL | UNKNOWN}
*/
function tryCompareTypeOfEquality(a, b) { function tryCompareTypeOfEquality(a, b) {
return typeof a !== typeof b ? NOT_EQUAL : UNKNOWN; return typeof a !== typeof b ? NOT_EQUAL : UNKNOWN;
} }
/**
* @returns {NOT_EQUAL | UNKNOWN}
*/
function tryCompareToStringTagEquality(a, b) { function tryCompareToStringTagEquality(a, b) {
var aTag = Symbol.toStringTag in a ? a[Symbol.toStringTag] : undefined; var aTag = Symbol.toStringTag in a ? a[Symbol.toStringTag] : undefined;
var bTag = Symbol.toStringTag in b ? b[Symbol.toStringTag] : undefined; var bTag = Symbol.toStringTag in b ? b[Symbol.toStringTag] : undefined;
return aTag !== bTag ? NOT_EQUAL : UNKNOWN; return aTag !== bTag ? NOT_EQUAL : UNKNOWN;
} }
/**
* @returns {value is null | undefined}
*/
function isOptional(value) { function isOptional(value) {
return value === undefined return value === undefined
|| value === null; || value === null;
} }
/**
* @returns {EQUAL | NOT_EQUAL}
*/
function compareOptionality(a, b) { function compareOptionality(a, b) {
return tryCompareStrictEquality(a, b) return tryCompareStrictEquality(a, b)
|| NOT_EQUAL; || NOT_EQUAL;
} }
/**
* @returns {value is number | bigint | string | symbol | boolean | undefined}
*/
function isPrimitiveEquatable(value) { function isPrimitiveEquatable(value) {
switch (typeof value) { switch (typeof value) {
case 'string': case 'string':
@ -118,9 +65,6 @@ var deepEqual = (function () {
} }
} }
/**
* @returns {EQUAL | NOT_EQUAL}
*/
function comparePrimitiveEquality(a, b) { function comparePrimitiveEquality(a, b) {
if (isBoxed(a)) a = a.valueOf(); if (isBoxed(a)) a = a.valueOf();
if (isBoxed(b)) b = b.valueOf(); if (isBoxed(b)) b = b.valueOf();
@ -130,33 +74,18 @@ var deepEqual = (function () {
|| NOT_EQUAL; || NOT_EQUAL;
} }
/**
* @returns {value is number}
*/
function isNaNEquatable(value) { function isNaNEquatable(value) {
return typeof value === 'number'; return typeof value === 'number';
} }
/**
* @param {number} a
* @param {number} b
* @returns {EQUAL | NOT_EQUAL}
*/
function compareNaNEquality(a, b) { function compareNaNEquality(a, b) {
return isNaN(a) && isNaN(b) ? EQUAL : NOT_EQUAL; return isNaN(a) && isNaN(b) ? EQUAL : NOT_EQUAL;
} }
/**
* @returns {value is object}
*/
function isObjectEquatable(value) { function isObjectEquatable(value) {
return typeof value === 'object'; return typeof value === 'object';
} }
/**
* @param {ComparisonCache} cache
* @returns {EQUAL | NOT_EQUAL}
*/
function compareObjectEquality(a, b, cache) { function compareObjectEquality(a, b, cache) {
if (!cache) cache = new Map(); if (!cache) cache = new Map();
return getCache(cache, a, b) return getCache(cache, a, b)
@ -179,43 +108,24 @@ var deepEqual = (function () {
|| typeof BigInt === 'function' && value instanceof BigInt; || typeof BigInt === 'function' && value instanceof BigInt;
} }
/**
* @returns {value is { valueOf(): any }}
*/
function isValueOfEquatable(value) { function isValueOfEquatable(value) {
return value instanceof Date; return value instanceof Date;
} }
/**
* @param {{ valueOf(): any }} a
* @param {{ valueOf(): any }} b
* @returns {EQUAL | NOT_EQUAL}
*/
function compareValueOfEquality(a, b) { function compareValueOfEquality(a, b) {
return compareIf(a.valueOf(), b.valueOf(), isPrimitiveEquatable, comparePrimitiveEquality) return compareIf(a.valueOf(), b.valueOf(), isPrimitiveEquatable, comparePrimitiveEquality)
|| NOT_EQUAL; || NOT_EQUAL;
} }
/**
* @returns {value is { toString(): string }}
*/
function isToStringEquatable(value) { function isToStringEquatable(value) {
return value instanceof RegExp; return value instanceof RegExp;
} }
/**
* @param {{ toString(): string }} a
* @param {{ toString(): string }} b
* @returns {EQUAL | NOT_EQUAL}
*/
function compareToStringEquality(a, b) { function compareToStringEquality(a, b) {
return compareIf(a.toString(), b.toString(), isPrimitiveEquatable, comparePrimitiveEquality) return compareIf(a.toString(), b.toString(), isPrimitiveEquatable, comparePrimitiveEquality)
|| NOT_EQUAL; || NOT_EQUAL;
} }
/**
* @returns {value is ArrayLike<unknown>}
*/
function isArrayLikeEquatable(value) { function isArrayLikeEquatable(value) {
return (Array.isArray ? Array.isArray(value) : value instanceof Array) return (Array.isArray ? Array.isArray(value) : value instanceof Array)
|| (typeof Uint8Array === 'function' && value instanceof Uint8Array) || (typeof Uint8Array === 'function' && value instanceof Uint8Array)
@ -231,13 +141,6 @@ var deepEqual = (function () {
|| (typeof BigInt64Array === 'function' && value instanceof BigInt64Array); || (typeof BigInt64Array === 'function' && value instanceof BigInt64Array);
} }
/**
* @template T
* @param {ArrayLike<T>} a
* @param {ArrayLike<T>} b
* @param {ComparisonCache} cache
* @returns {EQUAL | NOT_EQUAL}
*/
function compareArrayLikeEquality(a, b, cache) { function compareArrayLikeEquality(a, b, cache) {
if (a.length !== b.length) return NOT_EQUAL; if (a.length !== b.length) return NOT_EQUAL;
for (var i = 0; i < a.length; i++) { for (var i = 0; i < a.length; i++) {
@ -248,11 +151,6 @@ var deepEqual = (function () {
return EQUAL; return EQUAL;
} }
/**
* @template T
* @param {T} value
* @returns {value is Exclude<T, Promise | WeakMap | WeakSet | Map | Set>}
*/
function isStructurallyEquatable(value) { function isStructurallyEquatable(value) {
return !(typeof Promise === 'function' && value instanceof Promise // only comparable by reference return !(typeof Promise === 'function' && value instanceof Promise // only comparable by reference
|| typeof WeakMap === 'function' && value instanceof WeakMap // only comparable by reference || typeof WeakMap === 'function' && value instanceof WeakMap // only comparable by reference
@ -261,10 +159,6 @@ var deepEqual = (function () {
|| typeof Set === 'function' && value instanceof Set); // comparable via @@iterator || typeof Set === 'function' && value instanceof Set); // comparable via @@iterator
} }
/**
* @param {ComparisonCache} cache
* @returns {EQUAL | NOT_EQUAL}
*/
function compareStructuralEquality(a, b, cache) { function compareStructuralEquality(a, b, cache) {
var aKeys = []; var aKeys = [];
for (var key in a) aKeys.push(key); for (var key in a) aKeys.push(key);
@ -294,21 +188,11 @@ var deepEqual = (function () {
|| EQUAL; || EQUAL;
} }
/**
* @returns {value is Iterable<unknown>}
*/
function isIterableEquatable(value) { function isIterableEquatable(value) {
return typeof Symbol === 'function' return typeof Symbol === 'function'
&& typeof value[Symbol.iterator] === 'function'; && typeof value[Symbol.iterator] === 'function';
} }
/**
* @template T
* @param {Iterator<T>} a
* @param {Iterator<T>} b
* @param {ComparisonCache} cache
* @returns {EQUAL | NOT_EQUAL}
*/
function compareIteratorEquality(a, b, cache) { function compareIteratorEquality(a, b, cache) {
if (typeof Map === 'function' && a instanceof Map && b instanceof Map || if (typeof Map === 'function' && a instanceof Map && b instanceof Map ||
typeof Set === 'function' && a instanceof Set && b instanceof Set) { typeof Set === 'function' && a instanceof Set && b instanceof Set) {
@ -336,23 +220,10 @@ var deepEqual = (function () {
} }
} }
/**
* @template T
* @param {Iterable<T>} a
* @param {Iterable<T>} b
* @param {ComparisonCache} cache
* @returns {EQUAL | NOT_EQUAL}
*/
function compareIterableEquality(a, b, cache) { function compareIterableEquality(a, b, cache) {
return compareIteratorEquality(a[Symbol.iterator](), b[Symbol.iterator](), cache); return compareIteratorEquality(a[Symbol.iterator](), b[Symbol.iterator](), cache);
} }
/**
* @template T
* @template {EQUAL | NOT_EQUAL | UNKNOWN} R
* @param {(a: T, b: T, circular?: ComparisonCache) => R} compare
* @param {ComparisonCache} [cache]
*/
function cacheComparison(a, b, compare, cache) { function cacheComparison(a, b, compare, cache) {
var result = compare(a, b, cache); var result = compare(a, b, cache);
if (cache && (result === EQUAL || result === NOT_EQUAL)) { if (cache && (result === EQUAL || result === NOT_EQUAL)) {
@ -365,10 +236,6 @@ var deepEqual = (function () {
return NOT_EQUAL; return NOT_EQUAL;
} }
/**
* @param {EQUAL | NOT_EQUAL} result
* @param {ComparisonCache} cache
*/
function setCache(cache, left, right, result) { function setCache(cache, left, right, result) {
var otherCache; var otherCache;
@ -381,9 +248,6 @@ var deepEqual = (function () {
otherCache.set(left, result); otherCache.set(left, result);
} }
/**
* @param {ComparisonCache} cache
*/
function getCache(cache, left, right) { function getCache(cache, left, right) {
var otherCache; var otherCache;
/** @type {EQUAL | NOT_EQUAL | UNKNOWN | undefined} */ /** @type {EQUAL | NOT_EQUAL | UNKNOWN | undefined} */
@ -403,12 +267,6 @@ var deepEqual = (function () {
return deepEqual; return deepEqual;
})(); })();
/**
* @template T
* @param {T} actual
* @param {T} expected
* @param {string} [message]
*/
assert.deepEqual = function (actual, expected, message) { assert.deepEqual = function (actual, expected, message) {
assert(deepEqual(actual, expected), assert(deepEqual(actual, expected),
'Expected ' + assert._formatValue(actual) + ' to be structurally equal to ' + assert._formatValue(expected) + '. ' + (message || '')); 'Expected ' + assert._formatValue(actual) + ' to be structurally equal to ' + assert._formatValue(expected) + '. ' + (message || ''));

14
harness/types.d.ts vendored
View File

@ -1,14 +0,0 @@
declare function $ERROR(text: string): void;
// Proposal: regexp-match-indices
interface RegExpExecArray {
indices: RegExpIndicesArray;
}
interface RegExpMatchArray {
indices: RegExpIndicesArray;
}
interface RegExpIndicesArray extends Array<[number, number]> {
groups?: { [group: string]: [number, number] };
}

View File

@ -10,7 +10,6 @@ info: |
5. Return CreateArrayFromList(« _match_.[[StartIndex]], _match_.[[EndIndex]] »). 5. Return CreateArrayFromList(« _match_.[[StartIndex]], _match_.[[EndIndex]] »).
---*/ ---*/
let input = "abcd"; let input = "abcd";
let match = /b(c)/.exec(input); let match = /b(c)/.exec(input);
let indices = match.indices; let indices = match.indices;

View File

@ -22,7 +22,6 @@ info: |
... ...
---*/ ---*/
let input = "abcd"; let input = "abcd";
let match = /b(c)/.exec(input); let match = /b(c)/.exec(input);
let indices = match.indices; let indices = match.indices;

View File

@ -27,7 +27,6 @@ info: |
34. Let _indicesArray_ be MakeIndicesArray( _S_, _indices_, _groupNames_). 34. Let _indicesArray_ be MakeIndicesArray( _S_, _indices_, _groupNames_).
---*/ ---*/
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/).indices); assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./).indices); assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./).indices);
assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/).indices); assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/).indices);

View File

@ -12,7 +12,6 @@ info: |
d. Perform ! CreateDataProperty(_A_, ! ToString(_n_), _matchIndicesArray_). d. Perform ! CreateDataProperty(_A_, ! ToString(_n_), _matchIndicesArray_).
---*/ ---*/
let input = "abcd"; let input = "abcd";
let match = /b(c)/.exec(input); let match = /b(c)/.exec(input);
let indices = match.indices; let indices = match.indices;

View File

@ -36,7 +36,6 @@ info: |
5. Return _eUTF_. 5. Return _eUTF_.
---*/ ---*/
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/u).indices); assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/u).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./u).indices); assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./u).indices);
assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/u).indices); assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/u).indices);

View File

@ -8,7 +8,6 @@ esid: sec-makeindicesarray
features: [regexp-match-indices] features: [regexp-match-indices]
---*/ ---*/
assert.compareArray([1, 2], /(?<π>a)/u.exec("bab").indices.groups.π); assert.compareArray([1, 2], /(?<π>a)/u.exec("bab").indices.groups.π);
assert.compareArray([1, 2], /(?<\u{03C0}>a)/u.exec("bab").indices.groups.π); assert.compareArray([1, 2], /(?<\u{03C0}>a)/u.exec("bab").indices.groups.π);
assert.compareArray([1, 2], /(?<π>a)/u.exec("bab").indices.groups.\u03C0); assert.compareArray([1, 2], /(?<π>a)/u.exec("bab").indices.groups.\u03C0);

View File

@ -21,7 +21,6 @@ info: |
... ...
---*/ ---*/
let input = "abd"; let input = "abd";
let match = /b(c)?/.exec(input); let match = /b(c)?/.exec(input);
let indices = match.indices; let indices = match.indices;

View File

@ -10,7 +10,6 @@ info: |
6. Set _A_ to ! ArrayCreate(_n_). 6. Set _A_ to ! ArrayCreate(_n_).
---*/ ---*/
let match = /a/.exec("a"); let match = /a/.exec("a");
let indices = match.indices; let indices = match.indices;

View File

@ -12,7 +12,6 @@ info: |
35. Perform ! DefinePropertyOrThrow(_A_, `"indices"`, PropertyDescriptor { [[Value]]: _indicesArray_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }). 35. Perform ! DefinePropertyOrThrow(_A_, `"indices"`, PropertyDescriptor { [[Value]]: _indicesArray_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }).
---*/ ---*/
// `indices` is created with Define, not Set. // `indices` is created with Define, not Set.
let counter = 0; let counter = 0;
Object.defineProperty(Array.prototype, "indices", { Object.defineProperty(Array.prototype, "indices", {

View File

@ -7,7 +7,6 @@ description: >
includes: [deepEqual.js] includes: [deepEqual.js]
---*/ ---*/
assert.deepEqual([], []); assert.deepEqual([], []);
assert.deepEqual([1, "a", true], [1, "a", true]); assert.deepEqual([1, "a", true], [1, "a", true]);

View File

@ -7,7 +7,6 @@ description: >
includes: [deepEqual.js] includes: [deepEqual.js]
---*/ ---*/
var a = { x: 1 }; var a = { x: 1 };
var b = { x: 1 }; var b = { x: 1 };
a.a = a; a.a = a;

View File

@ -7,7 +7,6 @@ description: >
includes: [deepEqual.js] includes: [deepEqual.js]
---*/ ---*/
assert.deepEqual({ a: { x: 1 }, b: [true] }, { a: { x: 1 }, b: [true] }); assert.deepEqual({ a: { x: 1 }, b: [true] }, { a: { x: 1 }, b: [true] });
assert.throws(Test262Error, function () { assert.deepEqual({}, { a: { x: 1 }, b: [true] }); }); assert.throws(Test262Error, function () { assert.deepEqual({}, { a: { x: 1 }, b: [true] }); });

View File

@ -7,7 +7,6 @@ description: >
includes: [deepEqual.js] includes: [deepEqual.js]
---*/ ---*/
assert.deepEqual(new Set(), new Set()); assert.deepEqual(new Set(), new Set());
assert.deepEqual(new Set([1, "a", true]), new Set([1, "a", true])); assert.deepEqual(new Set([1, "a", true]), new Set([1, "a", true]));
assert.deepEqual(new Map(), new Map()); assert.deepEqual(new Map(), new Map());