Template Upload

This commit is contained in:
SOUTHERNCO\x2mjbyrn
2017-05-17 13:45:25 -04:00
parent 415b9c25f3
commit 7efe7605b8
11476 changed files with 2170865 additions and 34 deletions

19
node_modules/es6-shim/test/.eslintrc generated vendored Normal file
View File

@ -0,0 +1,19 @@
{
"rules": {
"array-callback-return": 0,
"func-name-matching": 0,
"max-statements-per-line": [2, { "max": 2 }],
"no-restricted-properties": 1,
"symbol-description": 0,
"prefer-promise-reject-errors": 0,
},
"env": {
"mocha": true
},
"globals": {
"Symbol": false,
"Promise": false,
"expect": false,
"assert": false
}
}

1037
node_modules/es6-shim/test/array.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

45
node_modules/es6-shim/test/browser-onload.js generated vendored Normal file
View File

@ -0,0 +1,45 @@
/* global window, mocha */
if (typeof window !== 'undefined') {
window.completedTests = 0;
window.sawFail = false;
window.onload = function () {
window.testsPassed = null;
var handleResults = function (runner) {
var failedTests = [];
if (runner.stats.end) {
window.testsPassed = runner.stats.failures === 0;
}
runner.on('pass', function () {
window.completedTests += 1;
});
runner.on('fail', function (test, err) {
window.sawFail = true;
var flattenTitles = function (testToFlatten) {
var titles = [];
var currentTest = testToFlatten;
while (currentTest.parent.title) {
titles.push(currentTest.parent.title);
currentTest = currentTest.parent;
}
return titles.reverse();
};
failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
});
});
runner.on('end', function () {
window.testsPassed = !window.sawFail;
// for sauce
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});
return runner;
};
handleResults(mocha.run());
};
}

11
node_modules/es6-shim/test/browser-setup.js generated vendored Normal file
View File

@ -0,0 +1,11 @@
/* global window, chai, mocha */
if (typeof window !== 'undefined') {
chai.config.includeStack = true;
window.expect = chai.expect;
window.assert = chai.assert;
mocha.setup('bdd');
window.require = function () {
return window;
};
}

5
node_modules/es6-shim/test/date.js generated vendored Normal file
View File

@ -0,0 +1,5 @@
describe('Date', function () {
it('when invalid, dates should toString to "Invalid Date"', function () {
expect(String(new Date(NaN))).to.equal('Invalid Date');
});
});

42
node_modules/es6-shim/test/index.html generated vendored Normal file
View File

@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>es6-shim tests</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="../node_modules/es5-shim/es5-shim.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../es6-shim.js"></script>
<script src="browser-setup.js"></script>
<script src="array.js"></script>
<script src="map.js"></script>
<script src="set.js"></script>
<script src="json.js"></script>
<script src="math.js"></script>
<script src="number.js"></script>
<script src="object.js"></script>
<script src="promise.js"></script>
<script src="regexp.js"></script>
<script src="string.js"></script>
<script src="reflect.js"></script>
<script src="worker-test.js"></script>
<script src="promise/all.js"></script>
<script src="promise/evil-promises.js"></script>
<!--
<script src="promise/promises-aplus.js"></script>
-->
<script src="../node_modules/promises-es6-tests/bundle/promises-es6-tests.js"></script>
<script src="promise/race.js"></script>
<script src="promise/reject.js"></script>
<script src="promise/resolve.js"></script>
<script src="promise/simple.js"></script>
<script src="promise/subclass.js"></script>
<script src="browser-onload.js"></script>
</head>
<body>
<div id="mocha"></div>
</body>
</html>

77
node_modules/es6-shim/test/json.js generated vendored Normal file
View File

@ -0,0 +1,77 @@
describe('JSON', function () {
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol';
var ifSymbolsIt = hasSymbols ? it : xit;
var ifSymbolsDescribe = hasSymbols ? describe : xit;
describe('.stringify()', function () {
ifFunctionsHaveNamesIt('has the right name', function () {
expect(JSON.stringify.name).to.equal('stringify');
});
ifSymbolsIt('serializes a Symbol to undefined', function () {
expect(JSON.stringify(Symbol())).to.equal(undefined);
});
ifSymbolsIt('serializes a Symbol object to {}', function () {
expect(function stringifyObjectSymbol() { JSON.stringify(Object(Symbol())); }).not.to['throw']();
expect(JSON.stringify(Object(Symbol()))).to.equal('{}');
});
ifSymbolsIt('serializes Symbols in an Array to null', function () {
expect(JSON.stringify([Symbol('foo')])).to.equal('[null]');
});
ifSymbolsIt('serializes Symbol objects in an Array to {}', function () {
expect(function stringifyObjectSymbolInArray() { JSON.stringify([Object(Symbol('foo'))]); }).not.to['throw']();
expect(JSON.stringify([Object(Symbol('foo'))])).to.equal('[{}]');
});
ifSymbolsDescribe('skips symbol properties and values in an object', function () {
var enumSym = Symbol('enumerable');
var nonenum = Symbol('non-enumerable');
var createObject = function () {
var obj = { a: 1 };
obj[enumSym] = true;
obj.sym = enumSym;
Object.defineProperty(obj, nonenum, { enumerable: false, value: true });
expect(Object.getOwnPropertySymbols(obj)).to.eql([enumSym, nonenum]);
return obj;
};
it('works with no replacer', function () {
var obj = createObject();
expect(JSON.stringify(obj)).to.equal('{"a":1}');
expect(JSON.stringify(obj, null, '|')).to.equal('{\n|"a": 1\n}');
});
it('works with a replacer function', function () {
var tuples = [];
var replacer = function (key, value) {
tuples.push([this, key, value]);
return value;
};
var obj = createObject();
expect(JSON.stringify(obj, replacer, '|')).to.equal('{\n|"a": 1\n}'); // populate `tuples` array
expect(tuples).to.eql([
[{ '': obj }, '', obj],
[obj, 'a', 1],
[obj, 'sym', enumSym]
]);
});
it('works with a replacer array', function () {
var obj = createObject();
obj.foo = 'bar';
obj[Symbol.prototype.toString.call(enumSym)] = 'tricksy';
expect(JSON.stringify(obj, ['a', enumSym])).to.equal('{"a":1}');
expect(JSON.stringify(obj, ['a', enumSym], '|')).to.equal('{\n|"a": 1\n}');
});
it('ignores a non-array non-callable replacer object', function () {
expect(JSON.stringify('z', { test: null })).to.equal('"z"');
});
});
});
});

603
node_modules/es6-shim/test/map.js generated vendored Normal file
View File

@ -0,0 +1,603 @@
// Big thanks to V8 folks for test ideas.
// v8/test/mjsunit/harmony/collections.js
var Assertion = expect().constructor;
Assertion.addMethod('theSameSet', function (otherArray) {
var array = this._obj;
expect(Array.isArray(array)).to.equal(true);
expect(Array.isArray(otherArray)).to.equal(true);
var diff = array.filter(function (value) {
return otherArray.every(function (otherValue) {
var areBothNaN = typeof value === 'number' && typeof otherValue === 'number' && value !== value && otherValue !== otherValue;
return !areBothNaN && value !== otherValue;
});
});
this.assert(
diff.length === 0,
'expected #{this} to be equal to #{exp} (as sets, i.e. no order)',
array,
otherArray
);
});
Assertion.addMethod('entries', function (expected) {
var collection = this._obj;
expect(Array.isArray(expected)).to.equal(true);
var expectedEntries = expected.slice();
var iterator = collection.entries();
var result;
do {
result = iterator.next();
expect(result.value).to.be.eql(expectedEntries.shift());
} while (!result.done);
});
describe('Map', function () {
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
var range = function range(from, to) {
var result = [];
for (var value = from; value < to; value++) {
result.push(value);
}
return result;
};
var prototypePropIsEnumerable = Object.prototype.propertyIsEnumerable.call(function () {}, 'prototype');
var expectNotEnumerable = function (object) {
if (prototypePropIsEnumerable && typeof object === 'function') {
expect(Object.keys(object)).to.eql(['prototype']);
} else {
expect(Object.keys(object)).to.eql([]);
}
};
var Sym = typeof Symbol === 'undefined' ? {} : Symbol;
var isSymbol = function (sym) {
return typeof Sym === 'function' && typeof sym === 'symbol';
};
var ifSymbolIteratorIt = isSymbol(Sym.iterator) ? it : xit;
var testMapping = function (map, key, value) {
expect(map.has(key)).to.equal(false);
expect(map.get(key)).to.equal(undefined);
expect(map.set(key, value)).to.equal(map);
expect(map.get(key)).to.equal(value);
expect(map.has(key)).to.equal(true);
};
if (typeof Map === 'undefined') {
return it('exists', function () {
expect(typeof Map).to.equal('function');
});
}
var map;
beforeEach(function () {
map = new Map();
});
afterEach(function () {
map = null;
});
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.Map).to.equal(Map);
});
it('should exist in global namespace', function () {
expect(typeof Map).to.equal('function');
});
it('should have the right arity', function () {
expect(Map).to.have.property('length', 0);
});
it('should has valid getter and setter calls', function () {
['get', 'set', 'has', 'delete'].forEach(function (method) {
expect(function () {
map[method]({});
}).to.not['throw']();
});
});
it('should accept an iterable as argument', function () {
testMapping(map, 'a', 'b');
testMapping(map, 'c', 'd');
var map2;
expect(function () { map2 = new Map(map); }).not.to['throw'](Error);
expect(map2).to.be.an.instanceOf(Map);
expect(map2.has('a')).to.equal(true);
expect(map2.has('c')).to.equal(true);
expect(map2).to.have.entries([['a', 'b'], ['c', 'd']]);
});
it('should throw with iterables that return primitives', function () {
expect(function () { return new Map('123'); }).to['throw'](TypeError);
expect(function () { return new Map([1, 2, 3]); }).to['throw'](TypeError);
expect(function () { return new Map(['1', '2', '3']); }).to['throw'](TypeError);
expect(function () { return new Map([true]); }).to['throw'](TypeError);
});
it('should not be callable without "new"', function () {
expect(Map).to['throw'](TypeError);
});
it('should be subclassable', function () {
if (!Object.setPrototypeOf) { return; } // skip test if on IE < 11
var MyMap = function MyMap() {
var testMap = new Map([['a', 'b']]);
Object.setPrototypeOf(testMap, MyMap.prototype);
return testMap;
};
Object.setPrototypeOf(MyMap, Map);
MyMap.prototype = Object.create(Map.prototype, {
constructor: { value: MyMap }
});
var myMap = new MyMap();
testMapping(myMap, 'c', 'd');
expect(myMap).to.have.entries([['a', 'b'], ['c', 'd']]);
});
it('uses SameValueZero even on a Map of size > 4', function () {
// Chrome 38-42, node 0.11/0.12, iojs 1/2 have a bug when the Map has a size > 4
var firstFour = [[1, 0], [2, 0], [3, 0], [4, 0]];
var fourMap = new Map(firstFour);
expect(fourMap.size).to.equal(4);
expect(fourMap.has(-0)).to.equal(false);
expect(fourMap.has(0)).to.equal(false);
fourMap.set(-0, fourMap);
expect(fourMap.has(0)).to.equal(true);
expect(fourMap.has(-0)).to.equal(true);
});
it('treats positive and negative zero the same', function () {
var value1 = {};
var value2 = {};
testMapping(map, +0, value1);
expect(map.has(-0)).to.equal(true);
expect(map.get(-0)).to.equal(value1);
expect(map.set(-0, value2)).to.equal(map);
expect(map.get(-0)).to.equal(value2);
expect(map.get(+0)).to.equal(value2);
});
it('should map values correctly', function () {
// Run this test twice, one with the "fast" implementation (which only
// allows string and numeric keys) and once with the "slow" impl.
[true, false].forEach(function (slowkeys) {
map = new Map();
range(1, 20).forEach(function (number) {
if (slowkeys) { testMapping(map, number, {}); }
testMapping(map, number / 100, {});
testMapping(map, 'key-' + number, {});
testMapping(map, String(number), {});
if (slowkeys) { testMapping(map, Object(String(number)), {}); }
});
var testkeys = [Infinity, -Infinity, NaN];
if (slowkeys) {
testkeys.push(true, false, null, undefined);
}
testkeys.forEach(function (key) {
testMapping(map, key, {});
testMapping(map, String(key), {});
});
testMapping(map, '', {});
// verify that properties of Object don't peek through.
[
'hasOwnProperty',
'constructor',
'toString',
'isPrototypeOf',
'__proto__',
'__parent__',
'__count__'
].forEach(function (key) {
testMapping(map, key, {});
});
});
});
it('should map empty values correctly', function () {
testMapping(map, {}, true);
testMapping(map, null, true);
testMapping(map, undefined, true);
testMapping(map, '', true);
testMapping(map, NaN, true);
testMapping(map, 0, true);
});
it('should has correct querying behavior', function () {
var key = {};
testMapping(map, key, 'to-be-present');
expect(map.has(key)).to.equal(true);
expect(map.has({})).to.equal(false);
expect(map.set(key, void 0)).to.equal(map);
expect(map.get(key)).to.equal(undefined);
expect(map.has(key)).to.equal(true);
expect(map.has({})).to.equal(false);
});
it('should allow NaN values as keys', function () {
expect(map.has(NaN)).to.equal(false);
expect(map.has(NaN + 1)).to.equal(false);
expect(map.has(23)).to.equal(false);
expect(map.set(NaN, 'value')).to.equal(map);
expect(map.has(NaN)).to.equal(true);
expect(map.has(NaN + 1)).to.equal(true);
expect(map.has(23)).to.equal(false);
});
it('should not have [[Enumerable]] props', function () {
expectNotEnumerable(Map);
expectNotEnumerable(Map.prototype);
expectNotEnumerable(new Map());
});
it('should not have an own constructor', function () {
var m = new Map();
expect(m).not.to.haveOwnPropertyDescriptor('constructor');
expect(m.constructor).to.equal(Map);
});
it('should allow common ecmascript idioms', function () {
expect(map).to.be.an.instanceOf(Map);
expect(typeof Map.prototype.get).to.equal('function');
expect(typeof Map.prototype.set).to.equal('function');
expect(typeof Map.prototype.has).to.equal('function');
expect(typeof Map.prototype['delete']).to.equal('function');
});
it('should have a unique constructor', function () {
expect(Map.prototype).to.not.equal(Object.prototype);
});
describe('#clear()', function () {
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Map.prototype.clear).to.have.property('name', 'clear');
});
it('is not enumerable', function () {
expect(Map.prototype).ownPropertyDescriptor('clear').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Map.prototype.clear).to.have.property('length', 0);
});
it('should have #clear method', function () {
expect(map.set(1, 2)).to.equal(map);
expect(map.set(5, 2)).to.equal(map);
expect(map.size).to.equal(2);
expect(map.has(5)).to.equal(true);
map.clear();
expect(map.size).to.equal(0);
expect(map.has(5)).to.equal(false);
});
});
describe('#keys()', function () {
if (!Object.prototype.hasOwnProperty.call(Map.prototype, 'keys')) {
return it('exists', function () {
expect(Map.prototype).to.have.property('keys');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Map.prototype.keys).to.have.property('name', 'keys');
});
it('is not enumerable', function () {
expect(Map.prototype).ownPropertyDescriptor('keys').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Map.prototype.keys).to.have.property('length', 0);
});
});
describe('#values()', function () {
if (!Object.prototype.hasOwnProperty.call(Map.prototype, 'values')) {
return it('exists', function () {
expect(Map.prototype).to.have.property('values');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Map.prototype.values).to.have.property('name', 'values');
});
it('is not enumerable', function () {
expect(Map.prototype).ownPropertyDescriptor('values').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Map.prototype.values).to.have.property('length', 0);
});
});
describe('#entries()', function () {
if (!Object.prototype.hasOwnProperty.call(Map.prototype, 'entries')) {
return it('exists', function () {
expect(Map.prototype).to.have.property('entries');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Map.prototype.entries).to.have.property('name', 'entries');
});
it('is not enumerable', function () {
expect(Map.prototype).ownPropertyDescriptor('entries').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Map.prototype.entries).to.have.property('length', 0);
});
it('throws when called on a non-Map', function () {
var expectedMessage = /^(Method )?Map.prototype.entries called on incompatible receiver |^entries method called on incompatible |^Cannot create a Map entry iterator for a non-Map object.|^Map\.prototype\.entries: 'this' is not a Map object$|^std_Map_iterator method called on incompatible \w+$/;
var nonMaps = [true, false, 'abc', NaN, new Set([1, 2]), { a: true }, [1], Object('abc'), Object(NaN)];
nonMaps.forEach(function (nonMap) {
expect(function () { return Map.prototype.entries.call(nonMap); }).to['throw'](TypeError, expectedMessage);
});
});
});
describe('#size', function () {
it('throws TypeError when accessed directly', function () {
// see https://github.com/paulmillr/es6-shim/issues/176
expect(function () { return Map.prototype.size; }).to['throw'](TypeError);
expect(function () { return Map.prototype.size; }).to['throw'](TypeError);
});
it('is an accessor function on the prototype', function () {
expect(Map.prototype).ownPropertyDescriptor('size').to.have.property('get');
expect(typeof Object.getOwnPropertyDescriptor(Map.prototype, 'size').get).to.equal('function');
expect(new Map()).not.to.haveOwnPropertyDescriptor('size');
});
});
it('should return false when deleting a nonexistent key', function () {
expect(map.has('a')).to.equal(false);
expect(map['delete']('a')).to.equal(false);
});
it('should have keys, values and size props', function () {
expect(map.set('a', 1)).to.equal(map);
expect(map.set('b', 2)).to.equal(map);
expect(map.set('c', 3)).to.equal(map);
expect(typeof map.keys).to.equal('function');
expect(typeof map.values).to.equal('function');
expect(map.size).to.equal(3);
expect(map['delete']('a')).to.equal(true);
expect(map.size).to.equal(2);
});
it('should have an iterator that works with Array.from', function () {
expect(Array).to.have.property('from');
expect(map.set('a', 1)).to.equal(map);
expect(map.set('b', NaN)).to.equal(map);
expect(map.set('c', false)).to.equal(map);
expect(Array.from(map)).to.eql([['a', 1], ['b', NaN], ['c', false]]);
expect(Array.from(map.keys())).to.eql(['a', 'b', 'c']);
expect(Array.from(map.values())).to.eql([1, NaN, false]);
expect(map).to.have.entries(Array.from(map.entries()));
});
ifSymbolIteratorIt('has the right default iteration function', function () {
// fixed in Webkit https://bugs.webkit.org/show_bug.cgi?id=143838
expect(Map.prototype).to.have.property(Sym.iterator, Map.prototype.entries);
});
describe('#forEach', function () {
var mapToIterate;
beforeEach(function () {
mapToIterate = new Map();
expect(mapToIterate.set('a', 1)).to.equal(mapToIterate);
expect(mapToIterate.set('b', 2)).to.equal(mapToIterate);
expect(mapToIterate.set('c', 3)).to.equal(mapToIterate);
});
afterEach(function () {
mapToIterate = null;
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Map.prototype.forEach).to.have.property('name', 'forEach');
});
it('is not enumerable', function () {
expect(Map.prototype).ownPropertyDescriptor('forEach').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Map.prototype.forEach).to.have.property('length', 1);
});
it('should be iterable via forEach', function () {
var expectedMap = {
a: 1,
b: 2,
c: 3
};
var foundMap = {};
mapToIterate.forEach(function (value, key, entireMap) {
expect(entireMap).to.equal(mapToIterate);
foundMap[key] = value;
});
expect(foundMap).to.eql(expectedMap);
});
it('should iterate over empty keys', function () {
var mapWithEmptyKeys = new Map();
var expectedKeys = [{}, null, undefined, '', NaN, 0];
expectedKeys.forEach(function (key) {
expect(mapWithEmptyKeys.set(key, true)).to.equal(mapWithEmptyKeys);
});
var foundKeys = [];
mapWithEmptyKeys.forEach(function (value, key, entireMap) {
expect(entireMap.get(key)).to.equal(value);
foundKeys.push(key);
});
expect(foundKeys).to.be.theSameSet(expectedKeys);
});
it('should support the thisArg', function () {
var context = function () {};
mapToIterate.forEach(function () {
expect(this).to.equal(context);
}, context);
});
it('should have a length of 1', function () {
expect(Map.prototype.forEach.length).to.equal(1);
});
it('should not revisit modified keys', function () {
var hasModifiedA = false;
mapToIterate.forEach(function (value, key) {
if (!hasModifiedA && key === 'a') {
expect(mapToIterate.set('a', 4)).to.equal(mapToIterate);
hasModifiedA = true;
} else {
expect(key).not.to.equal('a');
}
});
});
it('returns the map from #set() for chaining', function () {
expect(mapToIterate.set({}, {})).to.equal(mapToIterate);
expect(mapToIterate.set(42, {})).to.equal(mapToIterate);
expect(mapToIterate.set(0, {})).to.equal(mapToIterate);
expect(mapToIterate.set(NaN, {})).to.equal(mapToIterate);
expect(mapToIterate.set(-0, {})).to.equal(mapToIterate);
});
it('visits keys added in the iterator', function () {
var hasAdded = false;
var hasFoundD = false;
mapToIterate.forEach(function (value, key) {
if (!hasAdded) {
mapToIterate.set('d', 5);
hasAdded = true;
} else if (key === 'd') {
hasFoundD = true;
}
});
expect(hasFoundD).to.equal(true);
});
it('visits keys added in the iterator when there is a deletion', function () {
var hasSeenFour = false;
var mapToMutate = new Map();
mapToMutate.set('0', 42);
mapToMutate.forEach(function (value, key) {
if (key === '0') {
expect(mapToMutate['delete']('0')).to.equal(true);
mapToMutate.set('4', 'a value');
} else if (key === '4') {
hasSeenFour = true;
}
});
expect(hasSeenFour).to.equal(true);
});
it('does not visit keys deleted before a visit', function () {
var hasVisitedC = false;
var hasDeletedC = false;
mapToIterate.forEach(function (value, key) {
if (key === 'c') {
hasVisitedC = true;
}
if (!hasVisitedC && !hasDeletedC) {
hasDeletedC = mapToIterate['delete']('c');
expect(hasDeletedC).to.equal(true);
}
});
expect(hasVisitedC).to.equal(false);
});
it('should work after deletion of the current key', function () {
var expectedMap = {
a: 1,
b: 2,
c: 3
};
var foundMap = {};
mapToIterate.forEach(function (value, key) {
foundMap[key] = value;
expect(mapToIterate['delete'](key)).to.equal(true);
});
expect(foundMap).to.eql(expectedMap);
});
it('should convert key -0 to +0', function () {
var zeroMap = new Map();
var result = [];
zeroMap.set(-0, 'a');
zeroMap.forEach(function (value, key) {
result.push(String(1 / key) + ' ' + value);
});
zeroMap.set(1, 'b');
zeroMap.set(0, 'c'); // shouldn't cause reordering
zeroMap.forEach(function (value, key) {
result.push(String(1 / key) + ' ' + value);
});
expect(result.join(', ')).to.equal(
'Infinity a, Infinity c, 1 b'
);
});
});
it('should preserve insertion order', function () {
var convertToPairs = function (item) { return [item, true]; };
var arr1 = ['d', 'a', 'b'];
var arr2 = [3, 2, 'z', 'a', 1];
var arr3 = [3, 2, 'z', {}, 'a', 1];
[arr1, arr2, arr3].forEach(function (array) {
var entries = array.map(convertToPairs);
expect(new Map(entries)).to.have.entries(entries);
});
});
it('map iteration', function () {
var map = new Map();
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
map.set('d', 4);
var keys = [];
var iterator = map.keys();
keys.push(iterator.next().value);
expect(map['delete']('a')).to.equal(true);
expect(map['delete']('b')).to.equal(true);
expect(map['delete']('c')).to.equal(true);
map.set('e');
keys.push(iterator.next().value);
keys.push(iterator.next().value);
expect(iterator.next().done).to.equal(true);
map.set('f');
expect(iterator.next().done).to.equal(true);
expect(keys).to.eql(['a', 'd', 'e']);
});
});

