Merge branch 'Volox-ie11-sets-support'

- Merges #1478 from @Volox
- Fixes #1355
This commit is contained in:
Gregg Van Hove
2018-01-12 17:33:11 -08:00
8 changed files with 202 additions and 86 deletions

View File

@@ -38,7 +38,7 @@ getJasmineRequireObj().pp = function(j$) {
this.emitScalar('HTMLNode');
} else if (value instanceof Date) {
this.emitScalar('Date(' + value + ')');
} else if (j$.getType_(value) == '[object Set]') {
} else if (j$.isSet(value)) {
this.emitSet(value);
} else if (j$.isMap(value)) {
this.emitMap(value);
@@ -137,13 +137,18 @@ getJasmineRequireObj().pp = function(j$) {
}
this.append('Set( ');
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
var iter = set.values();
for (var i = 0; i < size; i++) {
var i = 0;
set.forEach( function( value, key ) {
if (i >= size) {
return;
}
if (i > 0) {
this.append(', ');
}
this.format(iter.next().value);
}
this.format(value);
i++;
}, this );
if (set.size > size){
this.append(', ...');
}

View File

@@ -97,6 +97,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
return typeof jasmineGlobal.Map !== 'undefined' && obj.constructor === jasmineGlobal.Map;
};
j$.isSet = function(obj) {
return typeof jasmineGlobal.Set !== 'undefined' && obj.constructor === jasmineGlobal.Set;
};
j$.isPromise = function(obj) {
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
};

View File

@@ -300,48 +300,49 @@ getJasmineRequireObj().matchersUtil = function(j$) {
diffBuilder.record(a, b);
return false;
}
} else if (className == '[object Set]') {
} else if (j$.isSet(a) && j$.isSet(b)) {
if (a.size != b.size) {
diffBuilder.record(a, b);
return false;
}
var valuesA = [];
a.forEach( function( valueA ) {
valuesA.push( valueA );
});
var valuesB = [];
b.forEach( function( valueB ) {
valuesB.push( valueB );
});
// For both sets, check they are all contained in the other set
var setPairs = [[a, b], [b, a]];
var setPairs = [[valuesA, valuesB], [valuesB, valuesA]];
var stackPairs = [[aStack, bStack], [bStack, aStack]];
var baseIter, baseValueIt, baseValue, baseStack;
var otherSet, otherIter, otherValueIt, otherValue, otherStack;
var baseValues, baseValue, baseStack;
var otherValues, otherValue, otherStack;
var found;
var prevStackSize;
for (i = 0; result && i < setPairs.length; i++) {
baseIter = setPairs[i][0].values();
otherSet = setPairs[i][1];
baseValues = setPairs[i][0];
otherValues = setPairs[i][1];
baseStack = stackPairs[i][0];
otherStack = stackPairs[i][1];
// For each value in the base set...
baseValueIt = baseIter.next();
while (result && !baseValueIt.done) {
baseValue = baseValueIt.value;
for (var k = 0; result && k < baseValues.length; k++) {
baseValue = baseValues[k];
found = false;
// ... test that it is present in the other set
// Optimisation: start looking for value by object identity
found = otherSet.has(baseValue);
if (!found) {
otherIter = otherSet.values();
otherValueIt = otherIter.next();
}
// If not found, compare by value equality
while (!found && !otherValueIt.done) {
otherValue = otherValueIt.value;
for (var l = 0; !found && l < otherValues.length; l++) {
otherValue = otherValues[l];
prevStackSize = baseStack.length;
// compare by value equality
found = eq(baseValue, otherValue, baseStack, otherStack, customTesters, j$.NullDiffBuilder());
if (!found && prevStackSize !== baseStack.length) {
baseStack.splice(prevStackSize);
otherStack.splice(prevStackSize);
}
otherValueIt = otherIter.next();
}
result = result && found;
baseValueIt = baseIter.next();
}
}