Some cleanup follow ups (#2351)

This commit is contained in:
Leo Balter 2019-09-18 14:15:53 -03:00 committed by GitHub
parent 1056d8fde9
commit 0fd3cf4d24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 11 additions and 58 deletions

View File

@ -5,8 +5,6 @@ description: |
Collection of assertion functions used throughout test262
---*/
/// <reference lib="esnext" />
/// <reference path="./types.d.ts" />
function assert(mustBeTrue, message) {
if (mustBeTrue === true) {
@ -95,10 +93,10 @@ assert.throws = function (expectedErrorConstructor, func, message) {
$ERROR(message);
};
assert._formatValue = function(value, seen) {
assert._formatValue = (value, seen) => {
switch (typeof value) {
case 'string':
return typeof JSON !== "undefined" ? JSON.stringify(value) : '"' + value + '"';
return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`;
case 'number':
case 'boolean':
case 'symbol':
@ -107,10 +105,10 @@ assert._formatValue = function(value, seen) {
case 'undefined':
return 'undefined';
case 'function':
return '[Function' + (value.name ? ': ' + value.name : '') + ']';
return `[Function${value.name ? `: ${value.name}` : ''}]`;
case 'object':
if (value === null) return 'null';
if (value instanceof Date) return 'Date "' + value.toISOString() + '"';
if (value instanceof Date) return `Date "${value.toISOString()}"`;
if (value instanceof RegExp) return value.toString();
if (!seen) {
seen = {
@ -119,29 +117,29 @@ assert._formatValue = function(value, seen) {
};
}
var usage = seen.map.get(value);
let usage = seen.map.get(value);
if (usage) {
usage.used = true;
return '[Ref: #' + usage.id + ']';
return `[Ref: #${usage.id}]`;
}
usage = { id: ++seen.counter, used: false };
seen.map.set(value, usage);
if (typeof Set !== "undefined" && value instanceof Set) {
return 'Set {' + Array.from(value).map(function (value) { return assert._formatValue(value, seen); }).join(', ') + '}' + (usage.used ? ' as #' + usage.id : '');
return `Set {${Array.from(value).map(value => assert._formatValue(value, seen)).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`;
}
if (typeof Map !== "undefined" && value instanceof Map) {
return 'Map {' + Array.from(value).map(function (pair) { return assert._formatValue(pair[0], seen) + ' => ' + assert._formatValue(pair[1], seen) + '}'; }).join(', ') + '}' + (usage.used ? ' as #' + usage.id : '');
return `Map {${Array.from(value).map(pair => `${assert._formatValue(pair[0], seen)} => ${assert._formatValue(pair[1], seen)}}`).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`;
}
if (Array.isArray ? Array.isArray(value) : value instanceof Array) {
return '[' + value.map(function (value) { return assert._formatValue(value, seen); }).join(', ') + ']' + (usage.used ? ' as #' + usage.id : '');
return `[${value.map(value => assert._formatValue(value, seen)).join(', ')}]${usage.used ? ` as #${usage.id}` : ''}`;
}
var tag = Symbol.toStringTag in value ? value[Symbol.toStringTag] : 'Object';
let tag = Symbol.toStringTag in value ? value[Symbol.toStringTag] : 'Object';
if (tag === 'Object' && Object.getPrototypeOf(value) === null) {
tag = '[Object: null prototype]';
}
return (tag ? tag + ' ' : '') + '{ ' + Object.keys(value).map(function (key) { return key.toString() + ': ' + assert._formatValue(value[key], seen); }).join(', ') + ' }' + (usage.used ? ' as #' + usage.id : '');
return `${tag ? `${tag} ` : ''}{ ${Object.keys(value).map(key => `${key.toString()}: ${assert._formatValue(value[key], seen)}`).join(', ')} }${usage.used ? ` as #${usage.id}` : ''}`;
default:
return typeof value;
}

View File

@ -6,7 +6,6 @@ description: |
---*/
// @ts-check
/// <reference path="./assert.js" />
function isSameValue(a, b) {
if (a === 0 && b === 0) return 1 / a === 1 / b;

View File

@ -6,7 +6,6 @@ description: |
---*/
// @ts-check
/// <reference path="./assert.js" />
var deepEqual = (function () {
/**

View File

@ -7,7 +7,6 @@ description: |
---*/
// @ts-check
/// <reference path="./assert.js" />
/**
* @param {object} obj

View File

@ -11,8 +11,6 @@ info: |
5. Return CreateArrayFromList(« _match_.[[StartIndex]], _match_.[[EndIndex]] »).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/compareArray.js" />
let input = "abcd";
let match = /b(c)/.exec(input);

View File

@ -22,8 +22,6 @@ info: |
...
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/compareArray.js" />
let input = "abcd";
let match = /b(c)/.exec(input);

View File

@ -27,10 +27,6 @@ info: |
34. Let _indicesArray_ be MakeIndicesArray( _S_, _indices_, _groupNames_).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/compareArray.js" />
/// <reference path="../../../../harness/propertyHelper.js" />
/// <reference path="../../../../harness/deepEqual.js" />
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./).indices);

View File

@ -12,8 +12,6 @@ info: |
d. Perform ! CreateDataProperty(_A_, ! ToString(_n_), _matchIndicesArray_).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/propertyHelper.js" />
let input = "abcd";
let match = /b(c)/.exec(input);

View File

@ -36,10 +36,6 @@ info: |
5. Return _eUTF_.
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/compareArray.js" />
/// <reference path="../../../../harness/propertyHelper.js" />
/// <reference path="../../../../harness/deepEqual.js" />
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/u).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./u).indices);

View File

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

View File

@ -21,7 +21,6 @@ info: |
...
---*/
/// <reference path="../../../../harness/assert.js" />
let input = "abd";
let match = /b(c)?/.exec(input);

View File

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

View File

@ -15,8 +15,6 @@ info: |
10. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/propertyHelper.js" />
const re = /./;
const indices = re.exec("a").indices;

View File

@ -13,8 +13,6 @@ info: |
i. Perform ! CreateDataProperty(_groups_, _groupNames_[_i_], _matchIndicesArray_).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/compareArray.js" />
const re = /(?<a>a).|(?<x>x)/;
const result = re.exec("ab").indices;

View File

@ -15,9 +15,6 @@ info: |
10. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/compareArray.js" />
/// <reference path="../../../../harness/propertyHelper.js" />
// `groups` is created with Define, not Set.
let counter = 0;

View File

@ -13,9 +13,6 @@ info: |
i. Perform ! CreateDataProperty(_groups_, _groupNames_[_i_], _matchIndicesArray_).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/compareArray.js" />
/// <reference path="../../../../harness/propertyHelper.js" />
// Properties created on result.groups in textual order.
let groupNames = Object.getOwnPropertyNames(/(?<fst>.)|(?<snd>.)/u.exec("abcd").indices.groups);

View File

@ -12,8 +12,6 @@ info: |
35. Perform ! DefinePropertyOrThrow(_A_, `"indices"`, PropertyDescriptor { [[Value]]: _indicesArray_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }).
---*/
/// <reference path="../../../../harness/assert.js" />
/// <reference path="../../../../harness/propertyHelper.js" />
// `indices` is created with Define, not Set.
let counter = 0;

View File

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

View File

@ -7,8 +7,6 @@ description: >
includes: [deepEqual.js]
---*/
/// <reference path="../../harness/assert.js" />
/// <reference path="../../harness/deepEqual.js" />
var a = { x: 1 };
var b = { x: 1 };

View File

@ -7,8 +7,6 @@ description: >
includes: [deepEqual.js]
---*/
/// <reference path="../../harness/assert.js" />
/// <reference path="../../harness/deepEqual.js" />
assert.deepEqual({ a: { x: 1 }, b: [true] }, { a: { x: 1 }, b: [true] });

View File

@ -7,8 +7,6 @@ description: >
includes: [deepEqual.js]
---*/
/// <reference path="../../harness/assert.js" />
/// <reference path="../../harness/deepEqual.js" />
assert.deepEqual(new Set(), new Set());
assert.deepEqual(new Set([1, "a", true]), new Set([1, "a", true]));

View File

@ -7,8 +7,6 @@ description: >
includes: [deepEqual.js]
---*/
/// <reference path="../../harness/assert.js" />
/// <reference path="../../harness/deepEqual.js" />
assert.deepEqual({}, {});
assert.deepEqual({ a: 1, b: true }, { a: 1, b: true });

View File

@ -7,8 +7,6 @@ description: >
includes: [deepEqual.js]
---*/
/// <reference path="../../harness/assert.js" />
/// <reference path="../../harness/deepEqual.js" />
var s1 = Symbol();
var s2 = Symbol();