848
node_modules/es6-shim/test/math.js generated vendored Normal file
View File

@ -0,0 +1,848 @@
var Assertion = expect().constructor;
Assertion.prototype.almostEqual = function (obj, precision) {
'use strict';
var allowedDiff = precision || 1e-11;
return this.within(obj - allowedDiff, obj + allowedDiff);
};
describe('Math', function () {
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
var isPositiveZero = function (zero) {
'use strict';
return zero === 0 && 1 / zero === Infinity;
};
var isNegativeZero = function (zero) {
'use strict';
return zero === 0 && 1 / zero === -Infinity;
};
var numberIsNaN = Number.isNaN || function (value) {
return value !== value;
};
var valueOfIsNaN = { valueOf: function () { return NaN; } };
var valueOfIsInfinity = { valueOf: function () { return Infinity; } };
var EPSILON = Number.EPSILON || 2.2204460492503130808472633361816e-16;
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.Math).to.equal(Math);
});
describe('.acosh()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'acosh')) {
return it('exists', function () {
expect(Math).to.have.property('acosh');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.acosh).to.have.property('name', 'acosh');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('acosh').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.acosh).to.have.property('length', 1);
});
it('should be correct', function () {
expect(numberIsNaN(Math.acosh(NaN))).to.equal(true);
expect(numberIsNaN(Math.acosh(0))).to.equal(true);
expect(numberIsNaN(Math.acosh(0.9999999))).to.equal(true);
expect(numberIsNaN(Math.acosh(-1e300))).to.equal(true);
expect(Math.acosh(1e+99)).to.almostEqual(228.64907138697046);
expect(isPositiveZero(Math.acosh(1))).to.equal(true);
expect(Math.acosh(Infinity)).to.equal(Infinity);
expect(Math.acosh(1234)).to.almostEqual(7.811163220849231);
expect(Math.acosh(8.88)).to.almostEqual(2.8737631531629235);
expect(Math.acosh(1e160)).to.almostEqual(369.10676205960726);
expect(Math.acosh(Number.MAX_VALUE)).to.almostEqual(710.4758600739439);
});
});
describe('.asinh()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'asinh')) {
return it('exists', function () {
expect(Math).to.have.property('asinh');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.asinh).to.have.property('name', 'asinh');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('asinh').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.asinh).to.have.property('length', 1);
});
it('should be correct for NaN', function () {
expect(numberIsNaN(Math.asinh(NaN))).to.equal(true);
});
it('should be correct for zeroes', function () {
expect(isPositiveZero(Math.asinh(+0))).to.equal(true);
expect(isNegativeZero(Math.asinh(-0))).to.equal(true);
});
it('should be correct for Infinities', function () {
expect(Math.asinh(Infinity)).to.equal(Infinity);
expect(Math.asinh(-Infinity)).to.equal(-Infinity);
});
it('should be correct', function () {
expect(Math.asinh(1234)).to.almostEqual(7.811163549201245);
expect(Math.asinh(9.99)).to.almostEqual(2.997227420191335);
expect(Math.asinh(1e150)).to.almostEqual(346.0809111296668);
expect(Math.asinh(1e7)).to.almostEqual(16.811242831518268);
expect(Math.asinh(-1e7)).to.almostEqual(-16.811242831518268);
});
});
describe('.atanh()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'atanh')) {
return it('exists', function () {
expect(Math).to.have.property('atanh');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.atanh).to.have.property('name', 'atanh');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('atanh').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.atanh).to.have.property('length', 1);
});
it('should be correct', function () {
expect(numberIsNaN(Math.atanh(NaN))).to.equal(true);
expect(numberIsNaN(Math.atanh(-1.00000001))).to.equal(true);
expect(numberIsNaN(Math.atanh(1.00000001))).to.equal(true);
expect(numberIsNaN(Math.atanh(-1e300))).to.equal(true);
expect(numberIsNaN(Math.atanh(1e300))).to.equal(true);
expect(Math.atanh(-1)).to.equal(-Infinity);
expect(Math.atanh(1)).to.equal(Infinity);
expect(isPositiveZero(Math.atanh(+0))).to.equal(true);
expect(isNegativeZero(Math.atanh(-0))).to.equal(true);
expect(Math.atanh(0.5)).to.almostEqual(0.5493061443340549);
expect(Math.atanh(-0.5)).to.almostEqual(-0.5493061443340549);
expect(Math.atanh(-0.5)).to.almostEqual(-0.5493061443340549);
expect(Math.atanh(0.444)).to.almostEqual(0.47720201260109457);
});
});
describe('.cbrt()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'cbrt')) {
return it('exists', function () {
expect(Math).to.have.property('cbrt');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.cbrt).to.have.property('name', 'cbrt');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('cbrt').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.cbrt).to.have.property('length', 1);
});
it('should be correct', function () {
expect(isNaN(Math.cbrt(NaN))).to.equal(true);
expect(isPositiveZero(Math.cbrt(+0))).to.equal(true);
expect(isNegativeZero(Math.cbrt(-0))).to.equal(true);
expect(Math.cbrt(Infinity)).to.equal(Infinity);
expect(Math.cbrt(-Infinity)).to.equal(-Infinity);
expect(Math.cbrt(-8)).to.almostEqual(-2);
expect(Math.cbrt(8)).to.almostEqual(2);
expect(Math.cbrt(-1000)).to.almostEqual(-10);
expect(Math.cbrt(1000)).to.almostEqual(10);
expect(Math.cbrt(-1e-300)).to.almostEqual(-1e-100);
expect(Math.cbrt(1e-300)).to.almostEqual(1e-100);
expect(Math.cbrt(-1e+300)).to.almostEqual(-1e+100);
expect(Math.cbrt(1e+300)).to.almostEqual(1e+100);
});
});
describe('.clz32()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'clz32')) {
return it('exists', function () {
expect(Math).to.have.property('clz32');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.clz32).to.have.property('name', 'clz32');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('clz32').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.clz32).to.have.property('length', 1);
});
it('should have proper uint32 conversion', function () {
var integers = [5295, -5295, -9007199254740991, 9007199254740991, 0, -0];
var nonNumbers = [undefined, true, null, {}, [], 'str'];
var nonIntegers = [-9007199254741992, 9007199254741992, 5.9];
integers.forEach(function (item) {
expect(Math.clz32(item)).to.be.within(0, 32);
});
nonIntegers.forEach(function (item) {
expect(Math.clz32(item)).to.be.within(0, 32);
});
nonNumbers.forEach(function (item) {
expect(Math.clz32(item)).to.equal(item === true ? 31 : 32);
});
expect(Math.clz32(true)).to.equal(Math.clz32(1));
expect(Math.clz32('')).to.equal(Math.clz32(0));
expect(Math.clz32('10')).to.equal(Math.clz32(10));
expect(Math.clz32(0.1)).to.equal(32);
expect(Math.clz32(-1)).to.equal(0);
expect(Math.clz32(1)).to.equal(31);
expect(Math.clz32(0xFFFFFFFF)).to.equal(0);
expect(Math.clz32(0x1FFFFFFFF)).to.equal(0);
expect(Math.clz32(0x111111111)).to.equal(3);
expect(Math.clz32(0x11111111)).to.equal(3);
});
it('returns 32 for numbers that coerce to 0', function () {
var zeroishes = [
0,
-0,
NaN,
Infinity,
-Infinity,
0x100000000,
undefined,
null,
false,
'',
'str',
{},
[],
[1, 2]
];
zeroishes.forEach(function (zeroish) {
expect(Math.clz32(zeroish)).to.equal(32);
});
});
});
describe('.cosh()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'cosh')) {
return it('exists', function () {
expect(Math).to.have.property('cosh');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.cosh).to.have.property('name', 'cosh');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('cosh').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.cosh).to.have.property('length', 1);
});
it('should be correct for NaN', function () {
expect(numberIsNaN(Math.cosh(NaN))).to.equal(true);
});
it('should be correct for Infinities', function () {
expect(Math.cosh(Infinity)).to.equal(Infinity);
expect(Math.cosh(-Infinity)).to.equal(Infinity);
});
it('should be correct for zeroes', function () {
expect(Math.cosh(-0)).to.equal(1);
expect(Math.cosh(+0)).to.equal(1);
});
it('should be correct', function () {
// Overridden precision values here are for Chrome, as of v25.0.1364.172
// Broadened slightly for Firefox 31
expect(Math.cosh(12)).to.almostEqual(81377.39571257407, 9e-11);
expect(Math.cosh(22)).to.almostEqual(1792456423.065795780980053377, 1e-5);
expect(Math.cosh(-10)).to.almostEqual(11013.23292010332313972137);
expect(Math.cosh(-23)).to.almostEqual(4872401723.1244513000, 1e-5);
expect(Math.cosh(-2e-17)).to.equal(1);
});
});
describe('.expm1()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'expm1')) {
return it('exists', function () {
expect(Math).to.have.property('expm1');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.expm1).to.have.property('name', 'expm1');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('expm1').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.expm1).to.have.property('length', 1);
});
it('should be correct for NaN', function () {
expect(numberIsNaN(Math.expm1(NaN))).to.equal(true);
});
it('should be correct for zeroes', function () {
expect(isPositiveZero(Math.expm1(+0))).to.equal(true);
expect(isNegativeZero(Math.expm1(-0))).to.equal(true);
});
it('should be correct for Infinity', function () {
expect(Math.expm1(Infinity)).to.equal(Infinity);
expect(Math.expm1(-Infinity)).to.equal(-1);
});
it('should be correct for arbitrary numbers', function () {
expect(Math.expm1(10)).to.almostEqual(22025.465794806716516957900645284244366353512618556781);
expect(Math.expm1(-10)).to.almostEqual(-0.99995460007023751514846440848443944938976208191113);
expect(Math.expm1(-2e-17)).to.almostEqual(-2e-17);
});
it('works with very negative numbers', function () {
expect(Math.expm1(-38)).to.almostEqual(-1);
expect(Math.expm1(-8675309)).to.almostEqual(-1);
expect(Math.expm1(-4815162342)).to.almostEqual(-1);
});
});
describe('.hypot()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'hypot')) {
return it('exists', function () {
expect(Math).to.have.property('hypot');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.hypot).to.have.property('name', 'hypot');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('hypot').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.hypot).to.have.property('length', 2);
});
it('should be correct', function () {
expect(Math.hypot(Infinity)).to.equal(Infinity);
expect(Math.hypot(-Infinity)).to.equal(Infinity);
expect(Math.hypot(Infinity, NaN)).to.equal(Infinity);
expect(Math.hypot(NaN, Infinity)).to.equal(Infinity);
expect(Math.hypot(-Infinity, 'Hello')).to.equal(Infinity);
expect(Math.hypot(1, 2, Infinity)).to.equal(Infinity);
expect(numberIsNaN(Math.hypot(NaN, 1))).to.equal(true);
expect(isPositiveZero(Math.hypot())).to.equal(true);
expect(isPositiveZero(Math.hypot(0, 0, 0))).to.equal(true);
expect(isPositiveZero(Math.hypot(0, -0, 0))).to.equal(true);
expect(isPositiveZero(Math.hypot(-0, -0, -0))).to.equal(true);
expect(Math.hypot(66, 66)).to.almostEqual(93.33809511662427);
expect(Math.hypot(0.1, 100)).to.almostEqual(100.0000499999875);
});
it('should coerce to a number', function () {
expect(Math.hypot('Infinity', 0)).to.equal(Infinity);
expect(Math.hypot('3', '3', '3', '3')).to.equal(6);
});
it('should take more than 3 arguments', function () {
expect(Math.hypot(66, 66, 66)).to.almostEqual(114.3153532995459);
expect(Math.hypot(66, 66, 66, 66)).to.equal(132);
});
it('should have the right length', function () {
expect(Math.hypot.length).to.equal(2);
});
it('works for very large or small numbers', function () {
expect(Math.hypot(1e+300, 1e+300)).to.almostEqual(1.4142135623730952e+300);
expect(Math.hypot(1e-300, 1e-300)).to.almostEqual(1.4142135623730952e-300);
expect(Math.hypot(1e+300, 1e+300, 2, 3)).to.almostEqual(1.4142135623730952e+300);
});
});
describe('.log2()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'log2')) {
return it('exists', function () {
expect(Math).to.have.property('log2');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.log2).to.have.property('name', 'log2');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('log2').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.log2).to.have.property('length', 1);
});
it('is correct for small numbers', function () {
expect(numberIsNaN(Math.log2(-1e-50))).to.equal(true);
});
it('is correct for edge cases', function () {
expect(numberIsNaN(Math.log2(NaN))).to.equal(true);
expect(Math.log2(+0)).to.equal(-Infinity);
expect(Math.log2(-0)).to.equal(-Infinity);
expect(isPositiveZero(Math.log2(1))).to.equal(true);
expect(Math.log2(Infinity)).to.equal(Infinity);
});
it('should have the right precision', function () {
expect(Math.log2(5)).to.almostEqual(2.321928094887362);
expect(Math.log2(32)).to.almostEqual(5);
});
});
describe('.log10', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'log10')) {
return it('exists', function () {
expect(Math).to.have.property('log10');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.log10).to.have.property('name', 'log10');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('log10').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.log10).to.have.property('length', 1);
});
it('should be correct for edge cases', function () {
expect(numberIsNaN(Math.log10(NaN))).to.equal(true);
expect(numberIsNaN(Math.log10(-1e-50))).to.equal(true);
expect(Math.log10(+0)).to.equal(-Infinity);
expect(Math.log10(-0)).to.equal(-Infinity);
expect(isPositiveZero(Math.log10(1))).to.equal(true);
expect(Math.log10(Infinity)).to.equal(Infinity);
});
it('should have the right precision', function () {
expect(Math.log10(5)).to.almostEqual(0.698970004336018);
expect(Math.log10(50)).to.almostEqual(1.6989700043360187);
});
});
describe('.log1p', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'log1p')) {
return it('exists', function () {
expect(Math).to.have.property('log1p');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.log1p).to.have.property('name', 'log1p');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('log1p').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.log1p).to.have.property('length', 1);
});
it('should be correct', function () {
expect(numberIsNaN(Math.log1p(NaN))).to.equal(true);
expect(numberIsNaN(Math.log1p(-1.000000001))).to.equal(true);
expect(Math.log1p(-1)).to.equal(-Infinity);
expect(isPositiveZero(Math.log1p(+0))).to.equal(true);
expect(isNegativeZero(Math.log1p(-0))).to.equal(true);
expect(Math.log1p(Infinity)).to.equal(Infinity);
expect(Math.log1p(5)).to.almostEqual(1.791759469228055);
expect(Math.log1p(50)).to.almostEqual(3.9318256327243257);
expect(Math.log1p(-1e-17)).to.equal(-1e-17);
expect(Math.log1p(-2e-17)).to.equal(-2e-17);
});
});
describe('.sign()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'sign')) {
return it('exists', function () {
expect(Math).to.have.property('sign');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.sign).to.have.property('name', 'sign');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('sign').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.sign).to.have.property('length', 1);
});
it('should be correct', function () {
// we also verify that [[ToNumber]] is being called
[Infinity, 1].forEach(function (value) {
expect(Math.sign(value)).to.equal(1);
expect(Math.sign(String(value))).to.equal(1);
});
expect(Math.sign(true)).to.equal(1);
[-Infinity, -1].forEach(function (value) {
expect(Math.sign(value)).to.equal(-1);
expect(Math.sign(String(value))).to.equal(-1);
});
expect(isPositiveZero(Math.sign(+0))).to.equal(true);
expect(isPositiveZero(Math.sign('0'))).to.equal(true);
expect(isPositiveZero(Math.sign('+0'))).to.equal(true);
expect(isPositiveZero(Math.sign(''))).to.equal(true);
expect(isPositiveZero(Math.sign(' '))).to.equal(true);
expect(isPositiveZero(Math.sign(null))).to.equal(true);
expect(isPositiveZero(Math.sign(false))).to.equal(true);
expect(isNegativeZero(Math.sign(-0))).to.equal(true);
expect(isNegativeZero(Math.sign('-0'))).to.equal(true);
expect(numberIsNaN(Math.sign(NaN))).to.equal(true);
expect(numberIsNaN(Math.sign('NaN'))).to.equal(true);
expect(numberIsNaN(Math.sign(undefined))).to.equal(true);
});
});
describe('.sinh()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'sinh')) {
return it('exists', function () {
expect(Math).to.have.property('sinh');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.sinh).to.have.property('name', 'sinh');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('sinh').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.sinh).to.have.property('length', 1);
});
it('should be correct', function () {
expect(numberIsNaN(Math.sinh(NaN))).to.equal(true);
expect(isPositiveZero(Math.sinh(+0))).to.equal(true);
expect(isNegativeZero(Math.sinh(-0))).to.equal(true);
expect(Math.sinh(Infinity)).to.equal(Infinity);
expect(Math.sinh(-Infinity)).to.equal(-Infinity);
expect(Math.sinh(-5)).to.almostEqual(-74.20321057778875);
expect(Math.sinh(2)).to.almostEqual(3.6268604078470186);
expect(Math.sinh(-2e-17)).to.equal(-2e-17);
});
});
describe('.tanh()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'tanh')) {
return it('exists', function () {
expect(Math).to.have.property('tanh');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.tanh).to.have.property('name', 'tanh');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('tanh').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.tanh).to.have.property('length', 1);
});
it('should be correct', function () {
expect(numberIsNaN(Math.tanh(NaN))).to.equal(true);
expect(isPositiveZero(Math.tanh(+0))).to.equal(true);
expect(isNegativeZero(Math.tanh(-0))).to.equal(true);
expect(Math.tanh(Infinity)).to.equal(1);
expect(Math.tanh(-Infinity)).to.equal(-1);
expect(Math.tanh(19)).to.almostEqual(1);
expect(Math.tanh(-19)).to.almostEqual(-1);
expect(Math.tanh(20)).to.equal(1); // JS loses precision for true value at this integer
expect(Math.tanh(-20)).to.equal(-1); // JS loses precision for true value at this integer
expect(Math.tanh(10)).to.almostEqual(0.9999999958776927);
expect(Math.tanh(-2e-17)).to.equal(-2e-17);
});
});
describe('.trunc()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'trunc')) {
return it('exists', function () {
expect(Math).to.have.property('trunc');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.trunc).to.have.property('name', 'trunc');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('trunc').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.trunc).to.have.property('length', 1);
});
it('should be correct', function () {
expect(numberIsNaN(Math.trunc(NaN))).to.equal(true);
expect(isNegativeZero(Math.trunc(-0))).to.equal(true);
expect(isPositiveZero(Math.trunc(+0))).to.equal(true);
expect(Math.trunc(Infinity)).to.equal(Infinity);
expect(Math.trunc(-Infinity)).to.equal(-Infinity);
expect(Math.trunc(1.01)).to.equal(1);
expect(Math.trunc(1.99)).to.equal(1);
expect(Math.trunc(-555.555)).to.equal(-555);
expect(Math.trunc(-1.99)).to.equal(-1);
});
it('should coerce to a number immediately', function () {
expect(Math.trunc(valueOfIsInfinity)).to.equal(Infinity);
expect(numberIsNaN(Math.trunc(valueOfIsNaN))).to.equal(true);
});
});
describe('.imul()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'imul')) {
return it('exists', function () {
expect(Math).to.have.property('imul');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.imul).to.have.property('name', 'imul');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('imul').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.imul).to.have.property('length', 2);
});
var str = 'str';
var obj = {};
var arr = [];
it('should be correct for non-numbers', function () {
expect(Math.imul(false, 7)).to.equal(0);
expect(Math.imul(7, false)).to.equal(0);
expect(Math.imul(false, false)).to.equal(0);
expect(Math.imul(true, 7)).to.equal(7);
expect(Math.imul(7, true)).to.equal(7);
expect(Math.imul(true, true)).to.equal(1);
expect(Math.imul(undefined, 7)).to.equal(0);
expect(Math.imul(7, undefined)).to.equal(0);
expect(Math.imul(undefined, undefined)).to.equal(0);
expect(Math.imul(str, 7)).to.equal(0);
expect(Math.imul(7, str)).to.equal(0);
expect(Math.imul(obj, 7)).to.equal(0);
expect(Math.imul(7, obj)).to.equal(0);
expect(Math.imul(arr, 7)).to.equal(0);
expect(Math.imul(7, arr)).to.equal(0);
});
it('should be correct for hex values', function () {
expect(Math.imul(0xffffffff, 5)).to.equal(-5);
expect(Math.imul(0xfffffffe, 5)).to.equal(-10);
});
it('should be correct', function () {
expect(Math.imul(2, 4)).to.equal(8);
expect(Math.imul(-1, 8)).to.equal(-8);
expect(Math.imul(-2, -2)).to.equal(4);
expect(Math.imul(-0, 7)).to.equal(0);
expect(Math.imul(7, -0)).to.equal(0);
expect(Math.imul(0.1, 7)).to.equal(0);
expect(Math.imul(7, 0.1)).to.equal(0);
expect(Math.imul(0.9, 7)).to.equal(0);
expect(Math.imul(7, 0.9)).to.equal(0);
expect(Math.imul(1.1, 7)).to.equal(7);
expect(Math.imul(7, 1.1)).to.equal(7);
expect(Math.imul(1.9, 7)).to.equal(7);
expect(Math.imul(7, 1.9)).to.equal(7);
});
it('should be correct for objects with valueOf', function () {
var x = {
x: 0,
valueOf: function () { this.x += 1; return this.x; }
};
expect(Math.imul(x, 1)).to.equal(1);
expect(Math.imul(1, x)).to.equal(2);
expect(Math.imul(x, 1)).to.equal(3);
expect(Math.imul(1, x)).to.equal(4);
expect(Math.imul(x, 1)).to.equal(5);
});
});
describe('.round()', function () {
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.round).to.have.property('name', 'round');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('round').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.round).to.have.property('length', 1);
});
it('works for edge cases', function () {
expect(numberIsNaN(Math.round(NaN))).to.equal(true);
expect(isPositiveZero(Math.round(0))).to.equal(true);
expect(isNegativeZero(Math.round(-0))).to.equal(true);
expect(Math.round(Infinity)).to.equal(Infinity);
expect(Math.round(-Infinity)).to.equal(-Infinity);
});
it('returns 0 for (0,0.5)', function () {
expect(Math.round(0.5)).not.to.equal(0);
expect(Math.round(0.5 - (EPSILON / 4))).to.equal(0);
expect(Math.round(0 + (EPSILON / 4))).to.equal(0);
});
it('returns -0 for (-0.5,0)', function () {
expect(Math.round(-0.5)).to.equal(0);
expect(Math.round(-0.5 - (EPSILON / 3.99))).not.to.equal(0);
expect(isNegativeZero(Math.round(-0.5 + (EPSILON / 3.99)))).to.equal(true);
expect(isNegativeZero(Math.round(0 - (EPSILON / 3.99)))).to.equal(true);
});
it('returns 1 / Number.EPSILON + 1 for 1 / Number.EPSILON + 1', function () {
var inverseEpsilonPlus1 = (1 / EPSILON) + 1;
expect(Math.round(inverseEpsilonPlus1)).to.equal(inverseEpsilonPlus1);
});
it('returns 2 / Number.EPSILON - 1 for 2 / Number.EPSILON - 1', function () {
var twiceInverseEpsilonMinus1 = (2 / EPSILON) - 1;
expect(Math.round(twiceInverseEpsilonMinus1)).to.equal(twiceInverseEpsilonMinus1);
});
});
describe('.fround()', function () {
if (!Object.prototype.hasOwnProperty.call(Math, 'fround')) {
return it('exists', function () {
expect(Math).to.have.property('fround');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Math.fround).to.have.property('name', 'fround');
});
it('is not enumerable', function () {
expect(Math).ownPropertyDescriptor('fround').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Math.fround).to.have.property('length', 1);
});
// Mozilla's reference tests: https://bug900125.bugzilla.mozilla.org/attachment.cgi?id=793163
it('returns NaN for undefined', function () {
expect(numberIsNaN(Math.fround())).to.equal(true);
});
it('returns NaN for NaN', function () {
expect(numberIsNaN(Math.fround(NaN))).to.equal(true);
});
it('works for zeroes and infinities', function () {
expect(isPositiveZero(Math.fround(0))).to.equal(true);
expect(isPositiveZero(Math.fround({ valueOf: function () { return 0; } }))).to.equal(true);
expect(isNegativeZero(Math.fround(-0))).to.equal(true);
expect(isNegativeZero(Math.fround({ valueOf: function () { return -0; } }))).to.equal(true);
expect(Math.fround(Infinity)).to.equal(Infinity);
expect(Math.fround({ valueOf: function () { return Infinity; } })).to.equal(Infinity);
expect(Math.fround(-Infinity)).to.equal(-Infinity);
expect(Math.fround({ valueOf: function () { return -Infinity; } })).to.equal(-Infinity);
});
it('returns infinity for large numbers', function () {
expect(Math.fround(1.7976931348623157e+308)).to.equal(Infinity);
expect(Math.fround(-1.7976931348623157e+308)).to.equal(-Infinity);
expect(Math.fround(3.4028235677973366e+38)).to.equal(Infinity);
});
it('returns zero for really small numbers', function () {
expect(Number.MIN_VALUE).to.equal(5e-324);
expect(Math.fround(Number.MIN_VALUE)).to.equal(0);
expect(Math.fround(-Number.MIN_VALUE)).to.equal(0);
});
it('rounds properly', function () {
expect(Math.fround(3)).to.equal(3);
expect(Math.fround(-3)).to.equal(-3);
});
it('rounds properly with the max float 32', function () {
var maxFloat32 = 3.4028234663852886e+38;
expect(Math.fround(maxFloat32)).to.equal(maxFloat32);
expect(Math.fround(-maxFloat32)).to.equal(-maxFloat32);
// round-nearest rounds down to maxFloat32
expect(Math.fround(maxFloat32 + Math.pow(2, Math.pow(2, 8 - 1) - 1 - 23 - 2))).to.equal(maxFloat32);
});
it('rounds properly with the min float 32', function () {
var minFloat32 = 1.401298464324817e-45;
expect(Math.fround(minFloat32)).to.equal(minFloat32);
expect(Math.fround(-minFloat32)).to.equal(-minFloat32);
expect(Math.fround(minFloat32 / 2)).to.equal(0);
expect(Math.fround(-minFloat32 / 2)).to.equal(0);
expect(Math.fround((minFloat32 / 2) + Math.pow(2, -202))).to.equal(minFloat32);
expect(Math.fround((-minFloat32 / 2) - Math.pow(2, -202))).to.equal(-minFloat32);
});
});
});

