测试版
This commit is contained in:
1981
node_modules/es5-shim/tests/spec/s-array.js
generated
vendored
Normal file
1981
node_modules/es5-shim/tests/spec/s-array.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
570
node_modules/es5-shim/tests/spec/s-date.js
generated
vendored
Normal file
570
node_modules/es5-shim/tests/spec/s-date.js
generated
vendored
Normal file
@@ -0,0 +1,570 @@
|
||||
describe('Date', function () {
|
||||
'use strict';
|
||||
|
||||
var supportsDescriptors = Object.defineProperty && (function () {
|
||||
try {
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, 'x', {
|
||||
enumerable: false,
|
||||
value: obj
|
||||
});
|
||||
// eslint-disable-next-line no-unreachable-loop
|
||||
for (var _ in obj) { return false; } // jscs:ignore disallowUnusedVariables
|
||||
return obj.x === obj;
|
||||
} catch (e) { /* this is ES3 */
|
||||
return false;
|
||||
}
|
||||
}());
|
||||
var ifSupportsDescriptorsIt = supportsDescriptors ? it : xit;
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
var negativeDate;
|
||||
beforeEach(function () {
|
||||
var negativeCanned = [
|
||||
{
|
||||
getTime: -3509827329600292,
|
||||
getUTCDay: 4,
|
||||
getDay: 4,
|
||||
dim: 31
|
||||
},
|
||||
{
|
||||
getTime: -3509824651200292,
|
||||
getUTCDay: 0,
|
||||
getDay: 0,
|
||||
dim: 29
|
||||
},
|
||||
{
|
||||
getTime: -3509822145600292,
|
||||
getUTCDay: 1,
|
||||
getDay: 1,
|
||||
dim: 31
|
||||
},
|
||||
{
|
||||
getTime: -3509819467200292,
|
||||
getUTCDay: 4,
|
||||
getDay: 4,
|
||||
dim: 30
|
||||
},
|
||||
{
|
||||
getTime: -3509816875200292,
|
||||
getUTCDay: 6,
|
||||
getDay: 6,
|
||||
dim: 31
|
||||
},
|
||||
{
|
||||
getTime: -3509814196800292,
|
||||
getUTCDay: 2,
|
||||
getDay: 2,
|
||||
dim: 30
|
||||
},
|
||||
{
|
||||
getTime: -3509811604800292,
|
||||
getUTCDay: 4,
|
||||
getDay: 4,
|
||||
dim: 31
|
||||
},
|
||||
{
|
||||
getTime: -3509808926400292,
|
||||
getUTCDay: 0,
|
||||
getDay: 0,
|
||||
dim: 31
|
||||
},
|
||||
{
|
||||
getTime: -3509806248000292,
|
||||
getUTCDay: 3,
|
||||
getDay: 3,
|
||||
dim: 30
|
||||
},
|
||||
{
|
||||
getTime: -3509803656000292,
|
||||
getUTCDay: 5,
|
||||
getDay: 5,
|
||||
dim: 31
|
||||
},
|
||||
{
|
||||
getTime: -3509800977600292,
|
||||
getUTCDay: 1,
|
||||
getDay: 1,
|
||||
dim: 30
|
||||
},
|
||||
{
|
||||
getTime: -3509798385600292,
|
||||
getUTCDay: 3,
|
||||
getDay: 3,
|
||||
dim: 31
|
||||
}
|
||||
];
|
||||
negativeDate = negativeCanned.map(function (item) {
|
||||
var dateFirst = new Date(item.getTime);
|
||||
var dateLast = new Date(item.getTime + ((item.dim - 1) * 86400000));
|
||||
return {
|
||||
dates: [dateFirst, dateLast],
|
||||
days: [1, item.dim],
|
||||
getUTCDay: [item.getUTCDay, (item.getUTCDay + item.dim - 1) % 7],
|
||||
getDay: [item.getDay, (item.getDay + item.dim - 1) % 7]
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
describe('.now()', function () {
|
||||
it('should be the current time', function () {
|
||||
var before = (new Date()).getTime();
|
||||
var middle = Date.now();
|
||||
var after = (new Date()).getTime();
|
||||
expect(middle).not.toBeLessThan(before);
|
||||
expect(middle).not.toBeGreaterThan(after);
|
||||
});
|
||||
});
|
||||
|
||||
describe('constructor', function () {
|
||||
it('works with standard formats', function () {
|
||||
// Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1
|
||||
expect(+new Date('2012-12-31T23:59:59.000Z')).toBe(1356998399000); // 1356998399000 1356998399000 1356998399000 1356998399000 1356998399000
|
||||
expect(+new Date('2012-04-04T05:02:02.170Z')).toBe(1333515722170); // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170
|
||||
expect(+new Date('2012-04-04T05:02:02.170999Z')).toBe(1333515722170); // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170
|
||||
expect(+new Date('2012-04-04T05:02:02.17Z')).toBe(1333515722170); // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170
|
||||
expect(+new Date('2012-04-04T05:02:02.1Z')).toBe(1333515722100); // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170
|
||||
expect(+new Date('2012-04-04T24:00:00.000Z')).toBe(1333584000000); // NaN 1333584000000 1333584000000 1333584000000 1333584000000
|
||||
expect(+new Date('2012-02-29T12:00:00.000Z')).toBe(1330516800000); // 1330516800000 1330516800000 1330516800000 1330516800000 1330516800000
|
||||
expect(+new Date('2011-03-01T12:00:00.000Z')).toBe(1298980800000); // 1298980800000 1298980800000 1298980800000 1298980800000 1298980800000
|
||||
|
||||
// https://github.com/es-shims/es5-shim/issues/80 Safari bug with leap day
|
||||
expect(new Date('2034-03-01T00:00:00.000Z')
|
||||
- new Date('2034-02-27T23:59:59.999Z')).toBe(86400001); // 86400001 86400001 86400001 86400001 1
|
||||
|
||||
});
|
||||
|
||||
ifSupportsDescriptorsIt('is not enumerable', function () {
|
||||
expect(Object.keys(new Date())).not.toContain('constructor');
|
||||
});
|
||||
|
||||
it('works as a function', function () {
|
||||
var zeroDate = Date(0);
|
||||
expect(zeroDate).toBe(String(zeroDate));
|
||||
var value = Date(1441705534578);
|
||||
expect(value).toBe(String(value));
|
||||
});
|
||||
|
||||
it('fixes this Safari 8/9 bug', function () {
|
||||
var offset = new Date(1970).getTimezoneOffset() * 60e3;
|
||||
|
||||
var timestamp = 2147483647; // Math.pow(2, 31) - 1
|
||||
var date = new Date(1970, 0, 1, 0, 0, 0, timestamp);
|
||||
var expectedTimestamp = timestamp + offset;
|
||||
expect(date.getTime()).toBe(expectedTimestamp);
|
||||
|
||||
var brokenTimestamp = 2147483648; // Math.pow(2, 31)
|
||||
var brokenDate = new Date(1970, 0, 1, 0, 0, 0, brokenTimestamp);
|
||||
var expectedBrokenTimestamp = brokenTimestamp + offset;
|
||||
expect(brokenDate.getTime()).toBe(expectedBrokenTimestamp); // NaN in Safari 8/9
|
||||
|
||||
var veryBrokenTS = 1435734000000;
|
||||
var veryBrokenDate = new Date(1970, 0, 1, 0, 0, 0, veryBrokenTS);
|
||||
var largeDate = new Date('Wed Jul 01 2015 07:00:00 GMT-0700 (PDT)');
|
||||
var expectedVeryBrokenTS = veryBrokenTS + (largeDate.getTimezoneOffset() * 60e3);
|
||||
expect(veryBrokenDate.getTime()).toBe(expectedVeryBrokenTS); // NaN in Safari 8/9
|
||||
});
|
||||
|
||||
it('works with a Date object', function () {
|
||||
var date = new Date(1456297712984);
|
||||
var copiedDate = new Date(date);
|
||||
expect(date).not.toBe(copiedDate);
|
||||
expect(copiedDate.getTime()).toBe(date.getTime());
|
||||
expect(+copiedDate).toBe(+date);
|
||||
expect(String(copiedDate)).toBe(String(date));
|
||||
});
|
||||
});
|
||||
|
||||
describe('.parse()', function () {
|
||||
// TODO: Write the rest of the test.
|
||||
|
||||
ifSupportsDescriptorsIt('is not enumerable', function () {
|
||||
expect(Object.getOwnPropertyDescriptor(Date, 'parse').enumerable).toBe(false);
|
||||
});
|
||||
|
||||
it('should be an invalid date', function () {
|
||||
// Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1
|
||||
expect(Date.parse('2012-11-31T23:59:59.000Z')).toBeFalsy(); // 1354406399000 NaN NaN 1354406399000 NaN
|
||||
expect(Date.parse('2012-12-31T23:59:60.000Z')).toBeFalsy(); // NaN NaN NaN NaN 1356998400000
|
||||
expect(Date.parse('2012-04-04T24:00:00.500Z')).toBeFalsy(); // NaN NaN 1333584000500 1333584000500 NaN
|
||||
expect(Date.parse('2012-12-31T10:08:60.000Z')).toBeFalsy(); // NaN NaN NaN NaN 1356948540000
|
||||
expect(Date.parse('2012-13-01T12:00:00.000Z')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('2012-12-32T12:00:00.000Z')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('2012-12-31T25:00:00.000Z')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('2012-12-31T24:01:00.000Z')).toBeFalsy(); // NaN NaN NaN 1356998460000 NaN
|
||||
expect(Date.parse('2012-12-31T12:60:00.000Z')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('2012-12-31T12:00:60.000Z')).toBeFalsy(); // NaN NaN NaN NaN 1356955260000
|
||||
expect(Date.parse('2012-00-31T23:59:59.000Z')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('2012-12-00T23:59:59.000Z')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('2011-02-29T12:00:00.000Z')).toBeFalsy(); // 1298980800000 NaN NaN 1298980800000 NaN
|
||||
});
|
||||
|
||||
it('should work', function () {
|
||||
var dates = {
|
||||
// Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1 Safari 8
|
||||
'2012-12-31T23:59:59.000Z': 1356998399000, // 1356998399000 1356998399000 1356998399000 1356998399000 1356998399000 1356998399000
|
||||
'2012-04-04T05:02:02.170Z': 1333515722170, // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170
|
||||
'2012-04-04T05:02:02.170999Z': 1333515722170, // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170.999
|
||||
'2012-04-04T05:02:02.17Z': 1333515722170, // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170
|
||||
'2012-04-04T05:02:02.1Z': 1333515722100, // 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 1333515722170
|
||||
'2012-04-04T24:00:00.000Z': 1333584000000, // NaN 1333584000000 1333584000000 1333584000000 1333584000000 1333584000000
|
||||
'2012-02-29T12:00:00.000Z': 1330516800000, // 1330516800000 1330516800000 1330516800000 1330516800000 1330516800000 1330516800000
|
||||
'2011-03-01T12:00:00.000Z': 1298980800000 // 1298980800000 1298980800000 1298980800000 1298980800000 1298980800000 1298980800000
|
||||
};
|
||||
for (var str in dates) {
|
||||
if (has.call(dates, str)) {
|
||||
expect(Math.floor(Date.parse(str))).toBe(dates[str]);
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/es-shims/es5-shim/issues/80 Safari bug with leap day
|
||||
expect(Date.parse('2034-03-01T00:00:00.000Z')
|
||||
- Date.parse('2034-02-27T23:59:59.999Z')).toBe(86400001); // 86400001 86400001 86400001 86400001 1
|
||||
|
||||
});
|
||||
|
||||
it('fixes a Safari 8/9 bug with parsing in UTC instead of local time', function () {
|
||||
var offset = new Date('2015-07-01').getTimezoneOffset() * 60e3;
|
||||
expect(Date.parse('2015-07-01T00:00:00')).toBe(1435708800000 + offset); // Safari 8/9 give NaN
|
||||
});
|
||||
|
||||
it('should support extended years', function () {
|
||||
// Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1
|
||||
expect(Date.parse('0000-01-01T00:00:00.000Z')).toBe(-621672192e5); // -621672192e5 -621672192e5 -621672192e5 -621672192e5 -621672192e5
|
||||
expect(Date.parse('0001-01-01T00:00:00Z')).toBe(-621355968e5); // -621355968e5 -621355968e5 -621355968e5 8.64e15 -621355968e5
|
||||
expect(Date.parse('+275760-09-13T00:00:00.000Z')).toBe(8.64e15); // 8.64e15 NaN 8.64e15 8.64e15 8.64e15
|
||||
expect(Date.parse('-271821-04-20T00:00:00.000Z')).toBe(-8.64e15); // -8.64e15 NaN -8.64e15 -8.64e15 -8.6400000864e15
|
||||
expect(Date.parse('+275760-09-13T00:00:00.001Z')).toBeFalsy(); // NaN NaN NaN 8.64e15 + 1 8.64e15 + 1
|
||||
expect(Date.parse('-271821-04-19T23:59:59.999Z')).toBeFalsy(); // NaN NaN NaN -8.64e15 - 1 -8.6400000864e15 - 1
|
||||
expect(Date.parse('+033658-09-27T01:46:40.000Z')).toBe(1e15); // 1e15 NaN 1e15 1e15 9999999136e5
|
||||
expect(Date.parse('-000001-01-01T00:00:00Z')).toBe(-621987552e5); // -621987552e5 NaN -621987552e5 -621987552e5 -621987552e5
|
||||
expect(Date.parse('+002009-12-15T00:00:00Z')).toBe(12608352e5); // 12608352e5 NaN 12608352e5 12608352e5 12608352e5
|
||||
});
|
||||
|
||||
it('works with timezone offsets', function () {
|
||||
// Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+01:00')).toBe(132783480e4); // 132783480e4 132783480e4 132783480e4 132783480e4 132783480e4
|
||||
expect(Date.parse('2012-01-29T12:00:00.000-00:00')).toBe(132783840e4); // 132783840e4 132783840e4 132783840e4 132783840e4 132783840e4
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+00:00')).toBe(132783840e4); // 132783840e4 132783840e4 132783840e4 132783840e4 132783840e4
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+23:59')).toBe(132775206e4); // 132775206e4 132775206e4 132775206e4 132775206e4 132775206e4
|
||||
expect(Date.parse('2012-01-29T12:00:00.000-23:59')).toBe(132792474e4); // 132792474e4 132792474e4 132792474e4 132792474e4 132792474e4
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+24:00')).toBeFalsy(); // NaN 1327752e6 NaN 1327752000000 1327752000000
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+24:01')).toBeFalsy(); // NaN NaN NaN 1327751940000 1327751940000
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+24:59')).toBeFalsy(); // NaN NaN NaN 1327748460000 1327748460000
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+25:00')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('2012-01-29T12:00:00.000+00:60')).toBeFalsy(); // NaN NaN NaN NaN NaN
|
||||
expect(Date.parse('-271821-04-20T00:00:00.000+00:01')).toBeFalsy(); // NaN NaN NaN -864000000006e4 -864000008646e4
|
||||
expect(Date.parse('-271821-04-20T00:01:00.000+00:01')).toBe(-8.64e15); // -8.64e15 NaN -8.64e15 -8.64e15 -864000008640e4
|
||||
|
||||
// When time zone is missed, local offset should be used (ES 5.1 bug)
|
||||
// see https://bugs.ecmascript.org/show_bug.cgi?id=112
|
||||
var tzOffset = Number(new Date(1970, 0));
|
||||
// same as (new Date().getTimezoneOffset() * 60000)
|
||||
expect(Date.parse('1970-01-01T00:00:00')).toBe(tzOffset); // tzOffset 0 0 0 NaN
|
||||
});
|
||||
|
||||
it('should be able to coerce to a number', function () {
|
||||
var actual = Number(new Date(1970, 0));
|
||||
var expected = parseInt(actual, 10);
|
||||
expect(actual).toBeDefined();
|
||||
expect(actual).toBe(expected);
|
||||
expect(isNaN(actual)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('matches web reality', function () {
|
||||
var actual = Number(new Date('1900-01-01T00:00:00.000'));
|
||||
var upperBound = -2208988800000; // safari 6.2 - 13.1
|
||||
var expected = -2208960000000;
|
||||
|
||||
expect(actual).toBeDefined();
|
||||
expect(actual).toBeGreaterThan(upperBound - 1);
|
||||
expect(actual).toBeLessThan(expected + 1);
|
||||
// expect(actual).toBe(expected); // TODO: figure out if `upperBound` is a bug or just a difference
|
||||
expect(isNaN(actual)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toString()', function () {
|
||||
var actual;
|
||||
|
||||
beforeEach(function () {
|
||||
actual = (new Date(1970, 0)).toString();
|
||||
});
|
||||
|
||||
it('should show correct date info for ' + actual, function () {
|
||||
expect(actual).toMatch(/1970/);
|
||||
expect(actual).toMatch(/jan/i);
|
||||
expect(actual).toMatch(/thu/i);
|
||||
expect(actual).toMatch(/00:00:00/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#valueOf()', function () {
|
||||
// Note that new Date(1970, 0).valueOf() is 0 in UTC timezone.
|
||||
// Check check that it's a number (and an int), not that it's "truthy".
|
||||
var actual;
|
||||
|
||||
beforeEach(function () {
|
||||
actual = (new Date(1970, 0)).valueOf();
|
||||
});
|
||||
it('should give a numeric value', function () {
|
||||
expect(typeof actual).toBe('number');
|
||||
});
|
||||
it('should not be NaN', function () {
|
||||
expect(isNaN(actual)).toBe(false);
|
||||
});
|
||||
it('should give an int value', function () {
|
||||
expect(actual).toBe(Math.floor(actual));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCDate()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
// Opera 10.6/11.61/Opera 12 bug
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date, index) {
|
||||
expect(date.getUTCDate()).toBe(item.days[index], date);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCDay()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date, index) {
|
||||
expect(date.getUTCDay()).toBe(item.getUTCDay[index]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCFullYear()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
// Opera 10.6/11.61/Opera 12 bug
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getUTCFullYear()).toBe(-109252);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCMonth()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
// Opera 10.6/11.61/Opera 12 bug
|
||||
negativeDate.forEach(function (item, index) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getUTCMonth()).toBe(index);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return correct values', function () {
|
||||
expect(new Date(8.64e15).getUTCMonth()).toBe(8);
|
||||
expect(new Date(0).getUTCMonth()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCHours()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getUTCHours()).toBe(11);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCMinutes()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getUTCMinutes()).toBe(59);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCSeconds()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getUTCSeconds()).toBe(59);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUTCMilliseconds()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
// Opera 10.6/11.61/Opera 12 bug
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getUTCMilliseconds()).toBe(708);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getDate()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date, index) {
|
||||
expect(date.getDate()).toBe(item.days[index]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getDay()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date, index) {
|
||||
expect(date.getDay()).toBe(item.getDay[index]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getFullYear()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
// Opera 10.6/11.61/Opera 12 bug
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getFullYear()).toBe(-109252);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMonth()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
// Opera 10.6/11.61/Opera 12 bug
|
||||
negativeDate.forEach(function (item, index) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getMonth()).toBe(index);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getHours()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getHours() + Math.floor(date.getTimezoneOffset() / 60)).toBe(11);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMinutes()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
var off = date.getTimezoneOffset();
|
||||
var offHours = Math.floor(off / 60);
|
||||
var offMins = off - (offHours * 60);
|
||||
var result = date.getMinutes() + offMins;
|
||||
// ceil/floor is for Firefox
|
||||
expect(result < 0 ? Math.ceil(result) : Math.floor(result)).toBe(59);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getSeconds()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date, i) {
|
||||
// the regex here is because in UTC, it's 59, but with TZData applied,
|
||||
// which can have fractional hour offsets, it'll be 1.
|
||||
expect(i + ':' + date.getSeconds()).toMatch(new RegExp(i + ':(?:' + 59 + '|' + 1 + ')'));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMilliseconds()', function () {
|
||||
it('should return the right value for negative dates', function () {
|
||||
// Opera 10.6/11.61/Opera 12 bug
|
||||
negativeDate.forEach(function (item) {
|
||||
item.dates.forEach(function (date) {
|
||||
expect(date.getMilliseconds()).toBe(708);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toISOString()', function () {
|
||||
// TODO: write the rest of the test.
|
||||
|
||||
it('should support extended years', function () {
|
||||
expect(new Date(-62198755200000).toISOString().indexOf('-000001-01-01')).toBe(0);
|
||||
expect(new Date(8.64e15).toISOString().indexOf('+275760-09-13')).toBe(0);
|
||||
});
|
||||
|
||||
it('should return correct dates', function () {
|
||||
expect(new Date(-1).toISOString()).toBe('1969-12-31T23:59:59.999Z'); // Safari 5.1.5 "1969-12-31T23:59:59.-01Z"
|
||||
negativeDate.forEach(function (item, index) {
|
||||
var m = index + 1;
|
||||
item.dates.forEach(function (date, idx) {
|
||||
var d = item.days[idx];
|
||||
expect(date.toISOString()).toBe('-109252-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d) + 'T11:59:59.708Z'); // Opera 11.61/Opera 12 bug with Date#getUTCMonth
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#toUTCString()', function () {
|
||||
it('should return correct dates', function () {
|
||||
expect(new Date(-1509842289600292).toUTCString()).toBe('Mon, 01 Jan -45875 11:59:59 GMT');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toDateString()', function () {
|
||||
it('should return correct dates', function () {
|
||||
expect(new Date(-1509842289600292).toDateString()).toBe('Mon Jan 01 -45875');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toString()', function () {
|
||||
it('should return correct dates', function () {
|
||||
var actual = new Date(1449662400000).toString();
|
||||
var re = /^Wed Dec 09 2015 \d\d:\d\d:\d\d GMT[-+]\d\d\d\d(?: |$)/;
|
||||
expect(re.test(actual)).toBe(true, actual);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toJSON()', function () {
|
||||
|
||||
// Opera 11.6x/12 bug
|
||||
it('should call toISOString', function () {
|
||||
var date = new Date(0);
|
||||
date.toISOString = function () {
|
||||
return 1;
|
||||
};
|
||||
expect(date.toJSON()).toBe(1);
|
||||
});
|
||||
|
||||
it('should return null for not finite dates', function () {
|
||||
var date = new Date(NaN),
|
||||
json;
|
||||
try {
|
||||
json = date.toJSON();
|
||||
} catch (e) {
|
||||
/* invalid json */
|
||||
expect(e).not.toEqual(jasmine.any(Error));
|
||||
}
|
||||
expect(json).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the isoString when stringified', function () {
|
||||
var date = new Date();
|
||||
expect(JSON.stringify(date.toISOString())).toBe(JSON.stringify(date));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
49
node_modules/es5-shim/tests/spec/s-error.js
generated
vendored
Normal file
49
node_modules/es5-shim/tests/spec/s-error.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
describe('Error', function () {
|
||||
'use strict';
|
||||
|
||||
var supportsDescriptors = Object.defineProperty && (function () {
|
||||
try {
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
|
||||
// eslint-disable-next-line no-unreachable-loop
|
||||
for (var _ in obj) { return false; } // jscs:ignore disallowUnusedVariables
|
||||
return obj.x === obj;
|
||||
} catch (e) { /* this is ES3 */
|
||||
return false;
|
||||
}
|
||||
}());
|
||||
var ifSupportsDescriptorsIt = supportsDescriptors ? it : xit;
|
||||
|
||||
describe('#toString()', function () {
|
||||
it('stringifies a newed error properly', function () {
|
||||
var msg = 'test';
|
||||
var error = new RangeError(msg);
|
||||
expect(error.name).toBe('RangeError');
|
||||
expect(error.message).toBe(msg);
|
||||
expect(String(error)).toBe(error.name + ': ' + msg);
|
||||
});
|
||||
|
||||
it('stringifies a thrown error properly', function () {
|
||||
var msg = 'test';
|
||||
var error;
|
||||
try {
|
||||
throw new RangeError(msg);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
expect(error.name).toBe('RangeError');
|
||||
expect(error.message).toBe(msg);
|
||||
expect(String(error)).toBe(error.name + ': ' + msg);
|
||||
});
|
||||
});
|
||||
|
||||
describe('enumerability of prototype properties', function () {
|
||||
ifSupportsDescriptorsIt('#message', function () {
|
||||
expect(Object.prototype.propertyIsEnumerable.call(Error.prototype, 'message')).toBe(false);
|
||||
});
|
||||
|
||||
ifSupportsDescriptorsIt('#name', function () {
|
||||
expect(Object.prototype.propertyIsEnumerable.call(Error.prototype, 'name')).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
174
node_modules/es5-shim/tests/spec/s-function.js
generated
vendored
Normal file
174
node_modules/es5-shim/tests/spec/s-function.js
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
describe('Function', function () {
|
||||
'use strict';
|
||||
|
||||
describe('#apply()', function () {
|
||||
it('works with arraylike objects', function () {
|
||||
var arrayLike = { length: 4, 0: 1, 2: 4, 3: true };
|
||||
var expectedArray = [1, undefined, 4, true];
|
||||
var actualArray = (function () {
|
||||
return Array.prototype.slice.apply(arguments);
|
||||
}.apply(null, arrayLike));
|
||||
expect(actualArray).toEqual(expectedArray);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#bind()', function () {
|
||||
var actual;
|
||||
|
||||
var testSubject = {
|
||||
push: function (o) {
|
||||
this.a.push(o);
|
||||
}
|
||||
};
|
||||
|
||||
var func = function func() {
|
||||
Array.prototype.forEach.call(arguments, function (a) {
|
||||
this.push(a);
|
||||
}, this);
|
||||
return this;
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
actual = [];
|
||||
testSubject.a = [];
|
||||
});
|
||||
|
||||
it('binds properly without a context', function () {
|
||||
var context;
|
||||
testSubject.func = function () {
|
||||
context = this;
|
||||
}.bind();
|
||||
testSubject.func();
|
||||
expect(context).toBe(function () { return this; }.call());
|
||||
});
|
||||
it('binds properly without a context, and still supplies bound arguments', function () {
|
||||
var a, context;
|
||||
testSubject.func = function () {
|
||||
a = Array.prototype.slice.call(arguments);
|
||||
context = this;
|
||||
}.bind(undefined, 1, 2, 3);
|
||||
testSubject.func(1, 2, 3);
|
||||
expect(a).toEqual([1, 2, 3, 1, 2, 3]);
|
||||
expect(context).toBe(function () { return this; }.call());
|
||||
});
|
||||
it('binds a context properly', function () {
|
||||
testSubject.func = func.bind(actual);
|
||||
testSubject.func(1, 2, 3);
|
||||
expect(actual).toEqual([1, 2, 3]);
|
||||
expect(testSubject.a).toEqual([]);
|
||||
});
|
||||
it('binds a context and supplies bound arguments', function () {
|
||||
testSubject.func = func.bind(actual, 1, 2, 3);
|
||||
testSubject.func(4, 5, 6);
|
||||
expect(actual).toEqual([1, 2, 3, 4, 5, 6]);
|
||||
expect(testSubject.a).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns properly without binding a context', function () {
|
||||
testSubject.func = function () {
|
||||
return this;
|
||||
}.bind();
|
||||
var context = testSubject.func();
|
||||
expect(context).toBe(function () { return this; }.call());
|
||||
});
|
||||
it('returns properly without binding a context, and still supplies bound arguments', function () {
|
||||
var context;
|
||||
testSubject.func = function () {
|
||||
context = this;
|
||||
return Array.prototype.slice.call(arguments);
|
||||
}.bind(undefined, 1, 2, 3);
|
||||
actual = testSubject.func(1, 2, 3);
|
||||
expect(context).toBe(function () { return this; }.call());
|
||||
expect(actual).toEqual([1, 2, 3, 1, 2, 3]);
|
||||
});
|
||||
it('returns properly while binding a context properly', function () {
|
||||
var ret;
|
||||
testSubject.func = func.bind(actual);
|
||||
ret = testSubject.func(1, 2, 3);
|
||||
expect(ret).toBe(actual);
|
||||
expect(ret).not.toBe(testSubject);
|
||||
});
|
||||
it('returns properly while binding a context and supplies bound arguments', function () {
|
||||
var ret;
|
||||
testSubject.func = func.bind(actual, 1, 2, 3);
|
||||
ret = testSubject.func(4, 5, 6);
|
||||
expect(ret).toBe(actual);
|
||||
expect(ret).not.toBe(testSubject);
|
||||
});
|
||||
it('has the new instance\'s context as a constructor', function () {
|
||||
var actualContext;
|
||||
var expectedContext = { foo: 'bar' };
|
||||
testSubject.Func = function () {
|
||||
actualContext = this;
|
||||
}.bind(expectedContext);
|
||||
var result = new testSubject.Func();
|
||||
expect(result).toBeTruthy();
|
||||
expect(actualContext).not.toBe(expectedContext);
|
||||
});
|
||||
it('passes the correct arguments as a constructor', function () {
|
||||
var expected = { name: 'Correct' };
|
||||
testSubject.Func = function (arg) {
|
||||
expect(Object.prototype.hasOwnProperty.call(this, 'name')).toBe(false);
|
||||
return arg;
|
||||
}.bind({ name: 'Incorrect' });
|
||||
var ret = new testSubject.Func(expected);
|
||||
expect(ret).toBe(expected);
|
||||
});
|
||||
it('returns the return value of the bound function when called as a constructor', function () {
|
||||
var oracle = [1, 2, 3];
|
||||
var Subject = function () {
|
||||
expect(this).not.toBe(oracle);
|
||||
return oracle;
|
||||
}.bind(null);
|
||||
var result = new Subject();
|
||||
expect(result).toBe(oracle);
|
||||
});
|
||||
|
||||
it('returns the correct value if constructor returns primitive', function () {
|
||||
var Subject = function (oracle) {
|
||||
expect(this).not.toBe(oracle);
|
||||
return oracle;
|
||||
}.bind(null);
|
||||
|
||||
var primitives = ['asdf', null, true, 1];
|
||||
for (var i = 0; i < primitives.length; ++i) {
|
||||
expect(new Subject(primitives[i])).not.toBe(primitives[i]);
|
||||
}
|
||||
|
||||
var objects = [[1, 2, 3], {}, function () {}];
|
||||
for (var j = 0; j < objects.length; ++j) {
|
||||
expect(new Subject(objects[j])).toBe(objects[j]);
|
||||
}
|
||||
});
|
||||
it('returns the value that instance of original "class" when called as a constructor', function () {
|
||||
var ClassA = function (x) {
|
||||
this.name = x || 'A';
|
||||
};
|
||||
var ClassB = ClassA.bind(null, 'B');
|
||||
|
||||
var result = new ClassB();
|
||||
expect(result instanceof ClassA).toBe(true);
|
||||
expect(result instanceof ClassB).toBe(true);
|
||||
});
|
||||
it('sets a correct length without thisArg', function () {
|
||||
var Subject = function (a, b, c) { return a + b + c; }.bind();
|
||||
expect(Subject.length).toBe(3);
|
||||
});
|
||||
it('sets a correct length with thisArg', function () {
|
||||
var Subject = function (a, b, c) { return a + b + c + this.d; }.bind({ d: 1 });
|
||||
expect(Subject.length).toBe(3);
|
||||
});
|
||||
it('sets a correct length with thisArg and first argument', function () {
|
||||
var Subject = function (a, b, c) { return a + b + c + this.d; }.bind({ d: 1 }, 1);
|
||||
expect(Subject.length).toBe(2);
|
||||
});
|
||||
it('sets a correct length without thisArg and first argument', function () {
|
||||
var Subject = function (a, b, c) { return a + b + c; }.bind(undefined, 1);
|
||||
expect(Subject.length).toBe(2);
|
||||
});
|
||||
it('sets a correct length without thisArg and too many argument', function () {
|
||||
var Subject = function (a, b, c) { return a + b + c; }.bind(undefined, 1, 2, 3, 4);
|
||||
expect(Subject.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
107
node_modules/es5-shim/tests/spec/s-global.js
generated
vendored
Normal file
107
node_modules/es5-shim/tests/spec/s-global.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
describe('global methods', function () {
|
||||
'use strict';
|
||||
|
||||
var foo = function foo() {};
|
||||
var functionsHaveNames = foo.name === 'foo';
|
||||
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
|
||||
var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
|
||||
var ifSymbolsIt = hasSymbols ? it : xit;
|
||||
|
||||
var is = function (x, y) {
|
||||
if (x === 0 && y === 0) {
|
||||
return 1 / x === 1 / y;
|
||||
}
|
||||
return x === y;
|
||||
};
|
||||
|
||||
describe('parseInt', function () {
|
||||
/* eslint-disable radix */
|
||||
|
||||
ifFunctionsHaveNamesIt('has the right name', function () {
|
||||
expect(parseInt.name).toBe('parseInt');
|
||||
});
|
||||
|
||||
it('accepts a radix', function () {
|
||||
for (var i = 2; i <= 36; ++i) {
|
||||
expect(parseInt('10', i)).toBe(i);
|
||||
}
|
||||
});
|
||||
|
||||
it('defaults the radix to 10 when the number does not start with 0x or 0X', function () {
|
||||
[
|
||||
'01',
|
||||
'08',
|
||||
'10',
|
||||
'42'
|
||||
].forEach(function (str) {
|
||||
expect(parseInt(str)).toBe(parseInt(str, 10));
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults the radix to 16 when the number starts with 0x or 0X', function () {
|
||||
expect(parseInt('0x16')).toBe(parseInt('0x16', 16));
|
||||
expect(parseInt('0X16')).toBe(parseInt('0X16', 16));
|
||||
});
|
||||
|
||||
it('ignores leading whitespace', function () {
|
||||
expect(parseInt(' 0x16')).toBe(parseInt('0x16', 16));
|
||||
expect(parseInt(' 42')).toBe(parseInt('42', 10));
|
||||
expect(parseInt(' 08')).toBe(parseInt('08', 10));
|
||||
|
||||
var mvsIsWS = (/\s/).test('\u180E');
|
||||
if (mvsIsWS) {
|
||||
expect(parseInt('\u180E' + 1)).toBe(1);
|
||||
} else {
|
||||
expect(parseInt('\u180E' + 1)).toBeNaN();
|
||||
}
|
||||
|
||||
var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'
|
||||
.replace(/\S/g, ''); // remove the mongolian vowel separator (/u180E) on modern engines
|
||||
expect(parseInt(ws + '08')).toBe(parseInt('08', 10));
|
||||
expect(parseInt(ws + '0x16')).toBe(parseInt('0x16', 16));
|
||||
});
|
||||
|
||||
it('defaults the radix properly when not a true number', function () {
|
||||
var fakeZero = { valueOf: function () { return 0; } };
|
||||
expect(parseInt('08', fakeZero)).toBe(parseInt('08', 10));
|
||||
expect(parseInt('0x16', fakeZero)).toBe(parseInt('0x16', 16));
|
||||
});
|
||||
|
||||
it('allows sign-prefixed hex values', function () {
|
||||
expect(parseInt('-0xF')).toBe(-15);
|
||||
expect(parseInt('-0xF', 16)).toBe(-15);
|
||||
expect(parseInt('+0xF')).toBe(15);
|
||||
expect(parseInt('+0xF', 16)).toBe(15);
|
||||
});
|
||||
|
||||
it('NaN parsing', function () {
|
||||
expect(parseInt()).toBeNaN();
|
||||
expect(parseInt(undefined)).toBeNaN();
|
||||
expect(parseInt(null)).toBeNaN();
|
||||
expect(parseInt(NaN)).toBeNaN();
|
||||
});
|
||||
|
||||
ifSymbolsIt('throws on symbols', function () {
|
||||
expect(function () { parseInt(Symbol('')); }).toThrow();
|
||||
expect(function () { parseInt(Object(Symbol(''))); }).toThrow();
|
||||
});
|
||||
/* eslint-enable radix */
|
||||
});
|
||||
|
||||
describe('parseFloat()', function () {
|
||||
it('works with zeroes', function () {
|
||||
expect(is(parseFloat('0'), 0) ? '+0' : '-0').toBe('+0');
|
||||
expect(is(parseFloat(' 0'), 0) ? '+0' : '-0').toBe('+0');
|
||||
expect(is(parseFloat('+0'), 0) ? '+0' : '-0').toBe('+0');
|
||||
expect(is(parseFloat(' +0'), 0) ? '+0' : '-0').toBe('+0');
|
||||
expect(is(parseFloat('-0'), -0) ? '-0' : '+0').toBe('-0');
|
||||
expect(is(parseFloat(' -0'), -0) ? '-0' : '+0').toBe('-0');
|
||||
});
|
||||
|
||||
it('NaN parsing', function () {
|
||||
expect(parseFloat(undefined)).toBeNaN();
|
||||
expect(parseFloat(null)).toBeNaN();
|
||||
expect(parseFloat(NaN)).toBeNaN();
|
||||
});
|
||||
});
|
||||
});
|
||||
103
node_modules/es5-shim/tests/spec/s-number.js
generated
vendored
Normal file
103
node_modules/es5-shim/tests/spec/s-number.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
describe('Number', function () {
|
||||
'use strict';
|
||||
|
||||
describe('#toExponential()', function () {
|
||||
// the spec allows for this test to fail.
|
||||
it('throws a RangeError when < 0 or > 20 (or > 100 in ES2018+)', function () {
|
||||
expect(function () { return 1.0.toExponential(-1); }).toThrow();
|
||||
expect(function () { return 1.0.toExponential(-Infinity); }).toThrow();
|
||||
expect(function () { return 1.0.toExponential(Infinity); }).toThrow();
|
||||
expect(function () {
|
||||
return [
|
||||
(0.9).toExponential(21), // ES2018 increased the limit from 21 to 100
|
||||
(0.9).toExponential(101)
|
||||
];
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('works for NaN receiver', function () {
|
||||
expect(NaN.toExponential(NaN)).toBe('NaN');
|
||||
expect(NaN.toExponential('abc')).toBe('NaN');
|
||||
});
|
||||
|
||||
it('works for non-finite receivers', function () {
|
||||
expect(Infinity.toExponential()).toBe('Infinity');
|
||||
expect((-Infinity).toExponential()).toBe('-Infinity');
|
||||
});
|
||||
|
||||
it('should round properly', function () {
|
||||
expect(1.0.toExponential()).toBe('1e+0');
|
||||
expect(1.0.toExponential(0)).toBe('1e+0');
|
||||
expect(1.0.toExponential(1)).toBe('1.0e+0');
|
||||
expect(1.0.toExponential(2)).toBe('1.00e+0');
|
||||
|
||||
expect(1.2345.toExponential()).toBe('1.2345e+0');
|
||||
expect(1.2345.toExponential(0)).toBe('1e+0');
|
||||
expect(1.2345.toExponential(1)).toBe('1.2e+0');
|
||||
expect(1.2345.toExponential(2)).toBe('1.23e+0');
|
||||
expect(1.2345.toExponential(3)).toMatch(/^1.23[45]e\+0$/);
|
||||
expect(1.2345.toExponential(4)).toBe('1.2345e+0');
|
||||
expect(1.2345.toExponential(5)).toBe('1.23450e+0');
|
||||
|
||||
expect((-6.9e-11).toExponential(4)).toBe('-6.9000e-11');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toFixed()', function () {
|
||||
it('should convert numbers correctly', function () {
|
||||
expect((0.00008).toFixed(3)).toBe('0.000');
|
||||
expect((0.9).toFixed(0)).toBe('1');
|
||||
expect((1.255).toFixed(2)).toBe('1.25');
|
||||
expect((1843654265.0774949).toFixed(5)).toBe('1843654265.07749');
|
||||
expect((1000000000000000128).toFixed(0)).toBe('1000000000000000128');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toPrecision()', function () {
|
||||
// the spec allows for this test to fail.
|
||||
it('throws a RangeError when < 1 or > 21 (or > 100 in ES2018+)', function () {
|
||||
expect(function () { return (0.9).toPrecision(0); }).toThrow();
|
||||
expect(function () {
|
||||
return [
|
||||
(0.9).toPrecision(22), // ES2018 increased the limit from 21 to 100
|
||||
(0.9).toPrecision(101)
|
||||
];
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('works as expected', function () {
|
||||
expect((0.00008).toPrecision(3)).toBe('0.0000800');
|
||||
expect((1.255).toPrecision(2)).toBe('1.3');
|
||||
expect((1843654265.0774949).toPrecision(13)).toBe('1843654265.077');
|
||||
expect(NaN.toPrecision(1)).toBe('NaN');
|
||||
});
|
||||
|
||||
it('works with an undefined precision', function () {
|
||||
var num = 123.456;
|
||||
expect(num.toPrecision()).toBe(String(num));
|
||||
expect(num.toPrecision(undefined)).toBe(String(num));
|
||||
});
|
||||
});
|
||||
|
||||
describe('constants', function () {
|
||||
it('should have MAX_VALUE', function () {
|
||||
expect(Number.MAX_VALUE).toBe(1.7976931348623157e308);
|
||||
});
|
||||
|
||||
it('should have MIN_VALUE', function () {
|
||||
expect(Number.MIN_VALUE).toBe(5e-324);
|
||||
});
|
||||
|
||||
it('should have NaN', function () {
|
||||
expect(Number.NaN).not.toBe(Number.NaN);
|
||||
});
|
||||
|
||||
it('should have POSITIVE_INFINITY', function () {
|
||||
expect(Number.POSITIVE_INFINITY).toBe(Infinity);
|
||||
});
|
||||
|
||||
it('should have NEGATIVE_INFINITY', function () {
|
||||
expect(Number.NEGATIVE_INFINITY).toBe(-Infinity);
|
||||
});
|
||||
});
|
||||
});
|
||||
403
node_modules/es5-shim/tests/spec/s-object.js
generated
vendored
Normal file
403
node_modules/es5-shim/tests/spec/s-object.js
generated
vendored
Normal file
@@ -0,0 +1,403 @@
|
||||
/* global window */
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
var supportsDescriptors = Object.defineProperty && (function () {
|
||||
try {
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
|
||||
// eslint-disable-next-line no-unreachable-loop
|
||||
for (var _ in obj) { return false; } // jscs:ignore disallowUnusedVariables
|
||||
return obj.x === obj;
|
||||
} catch (e) { /* this is ES3 */
|
||||
return false;
|
||||
}
|
||||
}());
|
||||
var ifSupportsDescriptorsIt = supportsDescriptors ? it : xit;
|
||||
var ifWindowIt = typeof window === 'undefined' ? xit : it;
|
||||
var extensionsPreventible = typeof Object.preventExtensions === 'function' && (function () {
|
||||
var obj = {};
|
||||
Object.preventExtensions(obj);
|
||||
obj.a = 3;
|
||||
return obj.a !== 3;
|
||||
}());
|
||||
var ifExtensionsPreventibleIt = extensionsPreventible ? it : xit;
|
||||
var canSeal = typeof Object.seal === 'function' && (function () {
|
||||
var obj = { a: 3 };
|
||||
Object.seal(obj);
|
||||
delete obj.a;
|
||||
return obj.a === 3;
|
||||
}());
|
||||
var ifCanSealIt = canSeal ? it : xit;
|
||||
var canFreeze = typeof Object.freeze === 'function' && (function () {
|
||||
var obj = {};
|
||||
Object.freeze(obj);
|
||||
obj.a = 3;
|
||||
return obj.a !== 3;
|
||||
}());
|
||||
var ifCanFreezeIt = canFreeze ? it : xit;
|
||||
|
||||
describe('Object', function () {
|
||||
'use strict';
|
||||
|
||||
describe('.keys()', function () {
|
||||
var obj = {
|
||||
str: 'boz',
|
||||
obj: { },
|
||||
arr: [],
|
||||
bool: true,
|
||||
num: 42,
|
||||
'null': null,
|
||||
undefined: undefined
|
||||
};
|
||||
|
||||
var loopedValues = [];
|
||||
for (var key in obj) {
|
||||
loopedValues.push(key);
|
||||
}
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
it('should have correct length', function () {
|
||||
expect(keys.length).toBe(7);
|
||||
});
|
||||
|
||||
describe('arguments objects', function () {
|
||||
it('works with an arguments object', function () {
|
||||
(function () {
|
||||
expect(arguments.length).toBe(3);
|
||||
expect(Object.keys(arguments).length).toBe(arguments.length);
|
||||
expect(Object.keys(arguments)).toEqual(['0', '1', '2']);
|
||||
}(1, 2, 3));
|
||||
});
|
||||
|
||||
it('works with a legacy arguments object', function () {
|
||||
var FakeArguments = function (args) {
|
||||
args.forEach(function (arg, i) {
|
||||
this[i] = arg;
|
||||
}.bind(this));
|
||||
};
|
||||
FakeArguments.prototype.length = 3;
|
||||
FakeArguments.prototype.callee = function () {};
|
||||
|
||||
var fakeOldArguments = new FakeArguments(['a', 'b', 'c']);
|
||||
expect(Object.keys(fakeOldArguments)).toEqual(['0', '1', '2']);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an Array', function () {
|
||||
expect(Array.isArray(keys)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return names which are own properties', function () {
|
||||
keys.forEach(function (name) {
|
||||
expect(has.call(obj, name)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return names which are enumerable', function () {
|
||||
keys.forEach(function (name) {
|
||||
expect(loopedValues.indexOf(name)).toNotBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
// ES6 Object.keys does not require this throw
|
||||
xit('should throw error for non object', function () {
|
||||
var e = {};
|
||||
expect(function () {
|
||||
try {
|
||||
Object.keys(42);
|
||||
} catch (err) {
|
||||
throw e;
|
||||
}
|
||||
}).toThrow(e);
|
||||
});
|
||||
|
||||
describe('enumerating over non-enumerable properties', function () {
|
||||
it('has no enumerable keys on a Function', function () {
|
||||
var Foo = function () {};
|
||||
expect(Object.keys(Foo.prototype)).toEqual([]);
|
||||
});
|
||||
|
||||
it('has no enumerable keys on a boolean', function () {
|
||||
expect(Object.keys(Boolean.prototype)).toEqual([]);
|
||||
});
|
||||
|
||||
it('has no enumerable keys on an object', function () {
|
||||
expect(Object.keys(Object.prototype)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with boxed primitives', function () {
|
||||
expect(Object.keys(Object('hello'))).toEqual(['0', '1', '2', '3', '4']);
|
||||
});
|
||||
|
||||
it('works with boxed primitives with extra properties', function () {
|
||||
var x = Object('x');
|
||||
x.y = 1;
|
||||
var actual = Object.keys(x);
|
||||
var expected = ['0', 'y'];
|
||||
actual.sort();
|
||||
expected.sort();
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
ifWindowIt('can serialize all objects on the `window`', function () {
|
||||
var windowItemKeys, exception;
|
||||
var excludedKeys = ['window', 'console', 'parent', 'self', 'frame', 'frames', 'frameElement', 'external', 'height', 'width', 'top', 'localStorage', 'applicationCache'];
|
||||
if (supportsDescriptors) {
|
||||
Object.defineProperty(window, 'thrower', {
|
||||
configurable: true,
|
||||
get: function () { throw new RangeError('thrower!'); }
|
||||
});
|
||||
}
|
||||
for (var k in window) {
|
||||
exception = void 0;
|
||||
windowItemKeys = exception;
|
||||
if (excludedKeys.indexOf(k) === -1 && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
|
||||
try {
|
||||
windowItemKeys = Object.keys(window[k]);
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
}
|
||||
expect(Array.isArray(windowItemKeys)).toBe(true);
|
||||
expect(exception).toBeUndefined();
|
||||
}
|
||||
}
|
||||
if (supportsDescriptors) {
|
||||
delete window.thrower;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('.isExtensible()', function () {
|
||||
var obj = { };
|
||||
|
||||
it('should return true if object is extensible', function () {
|
||||
expect(Object.isExtensible(obj)).toBe(true);
|
||||
});
|
||||
|
||||
ifExtensionsPreventibleIt('should return false if object is not extensible', function () {
|
||||
expect(Object.isExtensible(Object.preventExtensions(obj))).toBe(false);
|
||||
});
|
||||
|
||||
ifCanSealIt('should return false if object is sealed', function () {
|
||||
expect(Object.isExtensible(Object.seal(obj))).toBe(false);
|
||||
});
|
||||
|
||||
ifCanFreezeIt('should return false if object is frozen', function () {
|
||||
expect(Object.isExtensible(Object.freeze(obj))).toBe(false);
|
||||
});
|
||||
|
||||
it('should throw error for non object', function () {
|
||||
try {
|
||||
// note: in ES6, this is expected to return false.
|
||||
expect(Object.isExtensible(42)).toBe(false);
|
||||
} catch (err) {
|
||||
expect(err).toEqual(jasmine.any(TypeError));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('.defineProperty()', function () {
|
||||
var obj;
|
||||
|
||||
beforeEach(function () {
|
||||
obj = {};
|
||||
|
||||
Object.defineProperty(obj, 'name', {
|
||||
value: 'Testing',
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the initial value', function () {
|
||||
expect(has.call(obj, 'name')).toBeTruthy();
|
||||
expect(obj.name).toBe('Testing');
|
||||
});
|
||||
|
||||
it('should be setable', function () {
|
||||
obj.name = 'Other';
|
||||
expect(obj.name).toBe('Other');
|
||||
});
|
||||
|
||||
it('should return the parent initial value', function () {
|
||||
var child = Object.create(obj, {});
|
||||
|
||||
expect(child.name).toBe('Testing');
|
||||
expect(has.call(child, 'name')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not override the parent value', function () {
|
||||
var child = Object.create(obj, {});
|
||||
|
||||
Object.defineProperty(child, 'name', { value: 'Other' });
|
||||
|
||||
expect(obj.name).toBe('Testing');
|
||||
expect(child.name).toBe('Other');
|
||||
});
|
||||
|
||||
it('should throw error for non object', function () {
|
||||
expect(function () {
|
||||
Object.defineProperty(42, 'name', {});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should not throw error for empty descriptor', function () {
|
||||
expect(function () {
|
||||
Object.defineProperty({}, 'name', {});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
ifSupportsDescriptorsIt('allows setting a nonwritable prototype', function () {
|
||||
var F = function () {};
|
||||
expect(F.prototype).toEqual(Object.getOwnPropertyDescriptor(F, 'prototype').value);
|
||||
expect((new F()).toString).toEqual(Object.prototype.toString);
|
||||
|
||||
F.prototype = Number.prototype;
|
||||
expect(F.prototype).toEqual(Object.getOwnPropertyDescriptor(F, 'prototype').value);
|
||||
expect((new F()).toString).toEqual(Number.prototype.toString);
|
||||
|
||||
var toStringSentinel = {};
|
||||
var sentinel = { toString: toStringSentinel };
|
||||
Object.defineProperty(F, 'prototype', { value: sentinel, writable: false });
|
||||
|
||||
expect(F.prototype).toEqual(Object.getOwnPropertyDescriptor(F, 'prototype').value);
|
||||
expect((new F()).toString).toEqual(toStringSentinel);
|
||||
});
|
||||
|
||||
ifSupportsDescriptorsIt('properly makes a prototype non-writable', function () {
|
||||
var O = { prototype: 1 };
|
||||
expect(O.prototype).toEqual(Object.getOwnPropertyDescriptor(O, 'prototype').value);
|
||||
expect(O.prototype).toEqual(1);
|
||||
|
||||
expect(function () {
|
||||
Object.defineProperty(O, 'prototype', { writable: false, configurable: true });
|
||||
}).not.toThrow();
|
||||
|
||||
var sentinel = {};
|
||||
expect(function () {
|
||||
Object.defineProperty(O, 'prototype', { value: sentinel });
|
||||
}).not.toThrow();
|
||||
|
||||
expect(O.prototype).toEqual(Object.getOwnPropertyDescriptor(O, 'prototype').value);
|
||||
expect(O.prototype).toEqual(sentinel);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getOwnPropertyDescriptor()', function () {
|
||||
it('should return undefined because the object does not own the property', function () {
|
||||
var descr = Object.getOwnPropertyDescriptor({}, 'name');
|
||||
|
||||
expect(descr).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return a data descriptor', function () {
|
||||
var descr = Object.getOwnPropertyDescriptor({ name: 'Testing' }, 'name');
|
||||
var expected = {
|
||||
value: 'Testing',
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
configurable: true
|
||||
};
|
||||
|
||||
expect(descr).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should return undefined because the object does not own the property', function () {
|
||||
var descr = Object.getOwnPropertyDescriptor(Object.create({ name: 'Testing' }, {}), 'name');
|
||||
|
||||
expect(descr).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return a data descriptor', function () {
|
||||
var expected = {
|
||||
value: 'Testing',
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true
|
||||
};
|
||||
var obj = Object.create({}, { name: expected });
|
||||
|
||||
var descr = Object.getOwnPropertyDescriptor(obj, 'name');
|
||||
|
||||
expect(descr).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should throw error for non object', function () {
|
||||
try {
|
||||
// note: in ES6, we expect this to return undefined.
|
||||
expect(Object.getOwnPropertyDescriptor(42, 'name')).toBeUndefined();
|
||||
} catch (err) {
|
||||
expect(err).toEqual(jasmine.any(TypeError));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getPrototypeOf()', function () {
|
||||
it('should return the [[Prototype]] of an object', function () {
|
||||
var Foo = function () {};
|
||||
|
||||
var proto = Object.getPrototypeOf(new Foo());
|
||||
|
||||
expect(proto).toBe(Foo.prototype);
|
||||
});
|
||||
|
||||
it('should shamone to the `Object.prototype` if `object.constructor` is not a function', function () {
|
||||
var Foo = function () {};
|
||||
Foo.prototype.constructor = 1;
|
||||
|
||||
var proto = Object.getPrototypeOf(new Foo()),
|
||||
fnToString = Function.prototype.toString;
|
||||
|
||||
if (fnToString.call(Object.getPrototypeOf).indexOf('[native code]') < 0) {
|
||||
expect(proto).toBe(Object.prototype);
|
||||
} else {
|
||||
expect(proto).toBe(Foo.prototype);
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw error for non object', function () {
|
||||
try {
|
||||
expect(Object.getPrototypeOf(1)).toBe(Number.prototype); // ES6 behavior
|
||||
} catch (err) {
|
||||
expect(err).toEqual(jasmine.any(TypeError));
|
||||
}
|
||||
});
|
||||
|
||||
it('should return null on Object.create(null)', function () {
|
||||
var obj = Object.create(null);
|
||||
|
||||
expect(Object.getPrototypeOf(obj) === null).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.defineProperties()', function () {
|
||||
it('should define the constructor property', function () {
|
||||
var target = {};
|
||||
var newProperties = { constructor: { value: 'new constructor' } };
|
||||
Object.defineProperties(target, newProperties);
|
||||
expect(target.constructor).toBe('new constructor');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.create()', function () {
|
||||
it('should create objects with no properties when called as `Object.create(null)`', function () {
|
||||
var obj = Object.create(null);
|
||||
|
||||
expect('hasOwnProperty' in obj).toBe(false);
|
||||
expect('toString' in obj).toBe(false);
|
||||
expect('constructor' in obj).toBe(false);
|
||||
|
||||
var protoIsEnumerable = false;
|
||||
for (var k in obj) {
|
||||
if (k === '__proto__') {
|
||||
protoIsEnumerable = true;
|
||||
}
|
||||
}
|
||||
expect(protoIsEnumerable).toBe(false);
|
||||
|
||||
expect(obj instanceof Object).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
26
node_modules/es5-shim/tests/spec/s-regexp.js
generated
vendored
Normal file
26
node_modules/es5-shim/tests/spec/s-regexp.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
describe('RegExp', function () {
|
||||
'use strict';
|
||||
|
||||
describe('#toString()', function () {
|
||||
describe('literals', function () {
|
||||
it('should return correct flags and in correct order', function () {
|
||||
expect(String(/pattern/)).toBe('/pattern/');
|
||||
expect(String(/pattern/i)).toBe('/pattern/i');
|
||||
expect(String(/pattern/mi)).toBe('/pattern/im');
|
||||
expect(String(/pattern/im)).toBe('/pattern/im');
|
||||
expect(String(/pattern/mgi)).toBe('/pattern/gim');
|
||||
});
|
||||
});
|
||||
|
||||
describe('objects', function () {
|
||||
it('should return correct flags and in correct order', function () {
|
||||
/* eslint prefer-regex-literals: 0 */
|
||||
expect(String(new RegExp('pattern'))).toBe('/pattern/');
|
||||
expect(String(new RegExp('pattern', 'i'))).toBe('/pattern/i');
|
||||
expect(String(new RegExp('pattern', 'mi'))).toBe('/pattern/im');
|
||||
expect(String(new RegExp('pattern', 'im'))).toBe('/pattern/im');
|
||||
expect(String(new RegExp('pattern', 'mgi'))).toBe('/pattern/gim');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
277
node_modules/es5-shim/tests/spec/s-string.js
generated
vendored
Normal file
277
node_modules/es5-shim/tests/spec/s-string.js
generated
vendored
Normal file
@@ -0,0 +1,277 @@
|
||||
describe('String', function () {
|
||||
'use strict';
|
||||
|
||||
describe('#trim()', function () {
|
||||
var mvs = '\u180E';
|
||||
var mvsIsWS = (/\s/).test(mvs);
|
||||
var test = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680' + (mvsIsWS ? mvs : '') + '\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFFHello, World!\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680' + (mvsIsWS ? mvs : '') + '\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
|
||||
|
||||
it('trims all ES5 whitespace', function () {
|
||||
expect(test.trim()).toBe('Hello, World!');
|
||||
expect(test.trim().length).toBe(13);
|
||||
});
|
||||
|
||||
it('does not trim the zero-width space', function () {
|
||||
var zws = '\u200b';
|
||||
expect(zws.trim()).toBe(zws);
|
||||
});
|
||||
|
||||
it('properly handles the mongolian vowel separator', function () {
|
||||
if (mvsIsWS) {
|
||||
expect(mvs.trim()).toBe('');
|
||||
} else {
|
||||
expect(mvs.trim()).toBe(mvs);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#replace()', function () {
|
||||
it('returns undefined for non-capturing groups', function () {
|
||||
var groups = [];
|
||||
'x'.replace(/x(.)?/g, function (m, group) {
|
||||
groups.push(group); /* "" in FF, `undefined` in CH/WK/IE */
|
||||
});
|
||||
expect(groups.length).toBe(1);
|
||||
expect(groups[0]).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not fail in Firefox', function () {
|
||||
expect(function () {
|
||||
return '* alef\n* beth \n* gimel~0\n'.replace(
|
||||
/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
|
||||
function (match, m1, m2, m3, m4) { return '<li>' + m4 + '</li>\n'; }
|
||||
);
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#split()', function () {
|
||||
var test = 'ab';
|
||||
|
||||
it('If "separator" is undefined must return Array with one String - "this" string', function () {
|
||||
expect(test.split()).toEqual([test]);
|
||||
expect(test.split(void 0)).toEqual([test]);
|
||||
});
|
||||
|
||||
it('If "separator" is undefined and "limit" set to 0 must return Array[]', function () {
|
||||
expect(test.split(void 0, 0)).toEqual([]);
|
||||
});
|
||||
|
||||
describe('Tests from Steven Levithan', function () {
|
||||
it("''.split() results in ['']", function () {
|
||||
expect(''.split()).toEqual(['']);
|
||||
});
|
||||
it("''.split(/./) results in ['']", function () {
|
||||
expect(''.split(/./)).toEqual(['']);
|
||||
});
|
||||
it("''.split(/.?/) results in []", function () {
|
||||
expect(''.split(/.?/)).toEqual([]);
|
||||
});
|
||||
it("''.split(/.??/) results in []", function () {
|
||||
expect(''.split(/.??/)).toEqual([]);
|
||||
});
|
||||
it("'ab'.split(/a*/) results in ['', 'b']", function () {
|
||||
expect('ab'.split(/a*/)).toEqual(['', 'b']);
|
||||
});
|
||||
it("'ab'.split(/a*?/) results in ['a', 'b']", function () {
|
||||
expect('ab'.split(/a*?/)).toEqual(['a', 'b']);
|
||||
});
|
||||
it("'ab'.split(/(?:ab)/) results in ['', '']", function () {
|
||||
expect('ab'.split(/(?:ab)/)).toEqual(['', '']);
|
||||
});
|
||||
it("'ab'.split(/(?:ab)*/) results in ['', '']", function () {
|
||||
expect('ab'.split(/(?:ab)*/)).toEqual(['', '']);
|
||||
});
|
||||
it("'ab'.split(/(?:ab)*?/) results in ['a', 'b']", function () {
|
||||
expect('ab'.split(/(?:ab)*?/)).toEqual(['a', 'b']);
|
||||
});
|
||||
it("'test'.split('') results in ['t', 'e', 's', 't']", function () {
|
||||
expect('test'.split('')).toEqual(['t', 'e', 's', 't']);
|
||||
});
|
||||
it("'test'.split() results in ['test']", function () {
|
||||
expect('test'.split()).toEqual(['test']);
|
||||
});
|
||||
it("'111'.split(1) results in ['', '', '', '']", function () {
|
||||
expect('111'.split(1)).toEqual(['', '', '', '']);
|
||||
});
|
||||
it("'test'.split(/(?:)/, 2) results in ['t', 'e']", function () {
|
||||
expect('test'.split(/(?:)/, 2)).toEqual(['t', 'e']);
|
||||
});
|
||||
it("'test'.split(/(?:)/, -1) results in ['t', 'e', 's', 't']", function () {
|
||||
expect('test'.split(/(?:)/, -1)).toEqual(['t', 'e', 's', 't']);
|
||||
});
|
||||
it("'test'.split(/(?:)/, undefined) results in ['t', 'e', 's', 't']", function () {
|
||||
expect('test'.split(/(?:)/, undefined)).toEqual(['t', 'e', 's', 't']);
|
||||
});
|
||||
it("'test'.split(/(?:)/, null) results in []", function () {
|
||||
expect('test'.split(/(?:)/, null)).toEqual([]);
|
||||
});
|
||||
it("'test'.split(/(?:)/, NaN) results in []", function () {
|
||||
expect('test'.split(/(?:)/, NaN)).toEqual([]);
|
||||
});
|
||||
it("'test'.split(/(?:)/, true) results in ['t']", function () {
|
||||
expect('test'.split(/(?:)/, true)).toEqual(['t']);
|
||||
});
|
||||
it("'test'.split(/(?:)/, '2') results in ['t', 'e']", function () {
|
||||
expect('test'.split(/(?:)/, '2')).toEqual(['t', 'e']);
|
||||
});
|
||||
it("'test'.split(/(?:)/, 'two') results in []", function () {
|
||||
expect('test'.split(/(?:)/, 'two')).toEqual([]);
|
||||
});
|
||||
it("'a'.split(/-/) results in ['a']", function () {
|
||||
expect('a'.split(/-/)).toEqual(['a']);
|
||||
});
|
||||
it("'a'.split(/-?/) results in ['a']", function () {
|
||||
expect('a'.split(/-?/)).toEqual(['a']);
|
||||
});
|
||||
it("'a'.split(/-??/) results in ['a']", function () {
|
||||
expect('a'.split(/-??/)).toEqual(['a']);
|
||||
});
|
||||
it("'a'.split(/a/) results in ['', '']", function () {
|
||||
expect('a'.split(/a/)).toEqual(['', '']);
|
||||
});
|
||||
it("'a'.split(/a?/) results in ['', '']", function () {
|
||||
expect('a'.split(/a?/)).toEqual(['', '']);
|
||||
});
|
||||
it("'a'.split(/a??/) results in ['a']", function () {
|
||||
expect('a'.split(/a??/)).toEqual(['a']);
|
||||
});
|
||||
it("'ab'.split(/-/) results in ['ab']", function () {
|
||||
expect('ab'.split(/-/)).toEqual(['ab']);
|
||||
});
|
||||
it("'ab'.split(/-?/) results in ['a', 'b']", function () {
|
||||
expect('ab'.split(/-?/)).toEqual(['a', 'b']);
|
||||
});
|
||||
it("'ab'.split(/-??/) results in ['a', 'b']", function () {
|
||||
expect('ab'.split(/-??/)).toEqual(['a', 'b']);
|
||||
});
|
||||
it("'a-b'.split(/-/) results in ['a', 'b']", function () {
|
||||
expect('a-b'.split(/-/)).toEqual(['a', 'b']);
|
||||
});
|
||||
it("'a-b'.split(/-?/) results in ['a', 'b']", function () {
|
||||
expect('a-b'.split(/-?/)).toEqual(['a', 'b']);
|
||||
});
|
||||
it("'a-b'.split(/-??/) results in ['a', '-', 'b']", function () {
|
||||
expect('a-b'.split(/-??/)).toEqual(['a', '-', 'b']);
|
||||
});
|
||||
it("'a--b'.split(/-/) results in ['a', '', 'b']", function () {
|
||||
expect('a--b'.split(/-/)).toEqual(['a', '', 'b']);
|
||||
});
|
||||
it("'a--b'.split(/-?/) results in ['a', '', 'b']", function () {
|
||||
expect('a--b'.split(/-?/)).toEqual(['a', '', 'b']);
|
||||
});
|
||||
it("'a--b'.split(/-??/) results in ['a', '-', '-', 'b']", function () {
|
||||
expect('a--b'.split(/-??/)).toEqual(['a', '-', '-', 'b']);
|
||||
});
|
||||
it("''.split(/()()/) results in []", function () {
|
||||
expect(''.split(/()()/)).toEqual([]);
|
||||
});
|
||||
it("'.'.split(/()()/) results in ['.']", function () {
|
||||
expect('.'.split(/()()/)).toEqual(['.']);
|
||||
});
|
||||
it("'.'.split(/(.?)(.?)/) results in ['', '.', '', '']", function () {
|
||||
expect('.'.split(/(.?)(.?)/)).toEqual(['', '.', '', '']);
|
||||
});
|
||||
it("'.'.split(/(.??)(.??)/) results in ['.']", function () {
|
||||
expect('.'.split(/(.??)(.??)/)).toEqual(['.']);
|
||||
});
|
||||
it("'.'.split(/(.)?(.)?/) results in ['', '.', undefined, '']", function () {
|
||||
expect('.'.split(/(.)?(.)?/)).toEqual(['', '.', undefined, '']);
|
||||
});
|
||||
it("'A<B>bold</B>and<CODE>coded</CODE>'.split(/<(\\/)?([^<>]+)>/) results in ['A', undefined, 'B', 'bold', '/', 'B', 'and', undefined, 'CODE', 'coded', '/', 'CODE', '']", function () {
|
||||
expect('A<B>bold</B>and<CODE>coded</CODE>'.split(/<(\/)?([^<>]+)>/)).toEqual(['A', undefined, 'B', 'bold', '/', 'B', 'and', undefined, 'CODE', 'coded', '/', 'CODE', '']);
|
||||
});
|
||||
it("'tesst'.split(/(s)*/) results in ['t', undefined, 'e', 's', 't']", function () {
|
||||
expect('tesst'.split(/(s)*/)).toEqual(['t', undefined, 'e', 's', 't']);
|
||||
});
|
||||
it("'tesst'.split(/(s)*?/) results in ['t', undefined, 'e', undefined, 's', undefined, 's', undefined, 't']", function () {
|
||||
expect('tesst'.split(/(s)*?/)).toEqual(['t', undefined, 'e', undefined, 's', undefined, 's', undefined, 't']);
|
||||
});
|
||||
it("'tesst'.split(/(s*)/) results in ['t', '', 'e', 'ss', 't']", function () {
|
||||
expect('tesst'.split(/(s*)/)).toEqual(['t', '', 'e', 'ss', 't']);
|
||||
});
|
||||
it("'tesst'.split(/(s*?)/) results in ['t', '', 'e', '', 's', '', 's', '', 't']", function () {
|
||||
expect('tesst'.split(/(s*?)/)).toEqual(['t', '', 'e', '', 's', '', 's', '', 't']);
|
||||
});
|
||||
it("'tesst'.split(/(?:s)*/) results in ['t', 'e', 't']", function () {
|
||||
expect('tesst'.split(/(?:s)*/)).toEqual(['t', 'e', 't']);
|
||||
});
|
||||
it("'tesst'.split(/(?=s+)/) results in ['te', 's', 'st']", function () {
|
||||
expect('tesst'.split(/(?=s+)/)).toEqual(['te', 's', 'st']);
|
||||
});
|
||||
it("'test'.split('t') results in ['', 'es', '']", function () {
|
||||
expect('test'.split('t')).toEqual(['', 'es', '']);
|
||||
});
|
||||
it("'test'.split('es') results in ['t', 't']", function () {
|
||||
expect('test'.split('es')).toEqual(['t', 't']);
|
||||
});
|
||||
it("'test'.split(/t/) results in ['', 'es', '']", function () {
|
||||
expect('test'.split(/t/)).toEqual(['', 'es', '']);
|
||||
});
|
||||
it("'test'.split(/es/) results in ['t', 't']", function () {
|
||||
expect('test'.split(/es/)).toEqual(['t', 't']);
|
||||
});
|
||||
it("'test'.split(/(t)/) results in ['', 't', 'es', 't', '']", function () {
|
||||
expect('test'.split(/(t)/)).toEqual(['', 't', 'es', 't', '']);
|
||||
});
|
||||
it("'test'.split(/(es)/) results in ['t', 'es', 't']", function () {
|
||||
expect('test'.split(/(es)/)).toEqual(['t', 'es', 't']);
|
||||
});
|
||||
it("'test'.split(/(t)(e)(s)(t)/) results in ['', 't', 'e', 's', 't', '']", function () {
|
||||
expect('test'.split(/(t)(e)(s)(t)/)).toEqual(['', 't', 'e', 's', 't', '']);
|
||||
});
|
||||
it("'.'.split(/(((.((.??)))))/) results in ['', '.', '.', '.', '', '', '']", function () {
|
||||
expect('.'.split(/(((.((.??)))))/)).toEqual(['', '.', '.', '.', '', '', '']);
|
||||
});
|
||||
it("'.'.split(/(((((.??)))))/) results in ['.']", function () {
|
||||
expect('.'.split(/(((((.??)))))/)).toEqual(['.']);
|
||||
});
|
||||
it("'a b c d'.split(/ /, -(Math.pow(2, 32) - 1)) results in ['a']", function () {
|
||||
expect('a b c d'.split(/ /, -(Math.pow(2, 32) - 1))).toEqual(['a']);
|
||||
});
|
||||
it("'a b c d'.split(/ /, Math.pow(2, 32) + 1) results in ['a']", function () {
|
||||
expect('a b c d'.split(/ /, Math.pow(2, 32) + 1)).toEqual(['a']);
|
||||
});
|
||||
it("'a b c d'.split(/ /, Infinity) results in []", function () {
|
||||
expect('a b c d'.split(/ /, Infinity)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with the second argument', function () {
|
||||
expect('a b'.split(/ /, 1)).toEqual(['a']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#indexOf()', function () {
|
||||
it('has basic support', function () {
|
||||
expect('abcab'.indexOf('a')).toBe(0);
|
||||
expect('abcab'.indexOf('a', 1)).toBe(3);
|
||||
expect('abcab'.indexOf('a', 4)).toBe(-1);
|
||||
});
|
||||
|
||||
it('works with unicode', function () {
|
||||
expect('あいabcあいabc'.indexOf('あい')).toBe(0);
|
||||
expect('あいabcあいabc'.indexOf('あい', 0)).toBe(0);
|
||||
expect('あいabcあいabc'.indexOf('あい', 1)).toBe(5);
|
||||
expect('あいabcあいabc'.indexOf('あい', 6)).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#lastIndexOf()', function () {
|
||||
it('has the right length', function () {
|
||||
expect(String.prototype.lastIndexOf.length).toBe(1);
|
||||
});
|
||||
|
||||
it('has basic support', function () {
|
||||
expect('abcd'.lastIndexOf('d')).toBe(3);
|
||||
expect('abcd'.lastIndexOf('d', 3)).toBe(3);
|
||||
expect('abcd'.lastIndexOf('d', 2)).toBe(-1);
|
||||
});
|
||||
|
||||
it('works with unicode', function () {
|
||||
expect('abcあい'.lastIndexOf('あい')).toBe(3);
|
||||
expect('abcあい'.lastIndexOf('あい', 3)).toBe(3);
|
||||
expect('abcあい'.lastIndexOf('あい', 2)).toBe(-1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user