diff options
author | 2020-11-16 00:10:28 +0100 | |
---|---|---|
committer | 2020-11-16 00:10:28 +0100 | |
commit | e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch) | |
tree | 55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/es-abstract/test/helpers | |
download | website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2 website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip |
api, login, auth
Diffstat (limited to 'node_modules/es-abstract/test/helpers')
7 files changed, 360 insertions, 0 deletions
diff --git a/node_modules/es-abstract/test/helpers/OwnPropertyKeys.js b/node_modules/es-abstract/test/helpers/OwnPropertyKeys.js new file mode 100644 index 0000000..9c2b4fc --- /dev/null +++ b/node_modules/es-abstract/test/helpers/OwnPropertyKeys.js @@ -0,0 +1,42 @@ +'use strict'; + +var test = require('tape'); +var hasSymbols = require('has-symbols')(); + +var OwnPropertyKeys = require('../../helpers/OwnPropertyKeys'); +var defineProperty = require('./defineProperty'); + +test('OwnPropertyKeys', function (t) { + t.deepEqual(OwnPropertyKeys({ a: 1, b: 2 }).sort(), ['a', 'b'].sort(), 'returns own string keys'); + + t.test('Symbols', { skip: !hasSymbols }, function (st) { + var o = { a: 1 }; + var sym = Symbol(); + o[sym] = 2; + + st.deepEqual(OwnPropertyKeys(o), ['a', sym], 'returns own string and symbol keys'); + + st.end(); + }); + + t.test('non-enumerables', { skip: !defineProperty.oDP }, function (st) { + var o = { a: 1, b: 42, c: NaN }; + defineProperty(o, 'b', { enumerable: false, value: 42 }); + defineProperty(o, 'c', { enumerable: false, get: function () { return NaN; } }); + + if (hasSymbols) { + defineProperty(o, 'd', { enumerable: false, value: true }); + defineProperty(o, 'e', { enumerable: false, get: function () { return true; } }); + } + + st.deepEqual( + OwnPropertyKeys(o).sort(), + (hasSymbols ? ['a', 'b', 'c', 'd', 'e'] : ['a', 'b', 'c']).sort(), + 'returns non-enumerable own keys, including accessors and symbols if available' + ); + + st.end(); + }); + + t.end(); +}); diff --git a/node_modules/es-abstract/test/helpers/assertRecord.js b/node_modules/es-abstract/test/helpers/assertRecord.js new file mode 100644 index 0000000..d6a80c2 --- /dev/null +++ b/node_modules/es-abstract/test/helpers/assertRecord.js @@ -0,0 +1,60 @@ +'use strict'; + +var forEach = require('foreach'); +var debug = require('object-inspect'); + +var assertRecord = require('../../helpers/assertRecord'); +var v = require('./values'); + +module.exports = function assertRecordTests(ES, test) { + test('Property Descriptor', function (t) { + var record = 'Property Descriptor'; + + forEach(v.nonUndefinedPrimitives, function (primitive) { + t['throws']( + function () { assertRecord(ES.Type, record, 'arg', primitive); }, + TypeError, + debug(primitive) + ' is not a Property Descriptor' + ); + }); + + t['throws']( + function () { assertRecord(ES.Type, record, 'arg', { invalid: true }); }, + TypeError, + 'invalid keys not allowed on a Property Descriptor' + ); + + t.doesNotThrow( + function () { assertRecord(ES.Type, record, 'arg', {}); }, + 'empty object is an incomplete Property Descriptor' + ); + + t.doesNotThrow( + function () { assertRecord(ES.Type, record, 'arg', v.accessorDescriptor()); }, + 'accessor descriptor is a Property Descriptor' + ); + + t.doesNotThrow( + function () { assertRecord(ES.Type, record, 'arg', v.mutatorDescriptor()); }, + 'mutator descriptor is a Property Descriptor' + ); + + t.doesNotThrow( + function () { assertRecord(ES.Type, record, 'arg', v.dataDescriptor()); }, + 'data descriptor is a Property Descriptor' + ); + + t.doesNotThrow( + function () { assertRecord(ES.Type, record, 'arg', v.genericDescriptor()); }, + 'generic descriptor is a Property Descriptor' + ); + + t['throws']( + function () { assertRecord(ES.Type, record, 'arg', v.bothDescriptor()); }, + TypeError, + 'a Property Descriptor can not be both a Data and an Accessor Descriptor' + ); + + t.end(); + }); +}; diff --git a/node_modules/es-abstract/test/helpers/createBoundESNamespace.js b/node_modules/es-abstract/test/helpers/createBoundESNamespace.js new file mode 100644 index 0000000..880ba3d --- /dev/null +++ b/node_modules/es-abstract/test/helpers/createBoundESNamespace.js @@ -0,0 +1,21 @@ +'use strict'; + +var bind = require('function-bind'); + +var OwnPropertyKeys = require('../../helpers/OwnPropertyKeys'); + +module.exports = function createBoundESNamespace(ES) { + var keys = OwnPropertyKeys(ES); + var result = {}; + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var prop = ES[key]; + if (typeof prop === 'function') { + prop = bind.call(prop, undefined); + } + result[key] = prop; + } + + return result; +}; diff --git a/node_modules/es-abstract/test/helpers/defineProperty.js b/node_modules/es-abstract/test/helpers/defineProperty.js new file mode 100644 index 0000000..8f925be --- /dev/null +++ b/node_modules/es-abstract/test/helpers/defineProperty.js @@ -0,0 +1,22 @@ +'use strict'; + +var oDP = Object.defineProperty; +try { + oDP({}, 'a', { value: 1 }); +} catch (e) { + // IE 8 + oDP = null; +} + +module.exports = function defineProperty(O, P, Desc) { + if (oDP) { + return oDP(O, P, Desc); + } + if ((Desc.enumerable && Desc.configurable && Desc.writable) || !(P in O)) { + O[P] = Desc.value; // eslint-disable-line no-param-reassign + return O; + } + + throw new SyntaxError('helper does not yet support this configuration'); +}; +module.exports.oDP = oDP; diff --git a/node_modules/es-abstract/test/helpers/getSymbolDescription.js b/node_modules/es-abstract/test/helpers/getSymbolDescription.js new file mode 100644 index 0000000..fbe7a7b --- /dev/null +++ b/node_modules/es-abstract/test/helpers/getSymbolDescription.js @@ -0,0 +1,67 @@ +'use strict'; + +var test = require('tape'); +var debug = require('object-inspect'); +var forEach = require('foreach'); +var has = require('has'); + +var v = require('./values'); +var getSymbolDescription = require('../../helpers/getSymbolDescription'); +var getInferredName = require('../../helpers/getInferredName'); + +test('getSymbolDescription', function (t) { + t.test('no symbols', { skip: v.hasSymbols }, function (st) { + st['throws']( + getSymbolDescription, + SyntaxError, + 'requires Symbol support' + ); + + st.end(); + }); + + forEach(v.nonSymbolPrimitives.concat(v.objects), function (nonSymbol) { + t['throws']( + function () { getSymbolDescription(nonSymbol); }, + v.hasSymbols ? TypeError : SyntaxError, + debug(nonSymbol) + ' is not a Symbol' + ); + }); + + t.test('with symbols', { skip: !v.hasSymbols }, function (st) { + forEach( + [ + [Symbol(), undefined], + [Symbol(undefined), undefined], + [Symbol(null), 'null'], + [Symbol.iterator, 'Symbol.iterator'], + [Symbol('foo'), 'foo'] + ], + function (pair) { + var sym = pair[0]; + var desc = pair[1]; + st.equal(getSymbolDescription(sym), desc, debug(sym) + ' description is ' + debug(desc)); + } + ); + + st.test('only possible when inference or native `Symbol.prototype.description` is supported', { + skip: !getInferredName && !has(Symbol.prototype, 'description') + }, function (s2t) { + s2t.equal(getSymbolDescription(Symbol('')), '', 'Symbol("") description is ""'); + + s2t.end(); + }); + + st.test('only possible when global symbols are supported', { + skip: !has(Symbol, 'for') || !has(Symbol, 'keyFor') + }, function (s2t) { + // eslint-disable-next-line no-restricted-properties + s2t.equal(getSymbolDescription(Symbol['for']('')), '', 'Symbol.for("") description is ""'); + s2t.end(); + }); + + st.end(); + }); + + t.end(); +}); diff --git a/node_modules/es-abstract/test/helpers/runManifestTest.js b/node_modules/es-abstract/test/helpers/runManifestTest.js new file mode 100644 index 0000000..2fdb4f2 --- /dev/null +++ b/node_modules/es-abstract/test/helpers/runManifestTest.js @@ -0,0 +1,27 @@ +'use strict'; + +var path = require('path'); +var fs = require('fs'); + +var forEach = require('foreach'); +var keys = require('object-keys'); + +module.exports = function runManifestTest(test, ES, edition) { + test('ES' + edition + ' manifest', { skip: !fs.readdirSync }, function (t) { + var files = fs.readdirSync(path.join(__dirname, '../../' + edition), 'utf-8'); + var map = { + AbstractEqualityComparison: 'Abstract Equality Comparison', + AbstractRelationalComparison: 'Abstract Relational Comparison', + StrictEqualityComparison: 'Strict Equality Comparison' + }; + forEach(files, function (file) { + var name = path.basename(file, path.extname(file)); + var actual = ES[map[name] || name]; + var expected = require(path.join(__dirname, '../../' + edition + '/', file)); // eslint-disable-line global-require + t.equal(actual, expected, 'ES["' + name + '"] === ' + file); + }); + var actualCount = keys(ES).length; + t.equal(actualCount, files.length, 'expected ' + files.length + ' files, got ' + actualCount); + t.end(); + }); +}; diff --git a/node_modules/es-abstract/test/helpers/values.js b/node_modules/es-abstract/test/helpers/values.js new file mode 100644 index 0000000..ccef743 --- /dev/null +++ b/node_modules/es-abstract/test/helpers/values.js @@ -0,0 +1,121 @@ +'use strict'; + +var assign = require('../../helpers/assign'); + +var hasSymbols = require('has-symbols')(); + +var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } }; +var coercibleFnObject = { + valueOf: function () { return function valueOfFn() {}; }, + toString: function () { return 42; } +}; +var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } }; +var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } }; +var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } }; +var uncoercibleFnObject = { + valueOf: function () { return function valueOfFn() {}; }, + toString: function () { return function toStrFn() {}; } +}; +var objects = [{}, coercibleObject, coercibleFnObject, toStringOnlyObject, valueOfOnlyObject]; +var nullPrimitives = [undefined, null]; +var nonIntegerNumbers = [-1.3, 0.2, 1.8, 1 / 3]; +var zeroes = [0, -0]; +var infinities = [Infinity, -Infinity]; +var numbers = zeroes.concat([42], infinities, nonIntegerNumbers); +var strings = ['', 'foo', 'a\uD83D\uDCA9c']; +var booleans = [true, false]; +var symbols = hasSymbols ? [Symbol.iterator, Symbol('foo')] : []; +var nonSymbolPrimitives = [].concat(nullPrimitives, booleans, strings, numbers); +var nonNumberPrimitives = [].concat(nullPrimitives, booleans, strings, symbols); +var nonNullPrimitives = [].concat(booleans, strings, numbers, symbols); +var nonUndefinedPrimitives = [].concat(null, nonNullPrimitives); +var nonStrings = [].concat(nullPrimitives, booleans, numbers, symbols, objects); +var primitives = [].concat(nullPrimitives, nonNullPrimitives); +var nonPropertyKeys = [].concat(nullPrimitives, booleans, numbers, objects); +var propertyKeys = [].concat(strings, symbols); +var nonBooleans = [].concat(nullPrimitives, strings, symbols, numbers, objects); +var falsies = [].concat(nullPrimitives, false, '', 0, -0, NaN); +var truthies = [].concat(true, 'foo', 42, symbols, objects); +var timestamps = [].concat(0, 946713600000, 1546329600000); +var nonFunctions = [].concat(primitives, objects, [42]); +var nonArrays = [].concat(nonFunctions); + +var descriptors = { + configurable: function (descriptor) { + return assign(assign({}, descriptor), { '[[Configurable]]': true }); + }, + nonConfigurable: function (descriptor) { + return assign(assign({}, descriptor), { '[[Configurable]]': false }); + }, + enumerable: function (descriptor) { + return assign(assign({}, descriptor), { '[[Enumerable]]': true }); + }, + nonEnumerable: function (descriptor) { + return assign(assign({}, descriptor), { '[[Enumerable]]': false }); + }, + writable: function (descriptor) { + return assign(assign({}, descriptor), { '[[Writable]]': true }); + }, + nonWritable: function (descriptor) { + return assign(assign({}, descriptor), { '[[Writable]]': false }); + } +}; + +module.exports = { + coercibleObject: coercibleObject, + coercibleFnObject: coercibleFnObject, + valueOfOnlyObject: valueOfOnlyObject, + toStringOnlyObject: toStringOnlyObject, + uncoercibleObject: uncoercibleObject, + uncoercibleFnObject: uncoercibleFnObject, + objects: objects, + nonFunctions: nonFunctions, + nonArrays: nonArrays, + nullPrimitives: nullPrimitives, + numbers: numbers, + zeroes: zeroes, + infinities: infinities, + strings: strings, + booleans: booleans, + symbols: symbols, + hasSymbols: hasSymbols, + nonSymbolPrimitives: nonSymbolPrimitives, + nonNumberPrimitives: nonNumberPrimitives, + nonNullPrimitives: nonNullPrimitives, + nonUndefinedPrimitives: nonUndefinedPrimitives, + nonStrings: nonStrings, + nonNumbers: nonNumberPrimitives.concat(objects), + nonIntegerNumbers: nonIntegerNumbers, + primitives: primitives, + nonPropertyKeys: nonPropertyKeys, + propertyKeys: propertyKeys, + nonBooleans: nonBooleans, + falsies: falsies, + truthies: truthies, + timestamps: timestamps, + bothDescriptor: function () { + return { '[[Get]]': function () {}, '[[Value]]': true }; + }, + bothDescriptorWritable: function () { + return descriptors.writable({ '[[Get]]': function () {} }); + }, + accessorDescriptor: function (value) { + return descriptors.enumerable(descriptors.configurable({ + '[[Get]]': function get() { return value; } + })); + }, + mutatorDescriptor: function () { + return descriptors.enumerable(descriptors.configurable({ + '[[Set]]': function () {} + })); + }, + dataDescriptor: function (value) { + return descriptors.nonWritable({ + '[[Value]]': arguments.length > 0 ? value : 42 + }); + }, + genericDescriptor: function () { + return descriptors.configurable(descriptors.nonEnumerable()); + }, + descriptors: descriptors +}; |