2
node_modules/es6-shim/test/mocha.opts generated vendored Normal file
View File

@ -0,0 +1,2 @@
--require test/test_helpers.js

39
node_modules/es6-shim/test/native.html generated vendored Normal file
View File

@ -0,0 +1,39 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>es6-shim tests</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="browser-setup.js"></script>
<script src="array.js"></script>
<script src="map.js"></script>
<script src="set.js"></script>
<script src="json.js"></script>
<script src="math.js"></script>
<script src="number.js"></script>
<script src="object.js"></script>
<script src="promise.js"></script>
<script src="regexp.js"></script>
<script src="string.js"></script>
<script src="reflect.js"></script>
<script src="worker-test.js"></script>
<script src="promise/all.js"></script>
<script src="promise/evil-promises.js"></script>
<!--
<script src="promise/promises-aplus.js"></script>
-->
<script src="promise/race.js"></script>
<script src="promise/reject.js"></script>
<script src="promise/resolve.js"></script>
<script src="promise/simple.js"></script>
<script src="promise/subclass.js"></script>
<script src="browser-onload.js"></script>
</head>
<body>
<div id="mocha"></div>
</body>
</html>

481
node_modules/es6-shim/test/number.js generated vendored Normal file
View File

@ -0,0 +1,481 @@
describe('Number', function () {
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
var integers = [5295, -5295, -9007199254740991, 9007199254740991, 0, -0];
var nonIntegers = [-9007199254741992, 9007199254741992, 5.9];
var infinities = [Infinity, -Infinity];
var valueOfThree = { valueOf: function () { return 3; } };
var valueOfNaN = { valueOf: function () { return NaN; } };
var valueOfThrows = { valueOf: function () { throw Object(17); } };
var toStringThrows = { toString: function () { throw Object(42); } };
var toPrimitiveThrows = {
valueOf: function () { throw Object(17); },
toString: function () { throw Object(42); }
};
var nonNumbers = [
undefined,
true,
false,
null,
{},
[],
'str',
'',
valueOfThree,
valueOfNaN,
valueOfThrows,
toStringThrows,
toPrimitiveThrows,
/a/g
];
var expectTrue = function (item) {
expect(item).to.equal(true);
};
var expectFalse = function (item) {
expect(item).to.equal(false);
};
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.Number).to.equal(Number);
});
describe('Number constants', function () {
it('should have max safe integer', function () {
expect(Number).to.have.property('MAX_SAFE_INTEGER');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'MAX_SAFE_INTEGER')).to.equal(false);
expect(Number.MAX_SAFE_INTEGER).to.equal(Math.pow(2, 53) - 1);
});
it('should have min safe integer', function () {
expect(Number).to.have.property('MIN_SAFE_INTEGER');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'MIN_SAFE_INTEGER')).to.equal(false);
expect(Number.MIN_SAFE_INTEGER).to.equal(-Math.pow(2, 53) + 1);
});
it('should have epsilon', function () {
expect(Number).to.have.property('EPSILON');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'EPSILON')).to.equal(false);
expect(Number.EPSILON).to.equal(2.2204460492503130808472633361816e-16);
});
it('should have NaN', function () {
expect(Number).to.have.property('NaN');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'NaN')).to.equal(false);
expect(isNaN(Number.NaN)).to.equal(true);
});
it('should have MAX_VALUE', function () {
expect(Number).to.have.property('MAX_VALUE');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'MAX_VALUE')).to.equal(false);
expect(Number.MAX_VALUE).to.equal(1.7976931348623157e+308);
});
it('should have MIN_VALUE', function () {
expect(Number).to.have.property('MIN_VALUE');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'MIN_VALUE')).to.equal(false);
expect(Number.MIN_VALUE).to.equal(5e-324);
});
it('should have NEGATIVE_INFINITY', function () {
expect(Number).to.have.property('NEGATIVE_INFINITY');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'NEGATIVE_INFINITY')).to.equal(false);
expect(Number.NEGATIVE_INFINITY).to.equal(-Infinity);
});
it('should have POSITIVE_INFINITY', function () {
expect(Number).to.have.property('POSITIVE_INFINITY');
expect(Object.prototype.propertyIsEnumerable.call(Number, 'POSITIVE_INFINITY')).to.equal(false);
expect(Number.POSITIVE_INFINITY).to.equal(Infinity);
});
});
describe('.parseInt()', function () {
if (!Object.prototype.hasOwnProperty.call(Number, 'parseInt')) {
return it('exists', function () {
expect(Number).to.have.property('parseInt');
});
}
it('should work', function () {
/* eslint-disable radix */
expect(Number.parseInt('601')).to.equal(601);
/* eslint-enable radix */
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Number.parseInt).to.have.property('name', 'parseInt');
});
it('is not enumerable', function () {
expect(Number).ownPropertyDescriptor('parseInt').to.have.property('enumerable', false);
});
it('has the right arity', function () {
// WebKit nightly had the wrong length; fixed in https://bugs.webkit.org/show_bug.cgi?id=143657
expect(Number.parseInt).to.have.property('length', 2);
});
it('is the same object as the global parseInt', function () {
// fixed in WebKit nightly in https://bugs.webkit.org/show_bug.cgi?id=143799#add_comment
expect(Number.parseInt).to.equal(parseInt);
});
});
describe('.parseFloat()', function () {
if (!Object.prototype.hasOwnProperty.call(Number, 'parseFloat')) {
return it('exists', function () {
expect(Number).to.have.property('parseFloat');
});
}
it('should work', function () {
expect(Number.parseFloat('5.5')).to.equal(5.5);
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Number.parseFloat).to.have.property('name', 'parseFloat');
});
it('is not enumerable', function () {
expect(Number).ownPropertyDescriptor('parseFloat').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Number.parseFloat).to.have.property('length', 1);
});
});
describe('.isFinite()', function () {
if (!Object.prototype.hasOwnProperty.call(Number, 'isFinite')) {
return it('exists', function () {
expect(Number).to.have.property('isFinite');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Number.isFinite).to.have.property('name', 'isFinite');
});
it('is not enumerable', function () {
expect(Number).ownPropertyDescriptor('isFinite').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Number.isFinite).to.have.property('length', 1);
});
it('should work', function () {
integers.map(Number.isFinite).forEach(expectTrue);
infinities.map(Number.isFinite).forEach(expectFalse);
expect(Number.isFinite(Infinity)).to.equal(false);
expect(Number.isFinite(-Infinity)).to.equal(false);
expect(Number.isFinite(NaN)).to.equal(false);
expect(Number.isFinite(4)).to.equal(true);
expect(Number.isFinite(4.5)).to.equal(true);
expect(Number.isFinite('hi')).to.equal(false);
expect(Number.isFinite('1.3')).to.equal(false);
expect(Number.isFinite('51')).to.equal(false);
expect(Number.isFinite(0)).to.equal(true);
expect(Number.isFinite(-0)).to.equal(true);
expect(Number.isFinite(valueOfThree)).to.equal(false);
expect(Number.isFinite(valueOfNaN)).to.equal(false);
expect(Number.isFinite(valueOfThrows)).to.equal(false);
expect(Number.isFinite(toStringThrows)).to.equal(false);
expect(Number.isFinite(toPrimitiveThrows)).to.equal(false);
});
it('should not be confused by type coercion', function () {
nonNumbers.map(Number.isFinite).forEach(expectFalse);
});
});
describe('.isInteger()', function () {
if (!Object.prototype.hasOwnProperty.call(Number, 'isInteger')) {
return it('exists', function () {
expect(Number).to.have.property('isInteger');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Number.isInteger).to.have.property('name', 'isInteger');
});
it('is not enumerable', function () {
expect(Number).ownPropertyDescriptor('isInteger').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Number.isInteger).to.have.property('length', 1);
});
it('should be truthy on integers', function () {
integers.map(Number.isInteger).forEach(expectTrue);
expect(Number.isInteger(4)).to.equal(true);
expect(Number.isInteger(4.0)).to.equal(true);
expect(Number.isInteger(1801439850948)).to.equal(true);
});
it('should be false when the type is not number', function () {
nonNumbers.forEach(function (thing) {
expect(Number.isInteger(thing)).to.equal(false);
});
});
it('should be false when NaN', function () {
expect(Number.isInteger(NaN)).to.equal(false);
});
it('should be false when ∞', function () {
expect(Number.isInteger(Infinity)).to.equal(false);
expect(Number.isInteger(-Infinity)).to.equal(false);
});
it('should be false when number is not integer', function () {
expect(Number.isInteger(3.4)).to.equal(false);
expect(Number.isInteger(-3.4)).to.equal(false);
});
it('should be true when abs(number) is 2^53 or larger', function () {
expect(Number.isInteger(Math.pow(2, 53))).to.equal(true);
expect(Number.isInteger(Math.pow(2, 54))).to.equal(true);
expect(Number.isInteger(-Math.pow(2, 53))).to.equal(true);
expect(Number.isInteger(-Math.pow(2, 54))).to.equal(true);
});
it('should be true when abs(number) is less than 2^53', function () {
var safeIntegers = [0, 1, Math.pow(2, 53) - 1];
safeIntegers.forEach(function (integer) {
expect(Number.isInteger(integer)).to.equal(true);
expect(Number.isInteger(-integer)).to.equal(true);
});
});
});
describe('.isSafeInteger()', function () {
if (!Object.prototype.hasOwnProperty.call(Number, 'isSafeInteger')) {
return it('exists', function () {
expect(Number).to.have.property('isSafeInteger');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Number.isSafeInteger).to.have.property('name', 'isSafeInteger');
});
it('is not enumerable', function () {
expect(Number).ownPropertyDescriptor('isSafeInteger').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Number.isSafeInteger).to.have.property('length', 1);
});
it('should be truthy on integers', function () {
integers.map(Number.isSafeInteger).forEach(expectTrue);
expect(Number.isSafeInteger(4)).to.equal(true);
expect(Number.isSafeInteger(4.0)).to.equal(true);
expect(Number.isSafeInteger(1801439850948)).to.equal(true);
});
it('should be false when the type is not number', function () {
nonNumbers.forEach(function (thing) {
expect(Number.isSafeInteger(thing)).to.equal(false);
});
});
it('should be false when NaN', function () {
expect(Number.isSafeInteger(NaN)).to.equal(false);
});
it('should be false when ∞', function () {
expect(Number.isSafeInteger(Infinity)).to.equal(false);
expect(Number.isSafeInteger(-Infinity)).to.equal(false);
});
it('should be false when number is not integer', function () {
expect(Number.isSafeInteger(3.4)).to.equal(false);
expect(Number.isSafeInteger(-3.4)).to.equal(false);
});
it('should be false when abs(number) is 2^53 or larger', function () {
expect(Number.isSafeInteger(Math.pow(2, 53))).to.equal(false);
expect(Number.isSafeInteger(Math.pow(2, 54))).to.equal(false);
expect(Number.isSafeInteger(-Math.pow(2, 53))).to.equal(false);
expect(Number.isSafeInteger(-Math.pow(2, 54))).to.equal(false);
});
it('should be true when abs(number) is less than 2^53', function () {
var safeIntegers = [0, 1, Math.pow(2, 53) - 1];
safeIntegers.forEach(function (integer) {
expect(Number.isSafeInteger(integer)).to.equal(true);
expect(Number.isSafeInteger(-integer)).to.equal(true);
});
});
});
describe('.isNaN()', function () {
if (!Object.prototype.hasOwnProperty.call(Number, 'isNaN')) {
return it('exists', function () {
expect(Number).to.have.property('isNaN');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Number.isNaN).to.have.property('name', 'isNaN');
});
it('is not enumerable', function () {
expect(Number).ownPropertyDescriptor('isNaN').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Number.isNaN).to.have.property('length', 1);
});
it('should be truthy only on NaN', function () {
integers.concat(nonIntegers).map(Number.isNaN).forEach(expectFalse);
nonNumbers.map(Number.isNaN).forEach(expectFalse);
expect(Number.isNaN(NaN)).to.equal(true);
expect(Number.isNaN(0 / 0)).to.equal(true);
expect(Number.isNaN(Number('NaN'))).to.equal(true);
expect(Number.isNaN(4)).to.equal(false);
expect(Number.isNaN(4.5)).to.equal(false);
expect(Number.isNaN('hi')).to.equal(false);
expect(Number.isNaN('1.3')).to.equal(false);
expect(Number.isNaN('51')).to.equal(false);
expect(Number.isNaN(0)).to.equal(false);
expect(Number.isNaN(-0)).to.equal(false);
expect(Number.isNaN(valueOfThree)).to.equal(false);
expect(Number.isNaN(valueOfNaN)).to.equal(false);
expect(Number.isNaN(valueOfThrows)).to.equal(false);
expect(Number.isNaN(toStringThrows)).to.equal(false);
expect(Number.isNaN(toPrimitiveThrows)).to.equal(false);
});
});
describe('constructor', function () {
it('behaves like the builtin', function () {
expect((1).constructor).to.equal(Number);
expect(Number()).to.equal(0);
});
describe('strings in the constructor', function () {
it('works on normal literals', function () {
expect(Number('1')).to.equal(+'1');
expect(Number('1.1')).to.equal(+'1.1');
expect(Number('0xA')).to.equal(0xA);
});
});
describe('when called with a receiver', function () {
it('returns a primitive when called with a primitive receiver', function () {
expect((1).constructor(2)).to.equal(2);
expect((1).constructor.call(null, 3)).to.equal(3);
expect(Object(1).constructor.call(null, 5)).to.equal(5);
});
it('returns a primitive when called with a different number as an object receiver', function () {
expect(Object(1).constructor(6)).to.equal(6);
expect(Object(1).constructor.call(Object(1), 7)).to.equal(7);
});
it('returns a primitive when called with the same number as an object receiver', function () {
expect(Object(1).constructor.call(Object(8), 8)).to.equal(8);
});
});
it('works with boxed primitives', function () {
expect(1 instanceof Number).to.equal(false);
expect(Object(1) instanceof Number).to.equal(true);
});
it('works with `new`', function () {
/* jshint -W053 */
/* eslint-disable no-new-wrappers */
var one = new Number('1');
var a = new Number('0xA');
/* eslint-enable no-new-wrappers */
/* jshint +W053 */
expect(+one).to.equal(1);
expect(one instanceof Number).to.equal(true);
expect(+a).to.equal(0xA);
expect(a instanceof Number).to.equal(true);
});
it('works with binary literals in string form', function () {
expect(Number('0b1')).to.equal(1);
expect(Number(' 0b1')).to.equal(1);
expect(Number('0b1 ')).to.equal(1);
expect(Number('0b10')).to.equal(2);
expect(Number(' 0b10')).to.equal(2);
expect(Number('0b10 ')).to.equal(2);
expect(Number('0b11')).to.equal(3);
expect(Number(' 0b11')).to.equal(3);
expect(Number('0b11 ')).to.equal(3);
expect(Number({
toString: function () { return '0b100'; },
valueOf: function () { return '0b101'; }
})).to.equal(5);
});
it('works with octal literals in string form', function () {
expect(Number('0o7')).to.equal(7);
expect(Number('0o10')).to.equal(8);
expect(Number('0o11')).to.equal(9);
expect(Number({
toString: function () { return '0o12'; },
valueOf: function () { return '0o13'; }
})).to.equal(11);
});
it('should produce NaN', function () {
expect(String(Number('0b12'))).to.equal('NaN');
expect(String(Number('0o18'))).to.equal('NaN');
expect(String(Number('0x1g'))).to.equal('NaN');
expect(String(Number('+0b1'))).to.equal('NaN');
expect(String(Number('+0o1'))).to.equal('NaN');
expect(String(Number('+0x1'))).to.equal('NaN');
expect(String(Number('-0b1'))).to.equal('NaN');
expect(String(Number('-0o1'))).to.equal('NaN');
expect(String(Number('-0x1'))).to.equal('NaN');
});
it('should work with well formed and poorly formed objects', function () {
expect(String(Number({}))).to.equal('NaN');
expect(String(Number({ valueOf: '1.1' }))).to.equal('NaN');
expect(Number({ valueOf: '1.1', toString: function () { return '2.2'; } })).to.equal(2.2);
expect(Number({ valueOf: function () { return '1.1'; }, toString: '2.2' })).to.equal(1.1);
expect(Number({
valueOf: function () { return '1.1'; },
toString: function () { return '2.2'; }
})).to.equal(1.1);
expect(String(Number({ valueOf: function () { return '-0x1a2b3c'; } }))).to.equal('NaN');
expect(String(Number({ toString: function () { return '-0x1a2b3c'; } }))).to.equal('NaN');
expect(Number({ valueOf: function () { return '0o12345'; } })).to.equal(5349);
expect(Number({ toString: function () { return '0o12345'; } })).to.equal(5349);
expect(Number({ valueOf: function () { return '0b101010'; } })).to.equal(42);
expect(Number({ toString: function () { return '0b101010'; } })).to.equal(42);
});
it('should work with correct whitespaces', function () {
var whitespace = ' \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000';
// Zero-width space (zws), next line character (nel), and non-character (bom) are not whitespace.
var nonWhitespaces = ['\u0085', '\u200b', '\ufffe'];
expect(String(Number(nonWhitespaces[0] + '0' + nonWhitespaces[0]))).to.equal('NaN');
expect(String(Number(nonWhitespaces[1] + '1' + nonWhitespaces[1]))).to.equal('NaN');
expect(String(Number(nonWhitespaces[2] + '2' + nonWhitespaces[2]))).to.equal('NaN');
expect(String(Number(whitespace + '3' + whitespace))).to.equal('3');
});
});
});

