Skip to content

Commit 6cdec38

Browse files
committed
Improving test coverage
1 parent 219d698 commit 6cdec38

File tree

8 files changed

+68
-9
lines changed

8 files changed

+68
-9
lines changed

Diff for: lib/common.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ function iterateOverSparseArray(arr, fn, fromIndex, loop) {
831831
function getSparseArrayIndexes(arr, fromIndex, loop, fromRight) {
832832
var indexes = [], i;
833833
for (i in arr) {
834+
// istanbul ignore next
834835
if (isArrayIndex(i) && (loop || (fromRight ? i <= fromIndex : i >= fromIndex))) {
835836
indexes.push(+i);
836837
}
@@ -877,7 +878,7 @@ function mapWithShortcuts(el, f, context, mapArgs) {
877878
if (!f) {
878879
return el;
879880
} else if (f.apply) {
880-
return f.apply(context, mapArgs || []);
881+
return f.apply(context, mapArgs);
881882
} else if (isArray(f)) {
882883
return f.map(function(m) {
883884
return mapWithShortcuts(el, m, context, mapArgs);
@@ -1135,14 +1136,17 @@ function createFormatMatcher(bracketMatcher, percentMatcher, precheck) {
11351136
var Inflections = {};
11361137

11371138
function getAcronym(str) {
1139+
// istanbul ignore next
11381140
return Inflections.acronyms && Inflections.acronyms.find(str);
11391141
}
11401142

11411143
function getHumanWord(str) {
1144+
// istanbul ignore next
11421145
return Inflections.human && Inflections.human.find(str);
11431146
}
11441147

11451148
function runHumanRules(str) {
1149+
// istanbul ignore next
11461150
return Inflections.human && Inflections.human.runRules(str) || str;
11471151
}
11481152

Diff for: lib/core.js

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var PROPERTY_DESCRIPTOR_SUPPORT = !!(Object.defineProperty && Object.definePrope
2828

2929
// The global context. Rhino uses a different "global" keyword so
3030
// do an extra check to be sure that it's actually the global context.
31+
// istanbul ignore next
3132
var globalContext = typeof global !== 'undefined' && global.Object === Object ? global : this;
3233

3334
// Is the environment node?
@@ -43,6 +44,7 @@ var namespacesByName = {};
4344
var namespacesByClassString = {};
4445

4546
// Defining properties.
47+
// istanbul ignore next
4648
var defineProperty = PROPERTY_DESCRIPTOR_SUPPORT ? Object.defineProperty : definePropertyShim;
4749

4850
// A default chainable class for unknown types.

Diff for: lib/date.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ var FormatTokensBase = [
430430
// It will continue to be supported for Node and usage with the
431431
// understanding that it may be blank.
432432
var match = d.toString().match(TIMEZONE_ABBREVIATION_REG);
433-
return match ? match[1]: '';
433+
// istanbul ignore next
434+
return match ? match[1] : '';
434435
}
435436
},
436437
{

Diff for: test/browser/javascripts/suite-ui.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
}
7070
};
7171

72-
function getStringified(p) {
73-
var str, arr, isArray = p && p.join, arrayHasUndefined;
72+
function getStringified(p, stack) {
73+
var str, arr, isArray = p && p.join, arrayHasUndefined, isCyc;
7474
if (p && p.getTime && p.setHours) {
7575
return p.toString();
7676
}
@@ -80,6 +80,9 @@
8080
if(typeof p !== 'object') return String(p);
8181
str = isArray ? '[' : '{';
8282
arr = [];
83+
stack = stack || [];
84+
85+
stringify:
8386
for(var key in p){
8487
if(!p.hasOwnProperty(key)) continue;
8588
if(p[key] === undefined) {
@@ -89,7 +92,21 @@
8992
if (typeof val === 'string') {
9093
val = '"' + val + '"';
9194
}
92-
arr.push((isArray ? '' : key + ': ') + getStringified(val));
95+
isCyc = false;
96+
97+
// Cyclic structure check
98+
if (stack.length > 1) {
99+
var i = stack.length;
100+
while (i--) {
101+
if (stack[i] === val) {
102+
arr.push(key + ':CYC');
103+
continue stringify;
104+
}
105+
}
106+
}
107+
108+
stack.push(val);
109+
arr.push((isArray ? '' : key + ': ') + getStringified(val, stack));
93110
}
94111
}
95112
str += arr.join(',');

Diff for: test/suite/suite.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344

345345
// Equality test methods.
346346

347-
function isEqual(one, two) {
347+
function isEqual(one, two, stack) {
348348
var type, klass;
349349

350350
type = typeof one;
@@ -364,7 +364,7 @@
364364
} else if (klass === '[object Array]' || klass === '[object Arguments]') {
365365
return arrayIsEqual(one, two) && klass === testInternalToString.call(two);
366366
} else if (klass === '[object Object]' && ('hasOwnProperty' in one) && type === 'object') {
367-
return objectIsEqual(one, two) && klass === testInternalToString.call(two);
367+
return objectIsEqual(one, two, stack) && klass === testInternalToString.call(two);
368368
} else if (klass === '[object Number]' && isNaN(one) && isNaN(two)) {
369369
return true;
370370
} else if (klass === '[object String]' || klass === '[object Number]') {
@@ -415,13 +415,34 @@
415415
return result && onep === twop;
416416
}
417417

418-
function objectIsEqual(one, two) {
418+
function objectIsEqual(one, two, stack) {
419419
var onep = 0, twop = 0, key;
420+
421+
stack = stack || [];
422+
420423
if (one && two) {
424+
isEqual:
421425
for(key in one) {
422426
if (!one.hasOwnProperty(key)) continue;
423427
onep++;
424-
if (!isEqual(one[key], two[key])) {
428+
429+
// Cyclic structure check
430+
if (stack.length > 1) {
431+
var i = stack.length;
432+
while (i--) {
433+
if (stack[i] === one[key]) {
434+
if (one[key] !== two[key]) {
435+
return false;
436+
} else {
437+
continue isEqual;
438+
}
439+
}
440+
}
441+
}
442+
443+
stack.push(one[key]);
444+
445+
if (!isEqual(one[key], two[key], stack)) {
425446
return false;
426447
}
427448
}

Diff for: test/tests/array.js

+7
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ namespace('Array', function () {
420420
test([o1, o2], [o1], 'instances | same deep reference is equal');
421421
test([o1, o3], [o1, o3], 'instances | different deep reference is not equal');
422422

423+
var foo = {};
424+
test([{foo:foo}], [{foo:foo}], 'Handles cyclic structures');
425+
426+
var foo = {};
427+
foo.bar = foo;
428+
test([foo], [foo], 'Handles cyclic structures');
429+
423430
});
424431

425432
method('flatten', function() {

Diff for: test/tests/date.js

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ namespace('Date', function () {
128128
assertDateParsed('Friday', opt, testCreateDate('Friday'));
129129
assertDateParsed('Saturday', opt, testCreateDate('Saturday'));
130130

131+
// Relative dates with future
132+
assertDateParsed('the 15th', { future: true }, testDateSet(getRelativeDateReset(0,1),{date:15}));
131133

132134
// fromUTC option
133135

Diff for: test/tests/es7/array.js

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ namespace('Array', function () {
5757
Array.prototype.includes.call({length: thrower, 0: true}, true);
5858
}, 'fromIndex conversion throws', RangeError);
5959

60+
equal([0].includes(0), true, '[0] includes 0');
61+
equal([0].includes(-0), false, '[0] includes -0');
62+
equal([-0].includes(0), false, '[0] includes 0');
63+
equal([-0].includes(-0), true, '[0] includes -0');
64+
6065
});
6166

6267
});

0 commit comments

Comments
 (0)