365
node_modules/es6-shim/test/object.js generated vendored Normal file
View File

@ -0,0 +1,365 @@
describe('Object', function () {
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.Object).to.equal(Object);
});
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifExtensionsPreventable = Object.preventExtensions ? it : xit;
var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol';
var ifSymbolsIt = hasSymbols ? it : xit;
var ifBrowserIt = typeof window === 'object' && typeof document === 'object' ? it : xit;
var ifObjectGetPrototypeOfIt = typeof Object.getPrototypeOf === 'function' ? it : xit;
if (Object.getOwnPropertyNames) {
describe('.getOwnPropertyNames()', function () {
it('throws on null or undefined', function () {
expect(function () { Object.getOwnPropertyNames(); }).to['throw'](TypeError);
expect(function () { Object.getOwnPropertyNames(undefined); }).to['throw'](TypeError);
expect(function () { Object.getOwnPropertyNames(null); }).to['throw'](TypeError);
});
it('works on primitives', function () {
[true, false, NaN, 42, /a/g, 'foo'].forEach(function (item) {
expect(Object.getOwnPropertyNames(item)).to.eql(Object.getOwnPropertyNames(Object(item)));
});
});
ifBrowserIt('does not break when an iframe is added', function () {
/*global window, document */
var div = document.createElement('div');
div.innerHTML = '<iframe src="http://xkcd.com"></iframe>';
document.body.appendChild(div);
setTimeout(function () {
document.body.removeChild(div);
}, 0);
expect(Array.isArray(Object.getOwnPropertyNames(window))).to.eql(true);
});
});
}
if (Object.getOwnPropertyDescriptor) {
describe('.getOwnPropertyDescriptor()', function () {
it('throws on null or undefined', function () {
expect(function () { Object.getOwnPropertyDescriptor(); }).to['throw'](TypeError);
expect(function () { Object.getOwnPropertyDescriptor(undefined); }).to['throw'](TypeError);
expect(function () { Object.getOwnPropertyDescriptor(null); }).to['throw'](TypeError);
});
it('works on primitives', function () {
[true, false, NaN, 42, /a/g, 'foo'].forEach(function (item) {
expect(Object.getOwnPropertyDescriptor(item, 'foo')).to.eql(Object.getOwnPropertyDescriptor(Object(item), 'foo'));
});
});
});
}
if (Object.seal) {
describe('.seal()', function () {
it('works on primitives', function () {
[null, undefined, true, false, NaN, 42, 'foo'].forEach(function (item) {
expect(Object.seal(item)).to.eql(item);
});
});
});
}
if (Object.isSealed) {
describe('.isSealed()', function () {
it('works on primitives', function () {
[null, undefined, true, false, NaN, 42, 'foo'].forEach(function (item) {
expect(Object.isSealed(item)).to.equal(true);
});
});
});
}
if (Object.freeze) {
describe('.freeze()', function () {
it('works on primitives', function () {
[null, undefined, true, false, NaN, 42, 'foo'].forEach(function (item) {
expect(Object.freeze(item)).to.eql(item);
});
});
});
}
if (Object.isFrozen) {
describe('.isFrozen()', function () {
it('works on primitives', function () {
[null, undefined, true, false, NaN, 42, 'foo'].forEach(function (item) {
expect(Object.isFrozen(item)).to.equal(true);
});
});
});
}
if (Object.preventExtensions) {
describe('.preventExtensions()', function () {
it('works on primitives', function () {
[null, undefined, true, false, NaN, 42, 'foo'].forEach(function (item) {
expect(Object.preventExtensions(item)).to.eql(item);
});
});
});
}
if (Object.isExtensible) {
describe('.isExtensible()', function () {
it('works on primitives', function () {
[null, undefined, true, false, NaN, 42, 'foo'].forEach(function (item) {
expect(Object.isExtensible(item)).to.equal(false);
});
});
});
}
describe('.keys()', function () {
it('works on strings', function () {
expect(Object.keys('foo')).to.eql(['0', '1', '2']);
});
it('throws on null or undefined', function () {
expect(function () { Object.keys(); }).to['throw'](TypeError);
expect(function () { Object.keys(undefined); }).to['throw'](TypeError);
expect(function () { Object.keys(null); }).to['throw'](TypeError);
});
it('works on other primitives', function () {
[true, false, NaN, 42, /a/g].forEach(function (item) {
expect(Object.keys(item)).to.eql([]);
});
});
});
describe('.is()', function () {
if (!Object.prototype.hasOwnProperty.call(Object, 'is')) {
return it('exists', function () {
expect(Object).to.have.property('is');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Object.is).to.have.property('name', 'is');
});
it('should have the right arity', function () {
expect(Object.is).to.have.property('length', 2);
});
it('should compare regular objects correctly', function () {
[null, undefined, [0], 5, 'str', { a: null }].map(function (item) {
return Object.is(item, item);
}).forEach(function (result) {
expect(result).to.equal(true);
});
});
it('should compare 0 and -0 correctly', function () {
expect(Object.is(0, -0)).to.equal(false);
});
it('should compare NaNs correctly', function () {
expect(Object.is(NaN, NaN)).to.equal(true);
});
});
describe('.assign()', function () {
if (!Object.prototype.hasOwnProperty.call(Object, 'assign')) {
return it('exists', function () {
expect(Object).to.have.property('assign');
});
}
it('has the correct length', function () {
expect(Object.assign.length).to.eql(2);
});
it('returns the modified target object', function () {
var target = {};
var returned = Object.assign(target, { a: 1 });
expect(returned).to.equal(target);
});
it('should merge two objects', function () {
var target = { a: 1 };
var returned = Object.assign(target, { b: 2 });
expect(returned).to.eql({ a: 1, b: 2 });
});
it('should merge three objects', function () {
var target = { a: 1 };
var source1 = { b: 2 };
var source2 = { c: 3 };
var returned = Object.assign(target, source1, source2);
expect(returned).to.eql({ a: 1, b: 2, c: 3 });
});
it('only iterates over own keys', function () {
var Foo = function () {};
Foo.prototype.bar = true;
var foo = new Foo();
foo.baz = true;
var target = { a: 1 };
var returned = Object.assign(target, foo);
expect(returned).to.equal(target);
expect(target).to.eql({ baz: true, a: 1 });
});
it('throws when target is null or undefined', function () {
expect(function () { Object.assign(null); }).to['throw'](TypeError);
expect(function () { Object.assign(undefined); }).to['throw'](TypeError);
});
it('coerces lone target to an object', function () {
var result = {
bool: Object.assign(true),
number: Object.assign(1),
string: Object.assign('1')
};
expect(typeof result.bool).to.equal('object');
expect(Boolean.prototype.valueOf.call(result.bool)).to.equal(true);
expect(typeof result.number).to.equal('object');
expect(Number.prototype.valueOf.call(result.number)).to.equal(1);
expect(typeof result.string).to.equal('object');
expect(String.prototype.valueOf.call(result.string)).to.equal('1');
});
it('coerces target to an object, assigns from sources', function () {
var sourceA = { a: 1 };
var sourceB = { b: 1 };
var result = {
bool: Object.assign(true, sourceA, sourceB),
number: Object.assign(1, sourceA, sourceB),
string: Object.assign('1', sourceA, sourceB)
};
expect(typeof result.bool).to.equal('object');
expect(Boolean.prototype.valueOf.call(result.bool)).to.equal(true);
expect(result.bool).to.eql({ a: 1, b: 1 });
expect(typeof result.number).to.equal('object');
expect(Number.prototype.valueOf.call(result.number)).to.equal(1);
expect(typeof result.string).to.equal('object');
expect(String.prototype.valueOf.call(result.string)).to.equal('1');
expect(result.string).to.eql({ 0: '1', a: 1, b: 1 });
});
it('ignores non-object sources', function () {
expect(Object.assign({ a: 1 }, null, { b: 2 })).to.eql({ a: 1, b: 2 });
expect(Object.assign({ a: 1 }, undefined, { b: 2 })).to.eql({ a: 1, b: 2 });
expect(Object.assign({ a: 1 }, { b: 2 }, null)).to.eql({ a: 1, b: 2 });
});
ifExtensionsPreventable('does not have pending exceptions', function () {
'use strict';
// Firefox 37 still has "pending exception" logic in its Object.assign implementation,
// which is 72% slower than our shim, and Firefox 40's native implementation.
var thrower = { 1: 2, 2: 3, 3: 4 };
Object.defineProperty(thrower, 2, {
get: function () { return 3; },
set: function (v) { throw new RangeError('IE 9 does not throw on preventExtensions: ' + v); }
});
Object.preventExtensions(thrower);
expect(thrower).to.have.property(2, 3);
var error;
try {
Object.assign(thrower, 'wxyz');
} catch (e) {
error = e;
}
expect(thrower).not.to.have.property(0);
if (thrower[1] === 'x') {
// IE 9 doesn't throw in strict mode with preventExtensions
expect(error).to.be.an.instanceOf(RangeError);
} else {
expect(error).to.be.an.instanceOf(TypeError);
expect(thrower).to.have.property(1, 2);
}
expect(thrower).to.have.property(2, 3);
expect(thrower).to.have.property(3, 4);
});
ifSymbolsIt('includes enumerable symbols, after keys', function () {
/* eslint max-statements-per-line: 1 */
var visited = [];
var obj = {};
Object.defineProperty(obj, 'a', { get: function () { visited.push('a'); return 42; }, enumerable: true });
var symbol = Symbol('enumerable');
Object.defineProperty(obj, symbol, {
get: function () { visited.push(symbol); return Infinity; },
enumerable: true
});
var nonEnumSymbol = Symbol('non-enumerable');
Object.defineProperty(obj, nonEnumSymbol, {
get: function () { visited.push(nonEnumSymbol); return -Infinity; },
enumerable: false
});
var target = Object.assign({}, obj);
expect(visited).to.eql(['a', symbol]);
expect(target.a).to.equal(42);
expect(target[symbol]).to.equal(Infinity);
expect(target[nonEnumSymbol]).not.to.equal(-Infinity);
});
});
describe('Object.setPrototypeOf()', function () {
if (!Object.setPrototypeOf) {
return; // IE < 11
}
describe('argument checking', function () {
it('should throw TypeError if first arg is not object', function () {
var nonObjects = [null, undefined, true, false, 1, 3, 'foo'];
nonObjects.forEach(function (value) {
expect(function () { Object.setPrototypeOf(value); }).to['throw'](TypeError);
});
});
it('should throw TypeError if second arg is not object or null', function () {
expect(function () { Object.setPrototypeOf({}, null); }).not.to['throw'](TypeError);
var invalidPrototypes = [true, false, 1, 3, 'foo'];
invalidPrototypes.forEach(function (proto) {
expect(function () { Object.setPrototypeOf({}, proto); }).to['throw'](TypeError);
});
});
});
describe('set prototype', function () {
it('should work', function () {
var Foo = function () {};
var Bar = {};
var foo = new Foo();
expect(Object.getPrototypeOf(foo)).to.equal(Foo.prototype);
var fooBar = Object.setPrototypeOf(foo, Bar);
expect(fooBar).to.equal(foo);
expect(Object.getPrototypeOf(foo)).to.equal(Bar);
});
it('should be able to set to null', function () {
var Foo = function () {};
var foo = new Foo();
var fooNull = Object.setPrototypeOf(foo, null);
expect(fooNull).to.equal(foo);
expect(Object.getPrototypeOf(foo)).to.equal(null);
});
});
});
describe('.getPrototypeOf()', function () {
ifObjectGetPrototypeOfIt('does not throw for a primitive', function () {
expect(Object.getPrototypeOf(3)).to.equal(Number.prototype);
});
});
});

43
node_modules/es6-shim/test/promise.js generated vendored Normal file
View File

@ -0,0 +1,43 @@
/* This file is for testing implementation regressions of Promises. */
describe('Promise', function () {
if (typeof Promise === 'undefined') {
return it('exists', function () {
expect(typeof Promise).to.be('function');
});
}
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.Promise).to.equal(Promise);
});
it('ignores non-function .then arguments', function () {
expect(function () {
Promise.reject(42).then(null, 5).then(null, function () {});
}).not.to['throw']();
});
describe('extra methods (bad Chrome!)', function () {
it('does not have accept', function () {
expect(Promise).not.to.have.property('accept');
});
it('does not have defer', function () {
expect(Promise).not.to.have.property('defer');
});
it('does not have chain', function () {
expect(Promise.prototype).not.to.have.property('chain');
});
});
it('requires an object context', function () {
// this fails in Safari 7.1 - 9
expect(function promiseDotCallThree() {
Promise.call(3, function () {});
}).to['throw']();
});
});

203
node_modules/es6-shim/test/promise/all.js generated vendored Normal file
View File

@ -0,0 +1,203 @@
/* global it, describe, expect, assert, Promise */
var failIfThrows = function (done) {
'use strict';
return function (e) {
done(e || new Error());
};
};
describe('Promise.all', function () {
'use strict';
it('should not be enumerable', function () {
expect(Promise).ownPropertyDescriptor('all').to.have.property('enumerable', false);
});
it('fulfills if passed an empty array', function (done) {
var iterable = [];
Promise.all(iterable).then(function (value) {
assert(Array.isArray(value));
assert.deepEqual(value, []);
}).then(done, failIfThrows(done));
});
it('fulfills if passed an empty array-like', function (done) {
var f = function () {
Promise.all(arguments).then(function (value) {
assert(Array.isArray(value));
assert.deepEqual(value, []);
}).then(done, failIfThrows(done));
};
f();
});
it('fulfills if passed an array of mixed fulfilled promises and values', function (done) {
var iterable = [0, Promise.resolve(1), 2, Promise.resolve(3)];
Promise.all(iterable).then(function (value) {
assert(Array.isArray(value));
assert.deepEqual(value, [0, 1, 2, 3]);
}).then(done, failIfThrows(done));
});
it('rejects if any passed promise is rejected', function (done) {
var foreverPending = new Promise(function () { });
var error = new Error('Rejected');
var rejected = Promise.reject(error);
var iterable = [foreverPending, rejected];
Promise.all(iterable).then(
function () {
assert(false, 'should never get here');
},
function (reason) {
assert.strictEqual(reason, error);
}
).then(done, failIfThrows(done));
});
it('resolves foreign thenables', function (done) {
var normal = Promise.resolve(1);
var foreign = { then: function (f) { f(2); } };
var iterable = [normal, foreign];
Promise.all(iterable).then(function (value) {
assert.deepEqual(value, [1, 2]);
}).then(done, failIfThrows(done));
});
it('fulfills when passed an sparse array, giving `undefined` for the omitted values', function (done) {
/* jshint elision: true */
/* jscs:disable disallowSpaceBeforeComma */
/* jscs:disable requireSpaceAfterComma */
/* eslint-disable no-sparse-arrays */
var iterable = [Promise.resolve(0), , , Promise.resolve(1)];
/* eslint-enable no-sparse-arrays */
/* jscs:enable requireSpaceAfterComma */
/* jscs:enable disallowSpaceBeforeComma */
/* jshint elision: false */
Promise.all(iterable).then(function (value) {
assert.deepEqual(value, [0, undefined, undefined, 1]);
}).then(done, failIfThrows(done));
});
it('does not modify the input array', function (done) {
var input = [0, 1];
var iterable = input;
Promise.all(iterable).then(function (value) {
assert.notStrictEqual(input, value);
}).then(done, failIfThrows(done));
});
it('should reject with a TypeError if given a non-iterable', function (done) {
var notIterable = {};
Promise.all(notIterable).then(
function () {
assert(false, 'should never get here');
},
function (reason) {
assert(reason instanceof TypeError);
}
).then(done, failIfThrows(done));
});
// test cases from
// https://github.com/domenic/promises-unwrapping/issues/89#issuecomment-33110203
var tamper = function (p) {
p.then = function (fulfill, reject) {
fulfill('tampered');
return Promise.prototype.then.call(this, fulfill, reject);
};
return p;
};
it('should be robust against tampering (1)', function (done) {
var g = [tamper(Promise.resolve(0))];
// Prevent countdownHolder.[[Countdown]] from ever reaching zero
Promise.all(g).then(
function () { done(); },
failIfThrows(done)
);
});
it('should be robust against tampering (2)', function (done) {
// Promise from Promise.all resolved before arguments
var fulfillCalled = false;
var g = [
Promise.resolve(0),
tamper(Promise.resolve(1)),
Promise.resolve(2).then(function () {
assert(!fulfillCalled, 'should be resolved before all()');
}).then(function () {
assert(!fulfillCalled, 'should be resolved before all()');
})['catch'](failIfThrows(done))
];
Promise.all(g).then(function () {
assert(!fulfillCalled, 'should be resolved last');
fulfillCalled = true;
}).then(done, failIfThrows(done));
});
it('should be robust against tampering (3)', function (done) {
var g = [
Promise.resolve(0),
tamper(Promise.resolve(1)),
Promise.reject(2)
];
// Promise from Promise.all resolved despite rejected promise in arguments
Promise.all(g).then(function () {
throw new Error('should not reach here!');
}, function (e) {
assert.strictEqual(e, 2);
}).then(done, failIfThrows(done));
});
it('should be robust against tampering (4)', function (done) {
var hijack = true;
var actualArguments = [];
var P = function (resolver) {
var self;
if (hijack) {
hijack = false;
self = new Promise(function (resolve, reject) {
return resolver(function (values) {
// record arguments & # of times resolve function is called
actualArguments.push(values.slice());
return resolve(values);
}, reject);
});
} else {
self = new Promise(resolver);
}
Object.setPrototypeOf(self, P.prototype);
return self;
};
if (!Object.setPrototypeOf) { return done(); } // skip test if on IE < 11
Object.setPrototypeOf(P, Promise);
P.prototype = Object.create(Promise.prototype, {
constructor: { value: P }
});
P.resolve = function (p) { return p; };
var g = [
Promise.resolve(0),
tamper(Promise.resolve(1)),
Promise.resolve(2)
];
// Promise.all calls resolver twice
P.all(g)['catch'](failIfThrows(done));
Promise.resolve().then(function () {
assert.deepEqual(actualArguments, [[0, 'tampered', 2]]);
}).then(done, failIfThrows(done));
});
});

36
node_modules/es6-shim/test/promise/evil-promises.js generated vendored Normal file
View File

@ -0,0 +1,36 @@
describe('Evil promises should not be able to break invariants', function () {
'use strict';
specify('resolving to a promise that calls onFulfilled twice', function (done) {
// note that we have to create a trivial subclass, as otherwise the
// Promise.resolve(evilPromise) is just the identity function.
// (And in fact, most native Promise implementations use a private
// [[PromiseConstructor]] field in `Promise.resolve` which can't be
// easily patched in an ES5 engine, so instead of
// `Promise.resolve(evilPromise)` we'll use
// `new Promise(function(r){r(evilPromise);})` below.)
var EvilPromise = function (executor) {
var self = new Promise(executor);
Object.setPrototypeOf(self, EvilPromise.prototype);
return self;
};
if (!Object.setPrototypeOf) { return done(); } // skip test if on IE < 11
Object.setPrototypeOf(EvilPromise, Promise);
EvilPromise.prototype = Object.create(Promise.prototype, {
constructor: { value: EvilPromise }
});
var evilPromise = EvilPromise.resolve();
evilPromise.then = function (f) {
f(1);
f(2);
};
var calledAlready = false;
new Promise(function (r) { r(evilPromise); }).then(function (value) {
assert.strictEqual(calledAlready, false);
calledAlready = true;
assert.strictEqual(value, 1);
}).then(done, done);
});
});

23
node_modules/es6-shim/test/promise/promises-aplus.js generated vendored Normal file
View File

@ -0,0 +1,23 @@
// tests from promises-aplus-tests
describe('Promises/A+ Tests', function () {
'use strict';
if (typeof Promise === 'undefined') {
return;
}
require('promises-aplus-tests').mocha({
// an adapter from es6 spec to Promises/A+
deferred: function () {
var result = {};
result.promise = new Promise(function (resolve, reject) {
result.resolve = resolve;
result.reject = reject;
});
return result;
},
resolved: Promise.resolve.bind(Promise),
rejected: Promise.reject.bind(Promise)
});
});

22
node_modules/es6-shim/test/promise/promises-es6.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
// tests from promises-es6-tests
(function () {
'use strict';
if (typeof Promise === 'undefined') {
return;
}
describe('Promises/ES6 Tests', function () {
// an adapter that sets up global.Promise
// since it's already set up, empty functions will suffice
var adapter = {
defineGlobalPromise: function () {
},
removeGlobalPromise: function () {
}
};
require('promises-es6-tests').mocha(adapter);
});
}());

88
node_modules/es6-shim/test/promise/race.js generated vendored Normal file
View File

@ -0,0 +1,88 @@
var failIfThrows = function (done) {
'use strict';
return function (e) {
done(e || new Error());
};
};
var delayPromise = function (value, ms) {
'use strict';
return new Promise(function (resolve) {
setTimeout(function () {
resolve(value);
}, ms);
});
};
describe('Promise.race', function () {
'use strict';
it('should not be enumerable', function () {
expect(Promise).ownPropertyDescriptor('race').to.have.property('enumerable', false);
});
it('should fulfill if all promises are settled and the ordinally-first is fulfilled', function (done) {
var iterable = [Promise.resolve(1), Promise.reject(2), Promise.resolve(3)];
Promise.race(iterable).then(function (value) {
assert.strictEqual(value, 1);
}).then(done, failIfThrows(done));
});
it('should reject if all promises are settled and the ordinally-first is rejected', function (done) {
var iterable = [Promise.reject(1), Promise.reject(2), Promise.resolve(3)];
Promise.race(iterable).then(
function () {
assert(false, 'should never get here');
},
function (reason) {
assert.strictEqual(reason, 1);
}
).then(done, failIfThrows(done));
});
it('should settle in the same way as the first promise to settle', function (done) {
// ensure that even if timeouts are delayed an all execute together,
// p2 will settle first.
var p2 = delayPromise(2, 200);
var p1 = delayPromise(1, 1000);
var p3 = delayPromise(3, 500);
var iterable = [p1, p2, p3];
Promise.race(iterable).then(function (value) {
assert.strictEqual(value, 2);
}).then(done, failIfThrows(done));
});
// see https://github.com/domenic/promises-unwrapping/issues/75
it('should never settle when given an empty iterable', function (done) {
var iterable = [];
var settled = false;
Promise.race(iterable).then(
function () { settled = true; },
function () { settled = true; }
);
setTimeout(function () {
assert.strictEqual(settled, false);
done();
}, 300);
});
it('should reject with a TypeError if given a non-iterable', function (done) {
var notIterable = {};
Promise.race(notIterable).then(
function () {
assert(false, 'should never get here');
},
function (reason) {
assert(reason instanceof TypeError);
}
).then(done, failIfThrows(done));
});
});

34
node_modules/es6-shim/test/promise/reject.js generated vendored Normal file
View File

@ -0,0 +1,34 @@
var failIfThrows = function (done) {
'use strict';
return function (e) {
done(e || new Error());
};
};
describe('Promise.reject', function () {
'use strict';
it('should not be enumerable', function () {
expect(Promise).ownPropertyDescriptor('reject').to.have.property('enumerable', false);
});
it('should return a rejected promise', function (done) {
var value = {};
Promise.reject(value).then(failIfThrows(done), function (result) {
expect(result).to.equal(value);
done();
});
});
it('throws when receiver is a primitive', function () {
var promise = Promise.reject();
expect(function () { Promise.reject.call(undefined, promise); }).to['throw']();
expect(function () { Promise.reject.call(null, promise); }).to['throw']();
expect(function () { Promise.reject.call('', promise); }).to['throw']();
expect(function () { Promise.reject.call(42, promise); }).to['throw']();
expect(function () { Promise.reject.call(false, promise); }).to['throw']();
expect(function () { Promise.reject.call(true, promise); }).to['throw']();
promise.then(null, function () {}); // silence unhandled rejection errors in Chrome
});
});

33
node_modules/es6-shim/test/promise/resolve.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
var failIfThrows = function (done) {
'use strict';
return function (e) {
done(e || new Error());
};
};
describe('Promise.resolve', function () {
'use strict';
it('should not be enumerable', function () {
expect(Promise).ownPropertyDescriptor('resolve').to.have.property('enumerable', false);
});
it('should return a resolved promise', function (done) {
var value = {};
Promise.resolve(value).then(function (result) {
expect(result).to.equal(value);
done();
}, failIfThrows(done));
});
it('throws when receiver is a primitive', function () {
var promise = Promise.resolve();
expect(function () { Promise.resolve.call(undefined, promise); }).to['throw']();
expect(function () { Promise.resolve.call(null, promise); }).to['throw']();
expect(function () { Promise.resolve.call('', promise); }).to['throw']();
expect(function () { Promise.resolve.call(42, promise); }).to['throw']();
expect(function () { Promise.resolve.call(false, promise); }).to['throw']();
expect(function () { Promise.resolve.call(true, promise); }).to['throw']();
});
});

96
node_modules/es6-shim/test/promise/simple.js generated vendored Normal file
View File

@ -0,0 +1,96 @@
var failIfThrows = function (done) {
'use strict';
return function (e) {
done(e || new Error());
};
};
describe('Promise', function () {
'use strict';
specify('sanity check: a fulfilled promise calls its fulfillment handler', function (done) {
Promise.resolve(5).then(function (value) {
assert.strictEqual(value, 5);
}).then(done, failIfThrows(done));
});
specify('directly resolving the promise with itself', function (done) {
var resolvePromise;
var promise = new Promise(function (resolve) { resolvePromise = resolve; });
resolvePromise(promise);
promise.then(
function () {
assert(false, 'Should not be fulfilled');
},
function (err) {
assert(err instanceof TypeError);
}
).then(done, failIfThrows(done));
});
specify('Stealing a resolver and using it to trigger possible reentrancy bug (#83)', function () {
var stolenResolver;
var StealingPromiseConstructor = function StealingPromiseConstructor(resolver) {
stolenResolver = resolver;
resolver(function () { }, function () { });
};
var iterable = {};
var atAtIterator = '@@iterator'; // on firefox, at least.
iterable[atAtIterator] = function () {
stolenResolver(null, null);
throw new Error(0);
};
assert.doesNotThrow(function () {
Promise.all.call(StealingPromiseConstructor, iterable);
});
});
specify('resolve with a thenable calls it once', function () {
var resolve;
var p = new Promise(function (r) { resolve = r; });
var count = 0;
resolve({
then: function () {
count += 1;
throw new RangeError('reject the promise');
}
});
var a = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
var b = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
return Promise.all([a, b]);
});
specify('resolve with a thenable that throws on .then, rejects the promise synchronously', function () {
var resolve;
var p = new Promise(function (r) { resolve = r; });
var count = 0;
var thenable = Object.defineProperty({}, 'then', {
get: function () {
count += 1;
throw new RangeError('no then for you');
}
});
resolve(thenable);
assert.equal(count, 1);
var a = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
var b = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
return Promise.all([a, b]);
});
});

47
node_modules/es6-shim/test/promise/subclass.js generated vendored Normal file
View File

@ -0,0 +1,47 @@
/* global it, describe, assert, Promise */
describe('Support user subclassing of Promise', function () {
'use strict';
it('should work if you do it right', function (done) {
// This is the "correct" es6-compatible way.
// (Thanks, @domenic and @zloirock!)
var MyPromise = function (executor) {
var self = new Promise(executor);
Object.setPrototypeOf(self, MyPromise.prototype);
self.mine = 'yeah';
return self;
};
if (!Object.setPrototypeOf) { return done(); } // skip test if on IE < 11
Object.setPrototypeOf(MyPromise, Promise);
MyPromise.prototype = Object.create(Promise.prototype, {
constructor: { value: MyPromise }
});
// let's try it!
var p1 = MyPromise.resolve(5);
assert.strictEqual(p1.mine, 'yeah');
p1 = p1.then(function (x) {
assert.strictEqual(x, 5);
});
assert.strictEqual(p1.mine, 'yeah');
var p2 = new MyPromise(function (r) { r(6); });
assert.strictEqual(p2.mine, 'yeah');
p2 = p2.then(function (x) {
assert.strictEqual(x, 6);
});
assert.strictEqual(p2.mine, 'yeah');
var p3 = MyPromise.all([p1, p2]);
assert.strictEqual(p3.mine, 'yeah');
p3.then(function () { done(); }, done);
});
it("should throw if you don't inherit at all", function () {
var MyPromise = function () {};
assert['throws'](function () {
Promise.all.call(MyPromise, []);
}, TypeError);
});
});

679
node_modules/es6-shim/test/reflect.js generated vendored Normal file
View File

@ -0,0 +1,679 @@
var arePropertyDescriptorsSupported = function () {
try {
Object.defineProperty({}, 'x', {});
return true;
} catch (e) { /* this is IE 8. */
return false;
}
};
var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
var functionsHaveNames = function f() {}.name === 'f';
var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol';
var ifSymbolsIt = hasSymbols ? it : xit;
var describeIfGetProto = Object.getPrototypeOf ? describe : xdescribe;
var describeIfSetProto = Object.setPrototypeOf ? describe : xdescribe;
var describeIfES5 = supportsDescriptors ? describe : xdescribe;
var describeIfExtensionsPreventible = Object.preventExtensions ? describe : xdescribe;
var describeIfGetOwnPropertyNames = Object.getOwnPropertyNames ? describe : xdescribe;
var ifExtensionsPreventibleIt = Object.preventExtensions ? it : xit;
var ifES5It = supportsDescriptors ? it : xit;
var ifFreezeIt = typeof Object.freeze === 'function' ? it : xit;
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
describe('Reflect', function () {
if (typeof Reflect === 'undefined') {
return it('exists', function () {
expect(this).to.have.property('Reflect');
});
}
var object = {
something: 1,
_value: 0
};
if (supportsDescriptors) {
/* eslint-disable accessor-pairs */
Object.defineProperties(object, {
value: {
get: function () {
return this._value;
}
},
setter: {
set: function (val) {
this._value = val;
}
},
bool: {
value: true
}
});
/* eslint-enable accessor-pairs */
}
var testXThrow = function (values, func) {
var checker = function checker(item) {
try {
func(item);
return false;
} catch (e) {
return e instanceof TypeError;
}
};
values.forEach(function (item) {
expect(item).to.satisfy(checker);
});
};
var testCallableThrow = testXThrow.bind(null, [null, undefined, 1, 'string', true, [], {}]);
var testPrimitiveThrow = testXThrow.bind(null, [null, undefined, 1, 'string', true]);
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.Reflect).to.equal(Reflect);
});
describe('.apply()', function () {
if (typeof Reflect.apply === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('apply');
});
}
it('is a function', function () {
expect(typeof Reflect.apply).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.apply.name).to.equal('apply');
});
it('throws if target isnt callable', function () {
testCallableThrow(function (item) {
return Reflect.apply(item, null, []);
});
});
it('works also with redefined apply', function () {
expect(Reflect.apply(Array.prototype.push, [1, 2], [3, 4, 5])).to.equal(5);
var F = function F(a, b, c) {
return a + b + c;
};
F.apply = false;
expect(Reflect.apply(F, null, [1, 2, 3])).to.equal(6);
var G = function G(last) {
return this.x + 'lo' + last;
};
G.apply = function nop() {};
expect(Reflect.apply(G, { x: 'yel' }, ['!'])).to.equal('yello!');
});
});
describe('.construct()', function () {
if (typeof Reflect.construct === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('construct');
});
}
it('is a function', function () {
expect(typeof Reflect.construct).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.construct.name).to.equal('construct');
});
it('throws if target isnt callable', function () {
testCallableThrow(function (item) {
return Reflect.apply(item, null, []);
});
});
it('works also with redefined apply', function () {
var C = function C(a, b, c) {
this.qux = [a, b, c].join('|');
};
C.apply = undefined;
expect(Reflect.construct(C, ['foo', 'bar', 'baz']).qux).to.equal('foo|bar|baz');
});
it('correctly handles newTarget param', function () {
var F = function F() {};
expect(Reflect.construct(function () {}, [], F) instanceof F).to.equal(true);
});
});
describeIfES5('.defineProperty()', function () {
if (typeof Reflect.defineProperty === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('defineProperty');
});
}
it('is a function', function () {
expect(typeof Reflect.defineProperty).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.defineProperty.name).to.equal('defineProperty');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.defineProperty(item, 'prop', { value: true });
});
});
ifExtensionsPreventibleIt('returns false for non-extensible objects', function () {
var o = Object.preventExtensions({});
expect(Reflect.defineProperty(o, 'prop', {})).to.equal(false);
});
it('can return true, even for non-configurable, non-writable properties', function () {
var o = {};
var desc = {
value: 13,
enumerable: false,
writable: false,
configurable: false
};
expect(Reflect.defineProperty(o, 'prop', desc)).to.equal(true);
// Defined as non-configurable, but descriptor is identical.
expect(Reflect.defineProperty(o, 'prop', desc)).to.equal(true);
desc.value = 37; // Change
expect(Reflect.defineProperty(o, 'prop', desc)).to.equal(false);
});
it('can change from one property type to another, if configurable', function () {
var o = {};
var desc1 = {
set: function () {},
configurable: true
};
var desc2 = {
value: 13,
configurable: false
};
var desc3 = {
get: function () {}
};
expect(Reflect.defineProperty(o, 'prop', desc1)).to.equal(true);
expect(Reflect.defineProperty(o, 'prop', desc2)).to.equal(true);
expect(Reflect.defineProperty(o, 'prop', desc3)).to.equal(false);
});
});
describe('.deleteProperty()', function () {
if (typeof Reflect.deleteProperty === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('deleteProperty');
});
}
it('is a function', function () {
expect(typeof Reflect.deleteProperty).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.deleteProperty.name).to.equal('deleteProperty');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.deleteProperty(item, 'prop');
});
});
ifES5It('returns true for success and false for failure', function () {
var o = { a: 1 };
Object.defineProperty(o, 'b', { value: 2 });
expect(o).to.have.property('a');
expect(o).to.have.property('b');
expect(o.a).to.equal(1);
expect(o.b).to.equal(2);
expect(Reflect.deleteProperty(o, 'a')).to.equal(true);
expect(o).not.to.have.property('a');
expect(o.b).to.equal(2);
expect(Reflect.deleteProperty(o, 'b')).to.equal(false);
expect(o).to.have.property('b');
expect(o.b).to.equal(2);
expect(Reflect.deleteProperty(o, 'a')).to.equal(true);
});
it('cannot delete an arrays length property', function () {
expect(Reflect.deleteProperty([], 'length')).to.equal(false);
});
});
describeIfES5('.get()', function () {
if (typeof Reflect.get === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('get');
});
}
it('is a function', function () {
expect(typeof Reflect.get).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.get.name).to.equal('get');
});
it('throws on null and undefined', function () {
[null, undefined].forEach(function (item) {
expect(function () {
return Reflect.get(item, 'property');
}).to['throw'](TypeError);
});
});
it('can retrieve a simple value, from the target', function () {
var p = { something: 2, bool: false };
expect(Reflect.get(object, 'something')).to.equal(1);
// p has no effect
expect(Reflect.get(object, 'something', p)).to.equal(1);
// Value-defined properties take the target's value,
// and ignore that of the receiver.
expect(Reflect.get(object, 'bool', p)).to.equal(true);
// Undefined values
expect(Reflect.get(object, 'undefined_property')).to.equal(undefined);
});
it('will invoke getters on the receiver rather than target', function () {
var other = { _value: 1337 };
expect(Reflect.get(object, 'value', other)).to.equal(1337);
// No getter for setter property
expect(Reflect.get(object, 'setter', other)).to.equal(undefined);
});
it('will search the prototype chain', function () {
var other = Object.create(object);
other._value = 17;
var yetAnother = { _value: 4711 };
expect(Reflect.get(other, 'value', yetAnother)).to.equal(4711);
expect(Reflect.get(other, 'bool', yetAnother)).to.equal(true);
});
});
describeIfES5('.set()', function () {
if (typeof Reflect.set === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('set');
});
}
it('is a function', function () {
expect(typeof Reflect.set).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.set.name).to.equal('set');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.set(item, 'prop', 'value');
});
});
it('sets values on receiver', function () {
var target = {};
var receiver = {};
expect(Reflect.set(target, 'foo', 1, receiver)).to.equal(true);
expect('foo' in target).to.equal(false);
expect(receiver.foo).to.equal(1);
expect(Reflect.defineProperty(receiver, 'bar', {
value: 0,
writable: true,
enumerable: false,
configurable: true
})).to.equal(true);
expect(Reflect.set(target, 'bar', 1, receiver)).to.equal(true);
expect(receiver.bar).to.equal(1);
expect(Reflect.getOwnPropertyDescriptor(receiver, 'bar').enumerable).to.equal(false);
var out;
/* eslint-disable accessor-pairs */
target = Object.create({}, {
o: {
set: function () { out = this; }
}
});
/* eslint-enable accessor-pairs */
expect(Reflect.set(target, 'o', 17, receiver)).to.equal(true);
expect(out).to.equal(receiver);
});
});
describeIfES5('.getOwnPropertyDescriptor()', function () {
if (typeof Reflect.getOwnPropertyDescriptor === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('getOwnPropertyDescriptor');
});
}
it('is a function', function () {
expect(typeof Reflect.getOwnPropertyDescriptor).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.getOwnPropertyDescriptor.name).to.equal('getOwnPropertyDescriptor');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.getOwnPropertyDescriptor(item, 'prop');
});
});
it('retrieves property descriptors', function () {
var obj = { a: 4711 };
var desc = Reflect.getOwnPropertyDescriptor(obj, 'a');
expect(desc).to.deep.equal({
value: 4711,
configurable: true,
writable: true,
enumerable: true
});
});
});
describeIfGetProto('.getPrototypeOf()', function () {
if (typeof Reflect.getPrototypeOf === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('getPrototypeOf');
});
}
it('is a function', function () {
expect(typeof Reflect.getPrototypeOf).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.getPrototypeOf.name).to.equal('getPrototypeOf');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.getPrototypeOf(item);
});
});
it('retrieves prototypes', function () {
expect(Reflect.getPrototypeOf(Object.create(null))).to.equal(null);
expect(Reflect.getPrototypeOf([])).to.equal(Array.prototype);
});
});
describe('.has()', function () {
if (typeof Reflect.has === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('has');
});
}
it('is a function', function () {
expect(typeof Reflect.has).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.has.name).to.equal('has');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.has(item, 'prop');
});
});
it('will detect own properties', function () {
var target = Object.create ? Object.create(null) : {};
expect(Reflect.has(target, 'prop')).to.equal(false);
target.prop = undefined;
expect(Reflect.has(target, 'prop')).to.equal(true);
delete target.prop;
expect(Reflect.has(target, 'prop')).to.equal(false);
expect(Reflect.has(Reflect.has, 'length')).to.equal(true);
});
ifES5It('will detect an own accessor property', function () {
var target = Object.create(null);
/* eslint-disable accessor-pairs */
Object.defineProperty(target, 'accessor', {
set: function () {}
});
/* eslint-enable accessor-pairs */
expect(Reflect.has(target, 'accessor')).to.equal(true);
});
it('will search the prototype chain', function () {
var Parent = function () {};
Parent.prototype.someProperty = undefined;
var Child = function () {};
Child.prototype = new Parent();
var target = new Child();
target.bool = true;
expect(Reflect.has(target, 'bool')).to.equal(true);
expect(Reflect.has(target, 'someProperty')).to.equal(true);
expect(Reflect.has(target, 'undefinedProperty')).to.equal(false);
});
});
describeIfExtensionsPreventible('.isExtensible()', function () {
if (typeof Reflect.isExtensible === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('isExtensible');
});
}
it('is a function', function () {
expect(typeof Reflect.isExtensible).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.isExtensible.name).to.equal('isExtensible');
});
it('returns true for plain objects', function () {
expect(Reflect.isExtensible({})).to.equal(true);
expect(Reflect.isExtensible(Object.preventExtensions({}))).to.equal(false);
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.isExtensible(item);
});
});
});
describeIfGetOwnPropertyNames('.ownKeys()', function () {
if (typeof Reflect.ownKeys === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('ownKeys');
});
}
it('is a function', function () {
expect(typeof Reflect.ownKeys).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.ownKeys.name).to.equal('ownKeys');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.ownKeys(item);
});
});
it('should return the same result as Object.getOwnPropertyNames if there are no Symbols', function () {
var obj = { foo: 1, bar: 2 };
obj[1] = 'first';
var result = Object.getOwnPropertyNames(obj);
// Reflect.ownKeys depends on the implementation of
// Object.getOwnPropertyNames, at least for non-symbol keys.
expect(Reflect.ownKeys(obj)).to.deep.equal(result);
// We can only be sure of which keys should exist.
expect(result.sort()).to.deep.equal(['1', 'bar', 'foo']);
});
ifSymbolsIt('symbols come last', function () {
var s = Symbol();
var o = {
'non-symbol': true
};
o[s] = true;
expect(Reflect.ownKeys(o)).to.deep.equal(['non-symbol', s]);
});
});
describeIfExtensionsPreventible('.preventExtensions()', function () {
if (typeof Reflect.preventExtensions === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('preventExtensions');
});
}
it('is a function', function () {
expect(typeof Reflect.preventExtensions).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.preventExtensions.name).to.equal('preventExtensions');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.preventExtensions(item);
});
});
it('prevents extensions on objects', function () {
var obj = {};
Reflect.preventExtensions(obj);
expect(Object.isExtensible(obj)).to.equal(false);
});
});
describeIfSetProto('.setPrototypeOf()', function () {
if (typeof Reflect.setPrototypeOf === 'undefined') {
return it('exists', function () {
expect(Reflect).to.have.property('setPrototypeOf');
});
}
it('is a function', function () {
expect(typeof Reflect.setPrototypeOf).to.equal('function');
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Reflect.setPrototypeOf.name).to.equal('setPrototypeOf');
});
it('throws if the target isnt an object', function () {
testPrimitiveThrow(function (item) {
return Reflect.setPrototypeOf(item, null);
});
});
it('throws if the prototype is neither object nor null', function () {
var o = {};
[undefined, 1, 'string', true].forEach(function (item) {
expect(function () {
return Reflect.setPrototypeOf(o, item);
}).to['throw'](TypeError);
});
});
it('can set prototypes, and returns true on success', function () {
var obj = {};
expect(Reflect.setPrototypeOf(obj, Array.prototype)).to.equal(true);
expect(obj).to.be.an.instanceOf(Array);
expect(obj.toString).not.to.equal(undefined);
expect(Reflect.setPrototypeOf(obj, null)).to.equal(true);
expect(obj.toString).to.equal(undefined);
});
ifFreezeIt('is returns false on failure', function () {
var obj = Object.freeze({});
expect(Reflect.setPrototypeOf(obj, null)).to.equal(false);
});
it('fails when attempting to create a circular prototype chain', function () {
var o = {};
expect(Reflect.setPrototypeOf(o, o)).to.equal(false);
});
});
});

415
node_modules/es6-shim/test/regexp.js generated vendored Normal file
View File

@ -0,0 +1,415 @@
var getRegexLiteral = function (stringRegex) {
try {
/* jshint evil: true */
/* eslint-disable no-new-func */
return Function('return ' + stringRegex + ';')();
/* eslint-enable no-new-func */
/* jshint evil: false */
} catch (e) { /**/ }
};
var describeIfSupportsDescriptors = Object.getOwnPropertyDescriptor ? describe : describe.skip;
var callAllowsPrimitives = (function () { return this === 3; }.call(3));
var ifCallAllowsPrimitivesIt = callAllowsPrimitives ? it : it.skip;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
var hasSymbols = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' && typeof Symbol('') === 'symbol';
var ifSymbolsDescribe = hasSymbols ? describe : describe.skip;
var defaultRegex = (function () {
// Chrome Canary 51 has an undefined RegExp#toSource, and
// RegExp#toString produces `/undefined/`
try {
return RegExp.prototype.source ? String(RegExp.prototype) : '/(?:)/';
} catch (e) {
return '/(?:)/';
}
}());
describe('RegExp', function () {
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.RegExp).to.equal(RegExp);
});
it('can be called with no arguments', function () {
var regex = RegExp();
expect(String(regex)).to.equal(defaultRegex);
expect(regex).to.be.an.instanceOf(RegExp);
});
it('can be called with null/undefined', function () {
expect(String(RegExp(null))).to.equal('/null/');
expect(String(RegExp(undefined))).to.equal(defaultRegex);
});
describe('constructor', function () {
it('allows a regex as the pattern', function () {
var a = /a/g;
var b = new RegExp(a);
if (typeof a !== 'function') {
// in browsers like Safari 5, new RegExp with a regex returns the same instance.
expect(a).not.to.equal(b);
}
expect(a).to.eql(b);
});
it('allows a string with flags', function () {
expect(new RegExp('a', 'mgi')).to.eql(/a/gim);
expect(String(new RegExp('a', 'mgi'))).to.equal('/a/gim');
});
it('allows a regex with flags', function () {
var a = /a/g;
var makeRegex = function () { return new RegExp(a, 'mi'); };
expect(makeRegex).not.to['throw'](TypeError);
expect(makeRegex()).to.eql(/a/mi);
expect(String(makeRegex())).to.equal('/a/im');
});
it('works with instanceof', function () {
expect(/a/g).to.be.an.instanceOf(RegExp);
expect(new RegExp('a', 'im')).to.be.an.instanceOf(RegExp);
expect(new RegExp(/a/g, 'im')).to.be.an.instanceOf(RegExp);
});
it('has the right constructor', function () {
expect(/a/g).to.have.property('constructor', RegExp);
expect(new RegExp('a', 'im')).to.have.property('constructor', RegExp);
expect(new RegExp(/a/g, 'im')).to.have.property('constructor', RegExp);
});
it('toStrings properly', function () {
expect(Object.prototype.toString.call(/a/g)).to.equal('[object RegExp]');
expect(Object.prototype.toString.call(new RegExp('a', 'g'))).to.equal('[object RegExp]');
expect(Object.prototype.toString.call(new RegExp(/a/g, 'im'))).to.equal('[object RegExp]');
});
it('functions as a boxed primitive wrapper', function () {
var regex = /a/g;
expect(RegExp(regex)).to.equal(regex);
});
ifSymbolsDescribe('Symbol.replace', function () {
if (!hasSymbols || typeof Symbol.replace === 'undefined') {
return;
}
it('is a function', function () {
expect(RegExp.prototype).to.have.property(Symbol.replace);
expect(typeof RegExp.prototype[Symbol.replace]).to.equal('function');
});
it('is the same as String#replace', function () {
var regex = /a/g;
var str = 'abc';
var symbolReplace = regex[Symbol.replace](str);
var stringReplace = str.replace(regex);
expect(Object.keys(symbolReplace)).to.eql(Object.keys(stringReplace));
expect(symbolReplace).to.eql(stringReplace);
});
});
ifSymbolsDescribe('Symbol.search', function () {
if (!hasSymbols || typeof Symbol.search === 'undefined') {
return;
}
it('is a function', function () {
expect(RegExp.prototype).to.have.property(Symbol.search);
expect(typeof RegExp.prototype[Symbol.search]).to.equal('function');
});
it('is the same as String#search', function () {
var regex = /a/g;
var str = 'abc';
var symbolSearch = regex[Symbol.search](str);
var stringSearch = str.search(regex);
expect(Object.keys(symbolSearch)).to.eql(Object.keys(stringSearch));
expect(symbolSearch).to.eql(stringSearch);
});
});
ifSymbolsDescribe('Symbol.split', function () {
if (!hasSymbols || typeof Symbol.split === 'undefined') {
return;
}
it('is a function', function () {
expect(RegExp.prototype).to.have.property(Symbol.split);
expect(typeof RegExp.prototype[Symbol.split]).to.equal('function');
});
it('is the same as String#split', function () {
var regex = /a/g;
var str = 'abcabc';
var symbolSplit = regex[Symbol.split](str, 1);
var stringSplit = str.split(regex, 1);
expect(Object.keys(symbolSplit)).to.eql(Object.keys(stringSplit));
expect(symbolSplit).to.eql(stringSplit);
});
});
ifSymbolsDescribe('Symbol.match', function () {
if (!hasSymbols || typeof Symbol.match === 'undefined') {
return;
}
var regexFalsyMatch;
var nonregexTruthyMatch;
beforeEach(function () {
regexFalsyMatch = /./;
regexFalsyMatch[Symbol.match] = false;
nonregexTruthyMatch = { constructor: RegExp };
nonregexTruthyMatch[Symbol.match] = true;
});
it('is a function', function () {
expect(RegExp.prototype).to.have.property(Symbol.match);
expect(typeof RegExp.prototype[Symbol.match]).to.equal('function');
});
it('is the same as String#match', function () {
var regex = /a/g;
var str = 'abc';
var symbolMatch = regex[Symbol.match](str);
var stringMatch = str.match(regex);
expect(Object.keys(symbolMatch)).to.eql(Object.keys(stringMatch));
expect(symbolMatch).to.eql(stringMatch);
});
it('function does not passthrough regexes with a falsy Symbol.match', function () {
expect(RegExp(regexFalsyMatch)).not.to.equal(regexFalsyMatch);
});
it('constructor does not passthrough regexes with a falsy Symbol.match', function () {
expect(new RegExp(regexFalsyMatch)).not.to.equal(regexFalsyMatch);
});
it('function passes through non-regexes with a truthy Symbol.match', function () {
expect(RegExp(nonregexTruthyMatch)).to.equal(nonregexTruthyMatch);
});
it('constructor does not pass through non-regexes with a truthy Symbol.match', function () {
expect(new RegExp(nonregexTruthyMatch)).not.to.equal(nonregexTruthyMatch);
});
});
});
describeIfSupportsDescriptors('#flags', function () {
if (!Object.prototype.hasOwnProperty.call(RegExp.prototype, 'flags')) {
return it('exists', function () {
expect(RegExp.prototype).to.have.property('flags');
});
}
var regexpFlagsDescriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
var testGenericRegExpFlags = function (object) {
return regexpFlagsDescriptor.get.call(object);
};
it('has the correct descriptor', function () {
expect(regexpFlagsDescriptor.configurable).to.equal(true);
expect(regexpFlagsDescriptor.enumerable).to.equal(false);
expect(regexpFlagsDescriptor.get instanceof Function).to.equal(true);
expect(regexpFlagsDescriptor.set).to.equal(undefined);
});
ifCallAllowsPrimitivesIt('throws when not called on an object', function () {
var nonObjects = ['', false, true, 42, NaN, null, undefined];
nonObjects.forEach(function (nonObject) {
expect(function () { testGenericRegExpFlags(nonObject); }).to['throw'](TypeError);
});
});
it('has the correct flags on a literal', function () {
expect((/a/g).flags).to.equal('g');
expect((/a/i).flags).to.equal('i');
expect((/a/m).flags).to.equal('m');
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'sticky')) {
expect(getRegexLiteral('/a/y').flags).to.equal('y');
}
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'unicode')) {
expect(getRegexLiteral('/a/u').flags).to.equal('u');
}
});
it('has the correct flags on a constructed RegExp', function () {
expect(new RegExp('a', 'g').flags).to.equal('g');
expect(new RegExp('a', 'i').flags).to.equal('i');
expect(new RegExp('a', 'm').flags).to.equal('m');
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'sticky')) {
expect(new RegExp('a', 'y').flags).to.equal('y');
}
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'unicode')) {
expect(new RegExp('a', 'u').flags).to.equal('u');
}
});
it('returns flags sorted on a literal', function () {
expect((/a/gim).flags).to.equal('gim');
expect((/a/mig).flags).to.equal('gim');
expect((/a/mgi).flags).to.equal('gim');
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'sticky')) {
expect(getRegexLiteral('/a/gyim').flags).to.equal('gimy');
}
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'unicode')) {
expect(getRegexLiteral('/a/ugmi').flags).to.equal('gimu');
}
});
it('returns flags sorted on a constructed RegExp', function () {
expect(new RegExp('a', 'gim').flags).to.equal('gim');
expect(new RegExp('a', 'mig').flags).to.equal('gim');
expect(new RegExp('a', 'mgi').flags).to.equal('gim');
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'sticky')) {
expect(new RegExp('a', 'mygi').flags).to.equal('gimy');
}
if (Object.prototype.hasOwnProperty.call(RegExp.prototype, 'unicode')) {
expect(new RegExp('a', 'mugi').flags).to.equal('gimu');
}
});
});
describe('#toString()', function () {
it('throws on null/undefined', function () {
expect(function () { RegExp.prototype.toString.call(null); }).to['throw'](TypeError);
expect(function () { RegExp.prototype.toString.call(undefined); }).to['throw'](TypeError);
});
it('works on regexes', function () {
expect(RegExp.prototype.toString.call(/a/g)).to.equal('/a/g');
expect(RegExp.prototype.toString.call(new RegExp('a', 'g'))).to.equal('/a/g');
});
it('works on non-regexes', function () {
expect(RegExp.prototype.toString.call({ source: 'abc', flags: '' })).to.equal('/abc/');
expect(RegExp.prototype.toString.call({ source: 'abc', flags: 'xyz' })).to.equal('/abc/xyz');
});
ifSymbolsDescribe('Symbol.match', function () {
if (!hasSymbols || typeof Symbol.match === 'undefined') {
return;
}
it('accepts a non-regex with Symbol.match', function () {
var obj = { source: 'abc', flags: 'def' };
obj[Symbol.match] = RegExp.prototype[Symbol.match];
expect(RegExp.prototype.toString.call(obj)).to.equal('/abc/def');
});
});
});
describe('Object properties', function () {
it('does not have the nonstandard $input property', function () {
expect(RegExp).not.to.have.property('$input'); // Chrome < 39, Opera < 26 have this
});
it('has "input" property', function () {
expect(RegExp).to.have.ownProperty('input');
expect(RegExp).to.have.ownProperty('$_');
});
it('has "last match" property', function () {
expect(RegExp).to.have.ownProperty('lastMatch');
expect(RegExp).to.have.ownProperty('$+');
});
it('has "last paren" property', function () {
expect(RegExp).to.have.ownProperty('lastParen');
expect(RegExp).to.have.ownProperty('$&');
});
it('has "leftContext" property', function () {
expect(RegExp).to.have.ownProperty('leftContext');
expect(RegExp).to.have.ownProperty('$`');
});
it('has "rightContext" property', function () {
expect(RegExp).to.have.ownProperty('rightContext');
expect(RegExp).to.have.ownProperty("$'");
});
it.skip('has "multiline" property', function () {
// fails in IE 9, 10, 11
expect(RegExp).to.have.ownProperty('multiline');
expect(RegExp).to.have.ownProperty('$*');
});
it('has the right globals', function () {
var matchVars = [
'$1',
'$2',
'$3',
'$4',
'$5',
'$6',
'$7',
'$8',
'$9'
];
matchVars.forEach(function (match) {
expect(RegExp).to.have.property(match);
});
});
describe('updates RegExp globals', function () {
var str = 'abcdefghijklmnopq';
var re;
beforeEach(function () {
re = /(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)/;
re.exec(str);
});
it('has "input"', function () {
expect(RegExp.input).to.equal(str);
expect(RegExp.$_).to.equal(str);
});
it('has "multiline"', function () {
if (Object.prototype.hasOwnProperty.call(RegExp, 'multiline')) {
expect(RegExp.multiline).to.equal(false);
}
if (Object.prototype.hasOwnProperty.call(RegExp, '$*')) {
expect(RegExp['$*']).to.equal(false);
}
});
it('has "lastMatch"', function () {
expect(RegExp.lastMatch).to.equal('bcdefghijklmnop');
expect(RegExp['$&']).to.equal('bcdefghijklmnop');
});
// in all but IE, this works. IE lastParen breaks after 11 tokens.
it.skip('has "lastParen"', function () {
expect(RegExp.lastParen).to.equal('p');
expect(RegExp['$+']).to.equal('p');
});
it('has "lastParen" for less than 11 tokens', function () {
(/(b)(c)(d)/).exec('abcdef');
expect(RegExp.lastParen).to.equal('d');
expect(RegExp['$+']).to.equal('d');
});
it('has "leftContext"', function () {
expect(RegExp.leftContext).to.equal('a');
expect(RegExp['$`']).to.equal('a');
});
it('has "rightContext"', function () {
expect(RegExp.rightContext).to.equal('q');
expect(RegExp["$'"]).to.equal('q');
});
it('has $1 - $9', function () {
expect(RegExp.$1).to.equal('b');
expect(RegExp.$2).to.equal('c');
expect(RegExp.$3).to.equal('d');
expect(RegExp.$4).to.equal('e');
expect(RegExp.$5).to.equal('f');
expect(RegExp.$6).to.equal('g');
expect(RegExp.$7).to.equal('h');
expect(RegExp.$8).to.equal('i');
expect(RegExp.$9).to.equal('j');
});
});
});
});

637
node_modules/es6-shim/test/set.js generated vendored Normal file
View File

@ -0,0 +1,637 @@
// Big thanks to V8 folks for test ideas.
// v8/test/mjsunit/harmony/collections.js
var Assertion = expect().constructor;
Assertion.addMethod('theSameSet', function (otherArray) {
var array = this._obj;
expect(Array.isArray(array)).to.equal(true);
expect(Array.isArray(otherArray)).to.equal(true);
var diff = array.filter(function (value) {
return otherArray.every(function (otherValue) {
var areBothNaN = typeof value === 'number' && typeof otherValue === 'number' && value !== value && otherValue !== otherValue;
return !areBothNaN && value !== otherValue;
});
});
this.assert(
diff.length === 0,
'expected #{this} to be equal to #{exp} (as sets, i.e. no order)',
array,
otherArray
);
});
var $iterator$ = typeof Symbol === 'function' ? Symbol.iterator : void 0;
if (!$iterator$ && typeof Set === 'function') {
$iterator$ = typeof Set['@@iterator'] === 'function' ? '@@iterator' : '_es6-shim iterator_';
}
Assertion.addMethod('iterations', function (expected) {
var iterator = this._obj[$iterator$]();
expect(Array.isArray(expected)).to.equal(true);
var expectedValues = expected.slice();
var result;
do {
result = iterator.next();
expect(result.value).to.eql(expectedValues.shift());
} while (!result.done);
});
describe('Set', function () {
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
var range = function (from, to) {
var result = [];
for (var value = from; value < to; value++) {
result.push(value);
}
return result;
};
var prototypePropIsEnumerable = Object.prototype.propertyIsEnumerable.call(function () {}, 'prototype');
var expectNotEnumerable = function (object) {
if (prototypePropIsEnumerable && typeof object === 'function') {
expect(Object.keys(object)).to.eql(['prototype']);
} else {
expect(Object.keys(object)).to.eql([]);
}
};
var Sym = typeof Symbol === 'undefined' ? {} : Symbol;
var isSymbol = function (sym) {
return typeof Sym === 'function' && typeof sym === 'symbol';
};
var ifSymbolIteratorIt = isSymbol(Sym.iterator) ? it : xit;
var testSet = function (set, key) {
expect(set.has(key)).to.equal(false);
expect(set['delete'](key)).to.equal(false);
expect(set.add(key)).to.equal(set);
expect(set.has(key)).to.equal(true);
expect(set['delete'](key)).to.equal(true);
expect(set.has(key)).to.equal(false);
expect(set.add(key)).to.equal(set); // add it back
};
if (typeof Set === 'undefined') {
return it('exists', function () {
expect(typeof Set).to.equal('function');
});
}
var set;
beforeEach(function () {
set = new Set();
});
afterEach(function () {
set = null;
});
it('set iteration', function () {
expect(set.add('a')).to.equal(set);
expect(set.add('b')).to.equal(set);
expect(set.add('c')).to.equal(set);
expect(set.add('d')).to.equal(set);
var keys = [];
var iterator = set.keys();
keys.push(iterator.next().value);
expect(set['delete']('a')).to.equal(true);
expect(set['delete']('b')).to.equal(true);
expect(set['delete']('c')).to.equal(true);
expect(set.add('e')).to.equal(set);
keys.push(iterator.next().value);
keys.push(iterator.next().value);
expect(iterator.next().done).to.equal(true);
expect(set.add('f')).to.equal(set);
expect(iterator.next().done).to.equal(true);
expect(keys).to.eql(['a', 'd', 'e']);
});
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.Set).to.equal(Set);
});
it('should exist in global namespace', function () {
expect(typeof Set).to.equal('function');
});
it('has the right arity', function () {
expect(Set).to.have.property('length', 0);
});
it('returns the set from #add() for chaining', function () {
expect(set.add({})).to.equal(set);
});
it('should return false when deleting an item not in the set', function () {
expect(set.has('a')).to.equal(false);
expect(set['delete']('a')).to.equal(false);
});
it('should accept an iterable as argument', function () {
testSet(set, 'a');
testSet(set, 'b');
var set2 = new Set(set);
expect(set2.has('a')).to.equal(true);
expect(set2.has('b')).to.equal(true);
expect(set2).to.have.iterations(['a', 'b']);
});
it('accepts an array as an argument', function () {
var arr = ['a', 'b', 'c'];
var setFromArray = new Set(arr);
expect(setFromArray).to.have.iterations(['a', 'b', 'c']);
});
it('should not be callable without "new"', function () {
expect(Set).to['throw'](TypeError);
});
it('should be subclassable', function () {
if (!Object.setPrototypeOf) { return; } // skip test if on IE < 11
var MySet = function MySet() {
var actualSet = new Set(['a', 'b']);
Object.setPrototypeOf(actualSet, MySet.prototype);
return actualSet;
};
Object.setPrototypeOf(MySet, Set);
MySet.prototype = Object.create(Set.prototype, {
constructor: { value: MySet }
});
var mySet = new MySet();
testSet(mySet, 'c');
testSet(mySet, 'd');
expect(mySet).to.have.iterations(['a', 'b', 'c', 'd']);
});
it('should has valid getter and setter calls', function () {
['add', 'has', 'delete'].forEach(function (method) {
expect(function () {
set[method]({});
}).to.not['throw']();
});
});
it('uses SameValueZero even on a Set of size > 4', function () {
var firstFour = [1, 2, 3, 4];
var fourSet = new Set(firstFour);
expect(fourSet.size).to.equal(4);
expect(fourSet.has(-0)).to.equal(false);
expect(fourSet.has(0)).to.equal(false);
fourSet.add(-0);
expect(fourSet.size).to.equal(5);
expect(fourSet.has(0)).to.equal(true);
expect(fourSet.has(-0)).to.equal(true);
});
it('should work as expected', function () {
// Run this test twice, one with the "fast" implementation (which only
// allows string and numeric keys) and once with the "slow" impl.
[true, false].forEach(function (slowkeys) {
set = new Set();
range(1, 20).forEach(function (number) {
if (slowkeys) { testSet(set, {}); }
testSet(set, number);
testSet(set, number / 100);
testSet(set, 'key-' + number);
testSet(set, String(number));
if (slowkeys) { testSet(set, Object(String(number))); }
});
var testkeys = [+0, Infinity, -Infinity, NaN];
if (slowkeys) {
testkeys.push(true, false, null, undefined);
}
testkeys.forEach(function (number) {
testSet(set, number);
testSet(set, String(number));
});
testSet(set, '');
// -0 and +0 should be the same key (Set uses SameValueZero)
expect(set.has(-0)).to.equal(true);
expect(set['delete'](+0)).to.equal(true);
testSet(set, -0);
expect(set.has(+0)).to.equal(true);
// verify that properties of Object don't peek through.
[
'hasOwnProperty',
'constructor',
'toString',
'isPrototypeOf',
'__proto__',
'__parent__',
'__count__'
].forEach(function (prop) { testSet(set, prop); });
});
});
describe('#size', function () {
it('returns the expected size', function () {
expect(set.add(1)).to.equal(set);
expect(set.add(5)).to.equal(set);
expect(set.size).to.equal(2);
});
});
describe('#clear()', function () {
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Set.prototype.clear).to.have.property('name', 'clear');
});
it('is not enumerable', function () {
expect(Set.prototype).ownPropertyDescriptor('clear').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Set.prototype.clear).to.have.property('length', 0);
});
it('clears a Set with only primitives', function () {
expect(set.add(1)).to.equal(set);
expect(set.size).to.equal(1);
expect(set.add(5)).to.equal(set);
expect(set.size).to.equal(2);
expect(set.has(5)).to.equal(true);
set.clear();
expect(set.size).to.equal(0);
expect(set.has(5)).to.equal(false);
});
it('clears a Set with primitives and objects', function () {
expect(set.add(1)).to.equal(set);
expect(set.size).to.equal(1);
var obj = {};
expect(set.add(obj)).to.equal(set);
expect(set.size).to.equal(2);
expect(set.has(obj)).to.equal(true);
set.clear();
expect(set.size).to.equal(0);
expect(set.has(obj)).to.equal(false);
});
});
describe('#keys()', function () {
if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'keys')) {
return it('exists', function () {
expect(Set.prototype).to.have.property('keys');
});
}
it('is the same object as #values()', function () {
expect(Set.prototype.keys).to.equal(Set.prototype.values);
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Set.prototype.keys).to.have.property('name', 'values');
});
it('is not enumerable', function () {
expect(Set.prototype).ownPropertyDescriptor('keys').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Set.prototype.keys).to.have.property('length', 0);
});
});
describe('#values()', function () {
if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'values')) {
return it('exists', function () {
expect(Set.prototype).to.have.property('values');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Set.prototype.values).to.have.property('name', 'values');
});
it('is not enumerable', function () {
expect(Set.prototype).ownPropertyDescriptor('values').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Set.prototype.values).to.have.property('length', 0);
});
it('throws when called on a non-Set', function () {
var expectedMessage = /^(Method )?Set.prototype.values called on incompatible receiver |^values method called on incompatible |^Cannot create a Set value iterator for a non-Set object.$|^Set.prototype.values: 'this' is not a Set object$|^std_Set_iterator method called on incompatible \w+$/;
var nonSets = [true, false, 'abc', NaN, new Map([[1, 2]]), { a: true }, [1], Object('abc'), Object(NaN)];
nonSets.forEach(function (nonSet) {
expect(function () { return Set.prototype.values.call(nonSet); }).to['throw'](TypeError, expectedMessage);
});
});
});
describe('#entries()', function () {
if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'entries')) {
return it('exists', function () {
expect(Set.prototype).to.have.property('entries');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Set.prototype.entries).to.have.property('name', 'entries');
});
it('is not enumerable', function () {
expect(Set.prototype).ownPropertyDescriptor('entries').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Set.prototype.entries).to.have.property('length', 0);
});
});
describe('#has()', function () {
if (!Object.prototype.hasOwnProperty.call(Set.prototype, 'has')) {
return it('exists', function () {
expect(Set.prototype).to.have.property('has');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Set.prototype.has).to.have.property('name', 'has');
});
it('is not enumerable', function () {
expect(Set.prototype).ownPropertyDescriptor('has').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Set.prototype.has).to.have.property('length', 1);
});
});
it('should allow NaN values as keys', function () {
expect(set.has(NaN)).to.equal(false);
expect(set.has(NaN + 1)).to.equal(false);
expect(set.has(23)).to.equal(false);
expect(set.add(NaN)).to.equal(set);
expect(set.has(NaN)).to.equal(true);
expect(set.has(NaN + 1)).to.equal(true);
expect(set.has(23)).to.equal(false);
});
it('should not have [[Enumerable]] props', function () {
expectNotEnumerable(Set);
expectNotEnumerable(Set.prototype);
expectNotEnumerable(new Set());
});
it('should not have an own constructor', function () {
var s = new Set();
expect(s).not.to.haveOwnPropertyDescriptor('constructor');
expect(s.constructor).to.equal(Set);
});
it('should allow common ecmascript idioms', function () {
expect(set instanceof Set).to.equal(true);
expect(typeof Set.prototype.add).to.equal('function');
expect(typeof Set.prototype.has).to.equal('function');
expect(typeof Set.prototype['delete']).to.equal('function');
});
it('should have a unique constructor', function () {
expect(Set.prototype).to.not.equal(Object.prototype);
});
describe('has an iterator that works with Array.from', function () {
if (!Object.prototype.hasOwnProperty.call(Array, 'from')) {
return it('requires Array.from to exist', function () {
expect(Array).to.have.property('from');
});
}
var values = [1, NaN, false, true, null, undefined, 'a'];
it('works with the full set', function () {
expect(new Set(values)).to.have.iterations(values);
});
it('works with Set#keys()', function () {
expect(new Set(values).keys()).to.have.iterations(values);
});
it('works with Set#values()', function () {
expect(new Set(values).values()).to.have.iterations(values);
});
it('works with Set#entries()', function () {
expect(new Set(values).entries()).to.have.iterations([
[1, 1],
[NaN, NaN],
[false, false],
[true, true],
[null, null],
[undefined, undefined],
['a', 'a']
]);
});
});
ifSymbolIteratorIt('has the right default iteration function', function () {
// fixed in Webkit https://bugs.webkit.org/show_bug.cgi?id=143838
expect(Set.prototype).to.have.property(Sym.iterator, Set.prototype.values);
});
it('should preserve insertion order', function () {
var arr1 = ['d', 'a', 'b'];
var arr2 = [3, 2, 'z', 'a', 1];
var arr3 = [3, 2, 'z', {}, 'a', 1];
[arr1, arr2, arr3].forEach(function (array) {
expect(new Set(array)).to.have.iterations(array);
});
});
describe('#forEach', function () {
var setToIterate;
beforeEach(function () {
setToIterate = new Set();
expect(setToIterate.add('a')).to.equal(setToIterate);
expect(setToIterate.add('b')).to.equal(setToIterate);
expect(setToIterate.add('c')).to.equal(setToIterate);
});
afterEach(function () {
setToIterate = null;
});
ifFunctionsHaveNamesIt('has the right name', function () {
expect(Set.prototype.forEach).to.have.property('name', 'forEach');
});
it('is not enumerable', function () {
expect(Set.prototype).ownPropertyDescriptor('forEach').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(Set.prototype.forEach).to.have.property('length', 1);
});
it('should be iterable via forEach', function () {
var expectedSet = ['a', 'b', 'c'];
var foundSet = [];
setToIterate.forEach(function (value, alsoValue, entireSet) {
expect(entireSet).to.equal(setToIterate);
expect(value).to.equal(alsoValue);
foundSet.push(value);
});
expect(foundSet).to.eql(expectedSet);
});
it('should iterate over empty keys', function () {
var setWithEmptyKeys = new Set();
var expectedKeys = [{}, null, undefined, '', NaN, 0];
expectedKeys.forEach(function (key) {
expect(setWithEmptyKeys.add(key)).to.equal(setWithEmptyKeys);
});
var foundKeys = [];
setWithEmptyKeys.forEach(function (value, key, entireSet) {
expect([key]).to.be.theSameSet([value]); // handles NaN correctly
expect(entireSet.has(key)).to.equal(true);
foundKeys.push(key);
});
expect(foundKeys).to.be.theSameSet(expectedKeys);
});
it('should support the thisArg', function () {
var context = function () {};
setToIterate.forEach(function () {
expect(this).to.equal(context);
}, context);
});
it('should have a length of 1', function () {
expect(Set.prototype.forEach.length).to.equal(1);
});
it('should not revisit modified keys', function () {
var hasModifiedA = false;
setToIterate.forEach(function (value, key) {
if (!hasModifiedA && key === 'a') {
expect(setToIterate.add('a')).to.equal(setToIterate);
hasModifiedA = true;
} else {
expect(key).not.to.equal('a');
}
});
});
it('visits keys added in the iterator', function () {
var hasAdded = false;
var hasFoundD = false;
setToIterate.forEach(function (value, key) {
if (!hasAdded) {
expect(setToIterate.add('d')).to.equal(setToIterate);
hasAdded = true;
} else if (key === 'd') {
hasFoundD = true;
}
});
expect(hasFoundD).to.equal(true);
});
it('visits keys added in the iterator when there is a deletion (slow path)', function () {
var hasSeenFour = false;
var setToMutate = new Set();
expect(setToMutate.add({})).to.equal(setToMutate); // force use of the slow O(N) implementation
expect(setToMutate.add('0')).to.equal(setToMutate);
setToMutate.forEach(function (value, key) {
if (key === '0') {
expect(setToMutate['delete']('0')).to.equal(true);
expect(setToMutate.add('4')).to.equal(setToMutate);
} else if (key === '4') {
hasSeenFour = true;
}
});
expect(hasSeenFour).to.equal(true);
});
it('visits keys added in the iterator when there is a deletion (fast path)', function () {
var hasSeenFour = false;
var setToMutate = new Set();
expect(setToMutate.add('0')).to.equal(setToMutate);
setToMutate.forEach(function (value, key) {
if (key === '0') {
expect(setToMutate['delete']('0')).to.equal(true);
expect(setToMutate.add('4')).to.equal(setToMutate);
} else if (key === '4') {
hasSeenFour = true;
}
});
expect(hasSeenFour).to.equal(true);
});
it('does not visit keys deleted before a visit', function () {
var hasVisitedC = false;
var hasDeletedC = false;
setToIterate.forEach(function (value, key) {
if (key === 'c') {
hasVisitedC = true;
}
if (!hasVisitedC && !hasDeletedC) {
hasDeletedC = setToIterate['delete']('c');
expect(hasDeletedC).to.equal(true);
}
});
expect(hasVisitedC).to.equal(false);
});
it('should work after deletion of the current key', function () {
var expectedSet = {
a: 'a',
b: 'b',
c: 'c'
};
var foundSet = {};
setToIterate.forEach(function (value, key) {
foundSet[key] = value;
expect(setToIterate['delete'](key)).to.equal(true);
});
expect(foundSet).to.eql(expectedSet);
});
it('should convert key -0 to +0', function () {
var zeroSet = new Set();
var result = [];
expect(zeroSet.add(-0)).to.equal(zeroSet);
zeroSet.forEach(function (key) {
result.push(String(1 / key));
});
expect(zeroSet.add(1)).to.equal(zeroSet);
expect(zeroSet.add(0)).to.equal(zeroSet); // shouldn't cause reordering
zeroSet.forEach(function (key) {
result.push(String(1 / key));
});
expect(result.join(', ')).to.equal(
'Infinity, Infinity, 1'
);
});
});
it('Set.prototype.size should throw TypeError', function () {
// see https://github.com/paulmillr/es6-shim/issues/176
expect(function () { return Set.prototype.size; }).to['throw'](TypeError);
expect(function () { return Set.prototype.size; }).to['throw'](TypeError);
});
it.skip('should throw proper errors when user invokes methods with wrong types of receiver', function () {
});
});

929
node_modules/es6-shim/test/string.js generated vendored Normal file
View File

@ -0,0 +1,929 @@
var runStringTests = function (it) {
'use strict';
var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : it.skip;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
var hasSymbols = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' && typeof Symbol.iterator === 'symbol';
var ifSymbolsDescribe = hasSymbols ? describe : describe.skip;
describe('String', function () {
var hasStrictMode = (function () { return this === null; }.call(null));
var testObjectCoercible = function (methodName) {
var fn = String.prototype[methodName];
if (!hasStrictMode) { return; } // skip these tests on IE <= 10
expect(function () { return fn.call(undefined); }).to['throw'](TypeError);
expect(function () { return fn.call(null); }).to['throw'](TypeError);
expect(function () { return fn.apply(undefined); }).to['throw'](TypeError);
expect(function () { return fn.apply(null); }).to['throw'](TypeError);
};
ifShimIt('is on the exported object', function () {
var exported = require('../');
expect(exported.String).to.equal(String);
});
describe('#repeat()', function () {
if (!Object.prototype.hasOwnProperty.call(String.prototype, 'repeat')) {
return it('exists', function () {
expect(String.prototype).to.have.property('repeat');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.prototype.repeat).to.have.property('name', 'repeat');
});
it('is not enumerable', function () {
expect(String.prototype).ownPropertyDescriptor('repeat').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(String.prototype.repeat).to.have.property('length', 1);
});
it('should throw a TypeError when called on null or undefined', function () {
testObjectCoercible('repeat');
});
it('should throw a RangeError when negative or infinite', function () {
expect(function negativeOne() { return 'test'.repeat(-1); }).to['throw'](RangeError);
expect(function infinite() { return 'test'.repeat(Infinity); }).to['throw'](RangeError);
});
it('should coerce to an integer', function () {
expect('test'.repeat(null)).to.eql('');
expect('test'.repeat(false)).to.eql('');
expect('test'.repeat('')).to.eql('');
expect('test'.repeat(NaN)).to.eql('');
expect('test'.repeat({})).to.eql('');
expect('test'.repeat([])).to.eql('');
expect('test'.repeat({
valueOf: function () { return 2; }
})).to.eql('testtest');
});
it('should work', function () {
expect('test'.repeat(3)).to.eql('testtesttest');
});
it('should work on integers', function () {
expect(String.prototype.repeat.call(2, 3)).to.eql('222');
});
it('should work on booleans', function () {
expect(String.prototype.repeat.call(true, 3)).to.eql('truetruetrue');
});
it('should work on dates', function () {
var d = new Date();
expect(String.prototype.repeat.call(d, 3)).to.eql([d, d, d].join(''));
});
});
describe('#startsWith()', function () {
if (!Object.prototype.hasOwnProperty.call(String.prototype, 'startsWith')) {
return it('exists', function () {
expect(String.prototype).to.have.property('startsWith');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.prototype.startsWith).to.have.property('name', 'startsWith');
});
it('is not enumerable', function () {
expect(String.prototype).ownPropertyDescriptor('startsWith').to.have.property('enumerable', false);
});
it('has the right arity', function () {
// WebKit nightly had this bug, fixed in https://bugs.webkit.org/show_bug.cgi?id=143659
expect(String.prototype.startsWith).to.have.property('length', 1);
});
it('should throw a TypeError when called on null or undefined', function () {
testObjectCoercible('startsWith');
});
it('should throw a TypeError when called on null or undefined', function () {
testObjectCoercible('startsWith');
});
it('should be truthy on correct results', function () {
expect('test'.startsWith('te')).to.equal(true);
expect('test'.startsWith('st')).to.equal(false);
expect(''.startsWith('/')).to.equal(false);
expect('#'.startsWith('/')).to.equal(false);
expect('##'.startsWith('///')).to.equal(false);
expect('abc'.startsWith('abc')).to.equal(true);
expect('abcd'.startsWith('abc')).to.equal(true);
expect('abc'.startsWith('a')).to.equal(true);
expect('abc'.startsWith('abcd')).to.equal(false);
expect('abc'.startsWith('bcde')).to.equal(false);
expect('abc'.startsWith('b')).to.equal(false);
expect('abc'.startsWith('abc', 0)).to.equal(true);
expect('abc'.startsWith('bc', 0)).to.equal(false);
expect('abc'.startsWith('bc', 1)).to.equal(true);
expect('abc'.startsWith('c', 1)).to.equal(false);
expect('abc'.startsWith('abc', 1)).to.equal(false);
expect('abc'.startsWith('c', 2)).to.equal(true);
expect('abc'.startsWith('d', 2)).to.equal(false);
expect('abc'.startsWith('dcd', 2)).to.equal(false);
expect('abc'.startsWith('a', NaN)).to.equal(true);
expect('abc'.startsWith('b', NaN)).to.equal(false);
expect('abc'.startsWith('ab', -43)).to.equal(true);
expect('abc'.startsWith('ab', -Infinity)).to.equal(true);
expect('abc'.startsWith('bc', -42)).to.equal(false);
expect('abc'.startsWith('bc', -Infinity)).to.equal(false);
if (hasStrictMode) {
expect(function () {
return ''.startsWith.call(null, 'nu');
}).to['throw'](TypeError);
expect(function () {
return ''.startsWith.call(undefined, 'un');
}).to['throw'](TypeError);
}
var myobj = {
toString: function () { return 'abc'; },
startsWith: String.prototype.startsWith
};
expect(myobj.startsWith('abc')).to.equal(true);
expect(myobj.startsWith('bc')).to.equal(false);
var gotStr = false;
var gotPos = false;
myobj = {
toString: function () {
expect(gotPos).to.equal(false);
gotStr = true;
return 'xyz';
},
startsWith: String.prototype.startsWith
};
var idx = {
valueOf: function () {
expect(gotStr).to.equal(true);
gotPos = true;
return 42;
}
};
myobj.startsWith('elephant', idx);
expect(gotPos).to.equal(true);
});
it('should handle large positions', function () {
expect('abc'.startsWith('a', 42)).to.equal(false);
expect('abc'.startsWith('a', Infinity)).to.equal(false);
});
it('should coerce to a string', function () {
expect('abcd'.startsWith({ toString: function () { return 'ab'; } })).to.equal(true);
expect('abcd'.startsWith({ toString: function () { return 'foo'; } })).to.equal(false);
});
it('should not allow a regex', function () {
expect(function () { return 'abcd'.startsWith(/abc/); }).to['throw'](TypeError);
expect(function () { return 'abcd'.startsWith(new RegExp('abc')); }).to['throw'](TypeError);
});
ifSymbolsDescribe('Symbol.match', function () {
if (!hasSymbols || !Symbol.match) {
return it('exists', function () {
expect(Symbol).to.have.property('match');
});
}
it('allows a regex with Symbol.match set to a falsy value', function () {
var re = /a/g;
re[Symbol.match] = false;
expect(function () { return 'abcd'.startsWith(re); }).not.to['throw']();
expect('abcd'.startsWith(re)).to.equal('abcd'.startsWith(String(re)));
});
});
});
describe('#endsWith()', function () {
if (!Object.prototype.hasOwnProperty.call(String.prototype, 'endsWith')) {
return it('exists', function () {
expect(String.prototype).to.have.property('endsWith');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.prototype.endsWith).to.have.property('name', 'endsWith');
});
it('is not enumerable', function () {
expect(String.prototype).ownPropertyDescriptor('endsWith').to.have.property('enumerable', false);
});
it('has the right arity', function () {
// WebKit nightly had this bug, fixed in https://bugs.webkit.org/show_bug.cgi?id=143659
expect(String.prototype.endsWith).to.have.property('length', 1);
});
it('should throw a TypeError when called on null or undefined', function () {
testObjectCoercible('endsWith');
});
it('should be truthy on correct results', function () {
expect('test'.endsWith('st')).to.equal(true);
expect('test'.endsWith('te')).to.equal(false);
expect(''.endsWith('/')).to.equal(false);
expect('#'.endsWith('/')).to.equal(false);
expect('##'.endsWith('///')).to.equal(false);
expect('abc'.endsWith('abc')).to.equal(true);
expect('abcd'.endsWith('bcd')).to.equal(true);
expect('abc'.endsWith('c')).to.equal(true);
expect('abc'.endsWith('abcd')).to.equal(false);
expect('abc'.endsWith('bbc')).to.equal(false);
expect('abc'.endsWith('b')).to.equal(false);
expect('abc'.endsWith('abc', 3)).to.equal(true);
expect('abc'.endsWith('bc', 3)).to.equal(true);
expect('abc'.endsWith('a', 3)).to.equal(false);
expect('abc'.endsWith('bc', 3)).to.equal(true);
expect('abc'.endsWith('a', 1)).to.equal(true);
expect('abc'.endsWith('abc', 1)).to.equal(false);
expect('abc'.endsWith('b', 2)).to.equal(true);
expect('abc'.endsWith('d', 2)).to.equal(false);
expect('abc'.endsWith('dcd', 2)).to.equal(false);
expect('abc'.endsWith('bc', undefined)).to.equal(true);
expect('abc'.endsWith('bc', NaN)).to.equal(false);
if (hasStrictMode) {
expect(function () {
return ''.endsWith.call(null, 'ull');
}).to['throw'](TypeError);
expect(function () {
return ''.endsWith.call(undefined, 'ned');
}).to['throw'](TypeError);
}
var myobj = {
toString: function () { return 'abc'; },
endsWith: String.prototype.endsWith
};
expect(myobj.endsWith('abc')).to.equal(true);
expect(myobj.endsWith('ab')).to.equal(false);
var gotStr = false;
var gotPos = false;
myobj = {
toString: function () {
expect(gotPos).to.equal(false);
gotStr = true;
return 'xyz';
},
endsWith: String.prototype.endsWith
};
var idx = {
valueOf: function () {
expect(gotStr).to.equal(true);
gotPos = true;
return 42;
}
};
myobj.endsWith('elephant', idx);
expect(gotPos).to.equal(true);
});
it('should coerce to a string', function () {
expect('abcd'.endsWith({ toString: function () { return 'cd'; } })).to.equal(true);
expect('abcd'.endsWith({ toString: function () { return 'foo'; } })).to.equal(false);
});
it('should not allow a regex', function () {
expect(function () { return 'abcd'.endsWith(/abc/); }).to['throw'](TypeError);
expect(function () { return 'abcd'.endsWith(new RegExp('abc')); }).to['throw'](TypeError);
});
it('should handle negative and zero endPositions properly', function () {
expect('abcd'.endsWith('bcd', 0)).to.equal(false);
expect('abcd'.endsWith('bcd', -2)).to.equal(false);
expect('abcd'.endsWith('b', -2)).to.equal(false);
expect('abcd'.endsWith('ab', -2)).to.equal(false);
expect('abc'.endsWith('bc', -43)).to.equal(false);
expect('abc'.endsWith('bc', -Infinity)).to.equal(false);
});
it('should handle large endPositions properly', function () {
expect('abc'.endsWith('a', 42)).to.equal(false);
expect('abc'.endsWith('bc', Infinity)).to.equal(true);
expect('abc'.endsWith('a', Infinity)).to.equal(false);
});
ifSymbolsDescribe('Symbol.match', function () {
if (!hasSymbols || !Symbol.match) {
return it('exists', function () {
expect(Symbol).to.have.property('match');
});
}
it('allows a regex with Symbol.match set to a falsy value', function () {
var re = /a/g;
re[Symbol.match] = false;
expect(function () { return 'abcd'.startsWith(re); }).not.to['throw']();
expect('abcd'.endsWith(re)).to.equal('abcd'.endsWith(String(re)));
});
});
});
describe('#includes()', function () {
if (!Object.prototype.hasOwnProperty.call(String.prototype, 'includes')) {
return it('exists', function () {
expect(String.prototype).to.have.property('includes');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.prototype.includes).to.have.property('name', 'includes');
});
it('is not enumerable', function () {
expect(String.prototype).ownPropertyDescriptor('includes').to.have.property('enumerable', false);
});
it('has the right arity', function () {
// WebKit nightly had this bug, fixed in https://bugs.webkit.org/show_bug.cgi?id=143659
expect(String.prototype.includes).to.have.property('length', 1);
});
it('should throw a TypeError when called on null or undefined', function () {
testObjectCoercible('includes');
});
it('throws a TypeError when given a regex', function () {
expect(function () { 'foo'.includes(/a/g); }).to['throw'](TypeError);
});
it('should be truthy on correct results', function () {
expect('test'.includes('es')).to.equal(true);
expect('abc'.includes('a')).to.equal(true);
expect('abc'.includes('b')).to.equal(true);
expect('abc'.includes('abc')).to.equal(true);
expect('abc'.includes('bc')).to.equal(true);
expect('abc'.includes('d')).to.equal(false);
expect('abc'.includes('abcd')).to.equal(false);
expect('abc'.includes('ac')).to.equal(false);
expect('abc'.includes('abc', 0)).to.equal(true);
expect('abc'.includes('bc', 0)).to.equal(true);
expect('abc'.includes('de', 0)).to.equal(false);
expect('abc'.includes('bc', 1)).to.equal(true);
expect('abc'.includes('c', 1)).to.equal(true);
expect('abc'.includes('a', 1)).to.equal(false);
expect('abc'.includes('abc', 1)).to.equal(false);
expect('abc'.includes('c', 2)).to.equal(true);
expect('abc'.includes('d', 2)).to.equal(false);
expect('abc'.includes('dcd', 2)).to.equal(false);
expect('abc'.includes('ab', NaN)).to.equal(true);
expect('abc'.includes('cd', NaN)).to.equal(false);
var myobj = {
toString: function () { return 'abc'; },
includes: String.prototype.includes
};
expect(myobj.includes('abc')).to.equal(true);
expect(myobj.includes('cd')).to.equal(false);
var gotStr = false;
var gotPos = false;
myobj = {
toString: function () {
expect(gotPos).to.equal(false);
gotStr = true;
return 'xyz';
},
includes: String.prototype.includes
};
var idx = {
valueOf: function () {
expect(gotStr).to.equal(true);
gotPos = true;
return 42;
}
};
myobj.includes('elephant', idx);
expect(gotPos).to.equal(true);
});
it('should handle large positions', function () {
expect('abc'.includes('a', 42)).to.equal(false);
expect('abc'.includes('a', Infinity)).to.equal(false);
});
it('should handle negative positions', function () {
expect('abc'.includes('ab', -43)).to.equal(true);
expect('abc'.includes('cd', -42)).to.equal(false);
expect('abc'.includes('ab', -Infinity)).to.equal(true);
expect('abc'.includes('cd', -Infinity)).to.equal(false);
});
it('should be falsy on incorrect results', function () {
expect('test'.includes('1290')).to.equal(false);
});
ifSymbolsDescribe('Symbol.match', function () {
if (!hasSymbols || !Symbol.match) {
return it('exists', function () {
expect(Symbol).to.have.property('match');
});
}
it('allows a regex with Symbol.match set to a falsy value', function () {
var re = /a/g;
re[Symbol.match] = false;
expect(function () { return 'abcd'.includes(re); }).not.to['throw']();
expect('abcd'.includes(re)).to.equal('abcd'.includes(String(re)));
});
});
});
describe('.fromCodePoint()', function () {
if (!Object.prototype.hasOwnProperty.call(String, 'fromCodePoint')) {
return it('exists', function () {
expect(String).to.have.property('fromCodePoint');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.fromCodePoint).to.have.property('name', 'fromCodePoint');
});
it('is not enumerable', function () {
expect(String).ownPropertyDescriptor('fromCodePoint').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(String.fromCodePoint).to.have.property('length', 1);
});
it('throws a RangeError', function () {
var invalidValues = [
'abc',
{},
-1,
0x10FFFF + 1
];
invalidValues.forEach(function (value) {
expect(function () { return String.fromCodePoint(value); }).to['throw'](RangeError);
});
});
it('returns the empty string with no args', function () {
expect(String.fromCodePoint()).to.equal('');
});
it('works', function () {
var codePoints = [];
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789…?!';
for (var i = 0; i < chars.length; ++i) {
codePoints.push(chars.charCodeAt(i));
expect(String.fromCodePoint(chars.charCodeAt(i))).to.equal(chars[i]);
}
expect(String.fromCodePoint.apply(String, codePoints)).to.equal(chars);
});
it('works with unicode', function () {
expect(String.fromCodePoint(0x2500)).to.equal('\u2500');
expect(String.fromCodePoint(0x010000)).to.equal('\ud800\udc00');
expect(String.fromCodePoint(0x10FFFF)).to.equal('\udbff\udfff');
});
});
describe('#codePointAt()', function () {
if (!Object.prototype.hasOwnProperty.call(String.prototype, 'codePointAt')) {
return it('exists', function () {
expect(String.prototype).to.have.property('codePointAt');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.prototype.codePointAt).to.have.property('name', 'codePointAt');
});
it('is not enumerable', function () {
expect(String.prototype).ownPropertyDescriptor('codePointAt').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(String.prototype.codePointAt).to.have.property('length', 1);
});
it('should throw a TypeError when called on null or undefined', function () {
testObjectCoercible('codePointAt');
});
it('should work', function () {
var str = 'abc';
expect(str.codePointAt(0)).to.equal(97);
expect(str.codePointAt(1)).to.equal(98);
expect(str.codePointAt(2)).to.equal(99);
});
it('should work with unicode', function () {
expect('\u2500'.codePointAt(0)).to.equal(0x2500);
expect('\ud800\udc00'.codePointAt(0)).to.equal(0x10000);
expect('\udbff\udfff'.codePointAt(0)).to.equal(0x10ffff);
expect('\ud800\udc00\udbff\udfff'.codePointAt(0)).to.equal(0x10000);
expect('\ud800\udc00\udbff\udfff'.codePointAt(1)).to.equal(0xdc00);
expect('\ud800\udc00\udbff\udfff'.codePointAt(2)).to.equal(0x10ffff);
expect('\ud800\udc00\udbff\udfff'.codePointAt(3)).to.equal(0xdfff);
});
it('should return undefined when pos is negative or too large', function () {
var str = 'abc';
expect(str.codePointAt(-1)).to.equal(undefined);
expect(str.codePointAt(str.length)).to.equal(undefined);
});
});
describe('#[Symbol.iterator]()', function () {
if (!Object.prototype.hasOwnProperty.call(Array, 'from')) {
return it('requires Array.from to test', function () {
expect(Array).to.have.property('from');
});
}
it('should work with plain strings', function () {
var str = 'abc';
expect(Array.from(str)).to.eql(['a', 'b', 'c']);
});
it('should work with surrogate characters', function () {
var str = '\u2500\ud800\udc00\udbff\udfff\ud800';
expect(Array.from(str)).to.eql(
['\u2500', '\ud800\udc00', '\udbff\udfff', '\ud800']
);
});
});
describe('.raw()', function () {
if (!Object.prototype.hasOwnProperty.call(String, 'raw')) {
return it('exists', function () {
expect(String).to.have.property('raw');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.raw).to.have.property('name', 'raw');
});
it('is not enumerable', function () {
expect(String).ownPropertyDescriptor('raw').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(String.raw).to.have.property('length', 1);
});
it('works with callSite.raw: Array', function () {
var callSite = {};
var str = 'The total is 10 ($11 with tax)';
callSite.raw = ['The total is ', ' ($', ' with tax)'];
expect(String.raw(callSite, 10, 11)).to.eql(str);
// eslint-disable-next-line no-template-curly-in-string
str = 'The total is {total} (${total * 1.01} with tax)';
callSite.raw = ['The total is ', ' ($', ' with tax)'];
expect(String.raw(callSite, '{total}', '{total * 1.01}')).to.eql(str);
});
it('works with callSite.raw: array-like object', function () {
var callSite = {};
var str = 'The total is 10 ($11 with tax)';
callSite.raw = { 0: 'The total is ', 1: ' ($', 2: ' with tax)', length: 3 };
expect(String.raw(callSite, 10, 11)).to.eql(str);
// eslint-disable-next-line no-template-curly-in-string
str = 'The total is {total} (${total * 1.01} with tax)';
callSite.raw = { 0: 'The total is ', 1: ' ($', 2: ' with tax)', length: 3 };
expect(String.raw(callSite, '{total}', '{total * 1.01}')).to.eql(str);
});
it('works with callSite.raw: empty Objects', function () {
var callSite = { raw: {} };
expect(String.raw(callSite, '{total}', '{total * 1.01}')).to.eql('');
expect(String.raw(callSite)).to.equal('');
});
it('ReturnIfAbrupt - Less Substitutions', function () {
var callSite = {
raw: { 0: 'The total is ', 1: ' ($', 2: ' with tax)', length: 3 }
};
var str = 'The total is 10 ($ with tax)';
expect(String.raw(callSite, 10)).to.equal(str);
});
});
describe('#trim()', function () {
if (!Object.prototype.hasOwnProperty.call(String.prototype, 'trim')) {
return it('exists', function () {
expect(String.prototype).to.have.property('trim');
});
}
ifFunctionsHaveNamesIt('has the right name', function () {
expect(String.prototype.trim).to.have.property('name', 'trim');
});
it('is not enumerable', function () {
expect(String.prototype).ownPropertyDescriptor('trim').to.have.property('enumerable', false);
});
it('has the right arity', function () {
expect(String.prototype.trim).to.have.property('length', 0);
});
it('should trim the correct characters', function () {
var whitespace = [
'\u0009',
'\u000b',
'\u000c',
'\u0020',
'\u00a0',
'\u1680',
'\u2000',
'\u2001',
'\u2002',
'\u2003',
'\u2004',
'\u2005',
'\u2006',
'\u2007',
'\u2008',
'\u2009',
'\u200A',
'\u202f',
'\u205f',
'\u3000'
].join('');
var lineTerminators = [
'\u000a',
'\u000d',
'\u2028',
'\u2029'
].join('');
var trimmed = (whitespace + lineTerminators).trim();
expect(trimmed).to.have.property('length', 0);
expect(trimmed).to.equal('');
});
it('should not trim U+0085', function () {
var trimmed = '\u0085'.trim();
expect(trimmed).to.have.property('length', 1);
expect(trimmed).to.equal('\u0085');
});
it('should trim on both sides', function () {
var trimmed = ' a '.trim();
expect(trimmed).to.have.property('length', 1);
expect(trimmed).to.equal('a');
});
});
describe('#search()', function () {
it('works with strings', function () {
expect('abc'.search('a')).to.equal(0);
expect('abc'.search('b')).to.equal(1);
expect('abc'.search('c')).to.equal(2);
expect('abc'.search('d')).to.equal(-1);
});
it('works with regexes', function () {
expect('abc'.search(/a/)).to.equal(0);
expect('abc'.search(/b/)).to.equal(1);
expect('abc'.search(/c/)).to.equal(2);
expect('abc'.search(/d/)).to.equal(-1);
});
ifSymbolsDescribe('Symbol.search', function () {
it('is a symbol', function () {
expect(typeof Symbol.search).to.equal('symbol');
});
if (!hasSymbols || typeof Symbol.search !== 'symbol') {
return;
}
it('is nonconfigurable', function () {
expect(Symbol).ownPropertyDescriptor('search').to.have.property('configurable', false);
});
it('is nonenumerable', function () {
expect(Symbol).ownPropertyDescriptor('search').to.have.property('enumerable', false);
});
it('is nonwritable', function () {
expect(Symbol).ownPropertyDescriptor('search').to.have.property('writable', false);
});
it('is respected', function () {
var str = Object('a');
var obj = {};
obj[Symbol.search] = function (string) { return string === str && this === obj; };
expect(str.search(obj)).to.equal(true);
});
});
});
describe('#replace()', function () {
it('works', function () {
expect('abcabc'.replace('c', 'd')).to.equal('abdabc');
expect('abcabc'.replace(/c/, 'd')).to.equal('abdabc');
expect('abcabc'.replace(/c/g, 'd')).to.equal('abdabd');
expect('abcabc'.replace(/C/ig, 'd')).to.equal('abdabd');
});
ifSymbolsDescribe('Symbol.replace', function () {
it('is a symbol', function () {
expect(typeof Symbol.replace).to.equal('symbol');
});
if (!hasSymbols || typeof Symbol.replace !== 'symbol') {
return;
}
it('is nonconfigurable', function () {
expect(Symbol).ownPropertyDescriptor('replace').to.have.property('configurable', false);
});
it('is nonenumerable', function () {
expect(Symbol).ownPropertyDescriptor('replace').to.have.property('enumerable', false);
});
it('is nonwritable', function () {
expect(Symbol).ownPropertyDescriptor('replace').to.have.property('writable', false);
});
it('respects Symbol.replace', function () {
var str = Object('a');
var replaceVal = Object('replaceValue');
var obj = {};
obj[Symbol.replace] = function (string, replaceValue) {
return string === str && replaceValue === replaceVal && this === obj;
};
expect(str.replace(obj, replaceVal)).to.equal(true);
});
});
});
describe('#split()', function () {
it('works', function () {
expect('abcabc'.split('b')).to.eql(['a', 'ca', 'c']);
expect('abcabc'.split('b', 2)).to.eql(['a', 'ca']);
expect('abcabc'.split(/b.?/)).to.eql(['a', 'a', '']);
expect('abcabc'.split(/b.?/, 2)).to.eql(['a', 'a']);
expect('abcabc'.split(/b/)).to.eql(['a', 'ca', 'c']);
expect('abcabc'.split(/b/, 2)).to.eql(['a', 'ca']);
expect('abcabc'.split(/b/g)).to.eql(['a', 'ca', 'c']);
expect('abcabc'.split(/b/g, 2)).to.eql(['a', 'ca']);
expect('abcabc'.split(/B/i)).to.eql(['a', 'ca', 'c']);
expect('abcabc'.split(/B/i, 2)).to.eql(['a', 'ca']);
expect('abcabc'.split(/B/gi)).to.eql(['a', 'ca', 'c']);
expect('abcabc'.split(/B/gi, 2)).to.eql(['a', 'ca']);
});
ifSymbolsDescribe('Symbol.split', function () {
it('is a symbol', function () {
expect(typeof Symbol.split).to.equal('symbol');
});
if (!hasSymbols || typeof Symbol.split !== 'symbol') {
return;
}
it('is nonconfigurable', function () {
expect(Symbol).ownPropertyDescriptor('split').to.have.property('configurable', false);
});
it('is nonenumerable', function () {
expect(Symbol).ownPropertyDescriptor('split').to.have.property('enumerable', false);
});
it('is nonwritable', function () {
expect(Symbol).ownPropertyDescriptor('split').to.have.property('writable', false);
});
it('respects Symbol.split', function () {
var str = Object('a');
var limitVal = Object(42);
var obj = {};
obj[Symbol.split] = function (string, limit) { return string === str && limit === limitVal && this === obj; };
expect(str.split(obj, limitVal)).to.equal(true);
});
});
});
describe('#match()', function () {
it('works with a string', function () {
var str = 'abca';
var match = str.match('a');
expect(match.index).to.equal(0);
expect(match.input).to.equal(str);
expect(Array.prototype.slice.call(match)).to.eql(['a']);
});
it('works with a regex', function () {
var str = 'abca';
var match = str.match(/a/);
expect(match.index).to.equal(0);
expect(match.input).to.equal(str);
expect(Array.prototype.slice.call(match)).to.eql(['a']);
});
ifSymbolsDescribe('Symbol.match', function () {
it('is a symbol', function () {
expect(typeof Symbol.match).to.equal('symbol');
});
if (!hasSymbols || typeof Symbol.match !== 'symbol') {
return;
}
it('is nonconfigurable', function () {
expect(Symbol).ownPropertyDescriptor('match').to.have.property('configurable', false);
});
it('is nonenumerable', function () {
expect(Symbol).ownPropertyDescriptor('match').to.have.property('enumerable', false);
});
it('is nonwritable', function () {
expect(Symbol).ownPropertyDescriptor('match').to.have.property('writable', false);
});
it('respects Symbol.match', function () {
var str = Object('a');
var obj = {};
obj[Symbol.match] = function (string) { return string === str && this === obj; };
expect(str.match(obj)).to.equal(true);
});
});
});
});
describe('Annex B', function () {
it('has #anchor', function () {
expect('foo'.anchor('bar"baz"')).to.equal('<a name="bar&quot;baz&quot;">foo</a>');
});
it('has #big', function () {
expect('foo'.big()).to.equal('<big>foo</big>');
});
it('has #blink', function () {
expect('foo'.blink()).to.equal('<blink>foo</blink>');
});
it('has #bold', function () {
expect('foo'.bold()).to.equal('<b>foo</b>');
});
it('has #fixed', function () {
expect('foo'.fixed()).to.equal('<tt>foo</tt>');
});
it('has #fontcolor', function () {
expect('foo'.fontcolor('blue"red"green')).to.equal('<font color="blue&quot;red&quot;green">foo</font>');
});
it('has #fontsize', function () {
expect('foo'.fontsize('10"large"small')).to.equal('<font size="10&quot;large&quot;small">foo</font>');
});
it('has #italics', function () {
expect('foo'.italics()).to.equal('<i>foo</i>');
});
it('has #link', function () {
expect('foo'.link('url"http://"')).to.equal('<a href="url&quot;http://&quot;">foo</a>');
});
it('has #small', function () {
expect('foo'.small()).to.equal('<small>foo</small>');
});
it('has #strike', function () {
expect('foo'.strike()).to.equal('<strike>foo</strike>');
});
it('has #sub', function () {
expect('foo'.sub()).to.equal('<sub>foo</sub>');
});
it('has #sup', function () {
expect('foo'.sup()).to.equal('<sup>foo</sup>');
});
});
};
describe('clean Object.prototype', function () {
return runStringTests.call(this, it);
});
describe('polluted Object.prototype', function () {
var shimmedIt = function () {
/* eslint-disable no-extend-native */
Object.prototype[1] = 42;
/* eslint-enable no-extend-native */
it.apply(this, arguments);
delete Object.prototype[1];
};
shimmedIt.skip = it.skip;
return runStringTests.call(this, shimmedIt);
});

17
node_modules/es6-shim/test/test_helpers.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
/* global expect: true, assert: true, require, process */
expect = (function () {
var chai = require('chai');
chai.config.includeStack = true;
return chai.expect;
}());
assert = (function () {
var chai = require('chai');
chai.config.includeStack = true;
return chai.assert;
}());
if (typeof process === 'undefined' || !process.env.NO_ES6_SHIM) {
require('../');
}

7
node_modules/es6-shim/test/worker-runner.workerjs generated vendored Normal file
View File

@ -0,0 +1,7 @@
importScripts(
'../node_modules/es5-shim/es5-shim.js',
'../node_modules/es5-shim/es5-sham.js',
'../es6-shim.js'
);
postMessage('ready');

39
node_modules/es6-shim/test/worker-test.js generated vendored Normal file
View File

@ -0,0 +1,39 @@
/* globals Worker, location */
describe('Worker', function () {
var workerErrorEventToError = function (errorEvent) {
var errorText = 'Error in Worker';
if (errorEvent.filename !== undefined) {
errorText += ' ' + errorEvent.filename;
}
if (errorEvent.lineno !== undefined) {
errorText += '(' + errorEvent.lineno + ')';
}
if (errorEvent.message !== undefined) {
errorText += ': ' + errorEvent.message;
}
return new Error(errorText);
};
var canRunWorkerTestInCurrentContext = function () {
var workerConstructorExists = typeof Worker !== 'undefined';
var locationPropertyExists = typeof location !== 'undefined';
var runningOnFileUriScheme = locationPropertyExists && location.protocol === 'file:';
// The Worker constructor doesn't exist in some older browsers nor does it exist in non-browser contexts like Node.
// Additionally some browsers (at least Chrome) don't allow Workers over file URIs.
// To prevent false negative test failures in the cases where Workers are unavailable for either of those reasons
// we skip this test.
return workerConstructorExists && !runningOnFileUriScheme;
};
if (canRunWorkerTestInCurrentContext()) {
it('can import es6-shim', function (done) {
var worker = new Worker('worker-runner.workerjs');
worker.addEventListener('error', function (errorEvent) { throw workerErrorEventToError(errorEvent); });
worker.addEventListener('message', function (messageEvent) {
expect(messageEvent.data).to.eql('ready');
done();
});
});
}
});