Merge branch 'ie11-maps-support' of https://github.com/Volox/jasmine into Volox-ie11-maps-support
- Merges #1477 from @Volox - Fixes #1472
This commit is contained in:
@@ -223,6 +223,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return obj.nodeType > 0;
|
return obj.nodeType > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
j$.isMap = function(obj) {
|
||||||
|
return typeof jasmineGlobal.Map !== 'undefined' && obj.constructor === jasmineGlobal.Map;
|
||||||
|
};
|
||||||
|
|
||||||
j$.isPromise = function(obj) {
|
j$.isPromise = function(obj) {
|
||||||
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
||||||
};
|
};
|
||||||
@@ -2775,26 +2779,34 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (className == '[object Map]') {
|
} else if (j$.isMap(a) && j$.isMap(b)) {
|
||||||
if (a.size != b.size) {
|
if (a.size != b.size) {
|
||||||
diffBuilder.record(a, b);
|
diffBuilder.record(a, b);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keysA = [];
|
||||||
|
var keysB = [];
|
||||||
|
a.forEach( function( valueA, keyA ) {
|
||||||
|
keysA.push( keyA );
|
||||||
|
});
|
||||||
|
b.forEach( function( valueB, keyB ) {
|
||||||
|
keysB.push( keyB );
|
||||||
|
});
|
||||||
|
|
||||||
// For both sets of keys, check they map to equal values in both maps.
|
// For both sets of keys, check they map to equal values in both maps.
|
||||||
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
||||||
var mapKeys = [a.keys(), b.keys()];
|
var mapKeys = [keysA, keysB];
|
||||||
var cmpKeys = [b.keys(), a.keys()];
|
var cmpKeys = [keysB, keysA];
|
||||||
var mapIter, mapKeyIt, mapKey, mapValueA, mapValueB;
|
var mapIter, mapKey, mapValueA, mapValueB;
|
||||||
var cmpIter, cmpKeyIt, cmpKey;
|
var cmpIter, cmpKey;
|
||||||
for (i = 0; result && i < mapKeys.length; i++) {
|
for (i = 0; result && i < mapKeys.length; i++) {
|
||||||
mapIter = mapKeys[i];
|
mapIter = mapKeys[i];
|
||||||
cmpIter = cmpKeys[i];
|
cmpIter = cmpKeys[i];
|
||||||
mapKeyIt = mapIter.next();
|
|
||||||
cmpKeyIt = cmpIter.next();
|
for (var j = 0; result && j < mapIter.length; j++) {
|
||||||
while (result && !mapKeyIt.done) {
|
mapKey = mapIter[j];
|
||||||
mapKey = mapKeyIt.value;
|
cmpKey = cmpIter[j];
|
||||||
cmpKey = cmpKeyIt.value;
|
|
||||||
mapValueA = a.get(mapKey);
|
mapValueA = a.get(mapKey);
|
||||||
|
|
||||||
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
||||||
@@ -2807,8 +2819,6 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
mapValueB = b.get(mapKey);
|
mapValueB = b.get(mapKey);
|
||||||
}
|
}
|
||||||
result = eq(mapValueA, mapValueB, aStack, bStack, customTesters, j$.NullDiffBuilder());
|
result = eq(mapValueA, mapValueB, aStack, bStack, customTesters, j$.NullDiffBuilder());
|
||||||
mapKeyIt = mapIter.next();
|
|
||||||
cmpKeyIt = cmpIter.next();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4040,7 +4050,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.emitScalar('Date(' + value + ')');
|
this.emitScalar('Date(' + value + ')');
|
||||||
} else if (j$.getType_(value) == '[object Set]') {
|
} else if (j$.getType_(value) == '[object Set]') {
|
||||||
this.emitSet(value);
|
this.emitSet(value);
|
||||||
} else if (j$.getType_(value) == '[object Map]') {
|
} else if (j$.isMap(value)) {
|
||||||
this.emitMap(value);
|
this.emitMap(value);
|
||||||
} else if (j$.isTypedArray_(value)) {
|
} else if (j$.isTypedArray_(value)) {
|
||||||
this.emitTypedArray(value);
|
this.emitTypedArray(value);
|
||||||
@@ -4157,13 +4167,18 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
this.append('Map( ');
|
this.append('Map( ');
|
||||||
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||||
var iter = map.entries();
|
var i = 0;
|
||||||
for (var i = 0; i < size; i++) {
|
map.forEach( function( value, key ) {
|
||||||
|
if (i >= size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
this.append(', ');
|
this.append(', ');
|
||||||
}
|
}
|
||||||
this.format(iter.next().value);
|
this.format([key,value]);
|
||||||
}
|
|
||||||
|
i++;
|
||||||
|
}, this );
|
||||||
if (map.size > size){
|
if (map.size > size){
|
||||||
this.append(', ...');
|
this.append(', ...');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ describe("jasmineUnderTest.pp", function () {
|
|||||||
describe('stringify maps', function() {
|
describe('stringify maps', function() {
|
||||||
it("should stringify maps properly", function() {
|
it("should stringify maps properly", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
expect(jasmineUnderTest.pp(new Map([[1, 2]]))).toEqual("Map( [ 1, 2 ] )");
|
var map = new Map();
|
||||||
|
map.set(1,2);
|
||||||
|
expect(jasmineUnderTest.pp(map)).toEqual("Map( [ 1, 2 ] )");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should truncate maps with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
|
it("should truncate maps with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
|
||||||
@@ -45,7 +47,11 @@ describe("jasmineUnderTest.pp", function () {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
expect(jasmineUnderTest.pp(new Map([["a", 1], ["b", 2], ["c", 3]]))).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
var map = new Map();
|
||||||
|
map.set("a",1);
|
||||||
|
map.set("b",2);
|
||||||
|
map.set("c",3);
|
||||||
|
expect(jasmineUnderTest.pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||||
}
|
}
|
||||||
@@ -120,15 +126,15 @@ describe("jasmineUnderTest.pp", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should truncate objects with too many keys", function () {
|
it("should truncate objects with too many keys", function () {
|
||||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
var long = {a: 1, b: 2, c: 3};
|
var long = {a: 1, b: 2, c: 3};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
expect(jasmineUnderTest.pp(long)).toEqual("Object({ a: 1, b: 2, ... })");
|
expect(jasmineUnderTest.pp(long)).toEqual("Object({ a: 1, b: 2, ... })");
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function withMaxChars(maxChars, fn) {
|
function withMaxChars(maxChars, fn) {
|
||||||
@@ -251,9 +257,9 @@ describe("jasmineUnderTest.pp", function () {
|
|||||||
|
|
||||||
it("should stringify spy objects properly", function() {
|
it("should stringify spy objects properly", function() {
|
||||||
var TestObject = {
|
var TestObject = {
|
||||||
someFunction: function() {}
|
someFunction: function() {}
|
||||||
},
|
},
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
|
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() {return [];}});
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() {return [];}});
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ describe("matchersUtil", function() {
|
|||||||
|
|
||||||
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
|
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
|
||||||
var one = [1,2,3],
|
var one = [1,2,3],
|
||||||
two = [1,2,3];
|
two = [1,2,3];
|
||||||
|
|
||||||
one.foo = 'bar';
|
one.foo = 'bar';
|
||||||
two.foo = 'baz';
|
two.foo = 'baz';
|
||||||
@@ -81,7 +81,7 @@ describe("matchersUtil", function() {
|
|||||||
|
|
||||||
it("passes for Arrays with equivalent contents and properties", function() {
|
it("passes for Arrays with equivalent contents and properties", function() {
|
||||||
var one = [1,2,3],
|
var one = [1,2,3],
|
||||||
two = [1,2,3];
|
two = [1,2,3];
|
||||||
|
|
||||||
one.foo = 'bar';
|
one.foo = 'bar';
|
||||||
two.foo = 'bar';
|
two.foo = 'bar';
|
||||||
@@ -122,7 +122,7 @@ describe("matchersUtil", function() {
|
|||||||
|
|
||||||
it("passes for Objects that are equivalent (with cycles)", function() {
|
it("passes for Objects that are equivalent (with cycles)", function() {
|
||||||
var actual = { a: "foo" },
|
var actual = { a: "foo" },
|
||||||
expected = { a: "foo" };
|
expected = { a: "foo" };
|
||||||
|
|
||||||
actual.b = actual;
|
actual.b = actual;
|
||||||
expected.b = actual;
|
expected.b = actual;
|
||||||
@@ -342,7 +342,7 @@ describe("matchersUtil", function() {
|
|||||||
|
|
||||||
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
|
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
|
||||||
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
||||||
symmetricTester = function(a, b) { return false; };
|
symmetricTester = function(a, b) { return false; };
|
||||||
|
|
||||||
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
||||||
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
||||||
@@ -360,7 +360,7 @@ describe("matchersUtil", function() {
|
|||||||
|
|
||||||
it("passes when an Any is compared to an Any that checks for the same type", function() {
|
it("passes when an Any is compared to an Any that checks for the same type", function() {
|
||||||
var any1 = new jasmineUnderTest.Any(Function),
|
var any1 = new jasmineUnderTest.Any(Function),
|
||||||
any2 = new jasmineUnderTest.Any(Function);
|
any2 = new jasmineUnderTest.Any(Function);
|
||||||
|
|
||||||
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
|
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -369,7 +369,7 @@ describe("matchersUtil", function() {
|
|||||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||||
|
|
||||||
var objA = Object.create(null),
|
var objA = Object.create(null),
|
||||||
objB = Object.create(null);
|
objB = Object.create(null);
|
||||||
|
|
||||||
objA.name = 'test';
|
objA.name = 'test';
|
||||||
objB.name = 'test';
|
objB.name = 'test';
|
||||||
@@ -381,7 +381,7 @@ describe("matchersUtil", function() {
|
|||||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||||
|
|
||||||
var objA = Object.create(null),
|
var objA = Object.create(null),
|
||||||
objB = Object.create(null);
|
objB = Object.create(null);
|
||||||
|
|
||||||
objA.name = 'test';
|
objA.name = 'test';
|
||||||
objB.test = 'name';
|
objB.test = 'name';
|
||||||
@@ -445,7 +445,8 @@ describe("matchersUtil", function() {
|
|||||||
|
|
||||||
it("passes when comparing identical maps", function() {
|
it("passes when comparing identical maps", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var mapA = new Map([[6, 5]]);
|
var mapA = new Map();
|
||||||
|
mapA.set(6, 5);
|
||||||
var mapB = new Map();
|
var mapB = new Map();
|
||||||
mapB.set(6, 5);
|
mapB.set(6, 5);
|
||||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||||
@@ -453,22 +454,34 @@ describe("matchersUtil", function() {
|
|||||||
|
|
||||||
it("passes when comparing identical maps with different insertion order", function() {
|
it("passes when comparing identical maps with different insertion order", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var mapA = new Map([['a', 3], [6, 1]]);
|
var mapA = new Map();
|
||||||
var mapB = new Map([[6, 1], ['a', 3]]);
|
mapA.set("a", 3);
|
||||||
|
mapA.set(6, 1);
|
||||||
|
var mapB = new Map();
|
||||||
|
mapB.set(6, 1);
|
||||||
|
mapB.set("a", 3);
|
||||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for maps with different elements", function() {
|
it("fails for maps with different elements", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var mapA = new Map([[6, 3], [5, 1]]);
|
var mapA = new Map();
|
||||||
var mapB = new Map([[6, 4], [5, 1]]);
|
mapA.set(6, 3);
|
||||||
|
mapA.set(5, 1);
|
||||||
|
var mapB = new Map();
|
||||||
|
mapB.set(6, 4);
|
||||||
|
mapB.set(5, 1);
|
||||||
|
|
||||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for maps of different size", function() {
|
it("fails for maps of different size", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var mapA = new Map([[6, 3]]);
|
var mapA = new Map();
|
||||||
var mapB = new Map([[6, 4], [5, 1]]);
|
mapA.set(6, 3);
|
||||||
|
var mapB = new Map();
|
||||||
|
mapB.set(6, 4);
|
||||||
|
mapB.set(5, 1);
|
||||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -485,28 +498,28 @@ describe("matchersUtil", function() {
|
|||||||
Object.defineProperty(Array.prototype, 'findIndex', {
|
Object.defineProperty(Array.prototype, 'findIndex', {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
value: function (predicate) {
|
value: function (predicate) {
|
||||||
if (this === null) {
|
if (this === null) {
|
||||||
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof predicate !== 'function') {
|
if (typeof predicate !== 'function') {
|
||||||
throw new TypeError('predicate must be a function');
|
throw new TypeError('predicate must be a function');
|
||||||
}
|
}
|
||||||
|
|
||||||
var list = Object(this);
|
var list = Object(this);
|
||||||
var length = list.length >>> 0;
|
var length = list.length >>> 0;
|
||||||
var thisArg = arguments[1];
|
var thisArg = arguments[1];
|
||||||
var value;
|
var value;
|
||||||
|
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
value = list[i];
|
value = list[i];
|
||||||
if (predicate.call(thisArg, value, i, list)) {
|
if (predicate.call(thisArg, value, i, list)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -436,11 +436,13 @@ describe("toEqual", function() {
|
|||||||
// == Maps ==
|
// == Maps ==
|
||||||
|
|
||||||
it("does not report mismatches between deep equal Maps", function() {
|
it("does not report mismatches between deep equal Maps", function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
// values are the same but with different object identity
|
// values are the same but with different object identity
|
||||||
var actual = new Map([['a', {x: 1}]]),
|
var actual = new Map();
|
||||||
expected = new Map([['a', {x: 1}]]);
|
actual.set('a',{x:1});
|
||||||
|
var expected = new Map();
|
||||||
|
expected.set('a',{x:1});
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -448,9 +450,11 @@ describe("toEqual", function() {
|
|||||||
it("reports deep mismatches within Maps", function() {
|
it("reports deep mismatches within Maps", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map([['a', {x: 1}]]),
|
var actual = new Map();
|
||||||
expected = new Map([['a', {x: 2}]]),
|
actual.set('a',{x:1});
|
||||||
message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
var expected = new Map();
|
||||||
|
expected.set('a',{x:2});
|
||||||
|
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
@@ -458,9 +462,12 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps nested in objects", function() {
|
it("reports mismatches between Maps nested in objects", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = {Maps: [new Map([['a', 1]])]},
|
var actual = {Maps:[new Map()]};
|
||||||
expected = {Maps: [new Map([['a', 2]])]},
|
actual.Maps[0].set('a',1);
|
||||||
message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
var expected = {Maps:[new Map()]};
|
||||||
|
expected.Maps[0].set('a',2);
|
||||||
|
|
||||||
|
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
@@ -468,9 +475,12 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps of different lengths", function() {
|
it("reports mismatches between Maps of different lengths", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map([['a', 1]]),
|
var actual = new Map();
|
||||||
expected = new Map([['a', 2], ['b', 1]]),
|
actual.set('a',1);
|
||||||
message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
var expected = new Map();
|
||||||
|
expected.set('a',2);
|
||||||
|
expected.set('b',1);
|
||||||
|
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
@@ -478,18 +488,22 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps with equal values but differing keys", function() {
|
it("reports mismatches between Maps with equal values but differing keys", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map([['a', 1]]),
|
var actual = new Map();
|
||||||
expected = new Map([['b', 1]]),
|
actual.set('a',1);
|
||||||
message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
var expected = new Map();
|
||||||
|
expected.set('b',1);
|
||||||
|
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not report mismatches between Maps with keys with same object identity", function() {
|
it("does not report mismatches between Maps with keys with same object identity", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var key = {x: 1},
|
var key = {x: 1};
|
||||||
actual = new Map([[key, 2]]),
|
var actual = new Map();
|
||||||
expected = new Map([[key, 2]]);
|
actual.set(key,2);
|
||||||
|
var expected = new Map();
|
||||||
|
expected.set(key,2);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -497,9 +511,11 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps with identical keys with different object identity", function() {
|
it("reports mismatches between Maps with identical keys with different object identity", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map([[{x: 1}, 2]]),
|
var actual = new Map();
|
||||||
expected = new Map([[{x: 1}, 2]]),
|
actual.set({x:1},2);
|
||||||
message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
var expected = new Map();
|
||||||
|
expected.set({x:1},2);
|
||||||
|
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
@@ -507,8 +523,11 @@ describe("toEqual", function() {
|
|||||||
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map([['a', 1]]),
|
var actual = new Map();
|
||||||
expected = new Map([[jasmineUnderTest.anything(), 1]]);
|
actual.set('a',1);
|
||||||
|
var expected = new Map();
|
||||||
|
expected.set(jasmineUnderTest.anything(),1);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -516,9 +535,12 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var key = Symbol(),
|
var key = Symbol();
|
||||||
actual = new Map([[key, 1]]),
|
var actual = new Map();
|
||||||
expected = new Map([[key, 1]]);
|
actual.set(key,1);
|
||||||
|
var expected = new Map();
|
||||||
|
expected.set(key,1);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -526,9 +548,11 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var actual = new Map([[Symbol(), 1]]),
|
var actual = new Map();
|
||||||
expected = new Map([[Symbol(), 1]]),
|
actual.set(Symbol(),1);
|
||||||
message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
var expected = new Map();
|
||||||
|
expected.set(Symbol(),1);
|
||||||
|
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toBe(message);
|
expect(compareEquals(actual, expected).message).toBe(message);
|
||||||
});
|
});
|
||||||
@@ -537,8 +561,11 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var actual = new Map([[Symbol(), 1]]),
|
var actual = new Map();
|
||||||
expected = new Map([[jasmineUnderTest.anything(), 1]]);
|
actual.set(Symbol(),1);
|
||||||
|
var expected = new Map();
|
||||||
|
expected.set(jasmineUnderTest.anything(),1);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,25 @@
|
|||||||
if (typeof Map === 'undefined') { return false; }
|
if (typeof Map === 'undefined') { return false; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var s = new Map([['a', 4]]);
|
var s = new Map();
|
||||||
if (s.size !== 1) { return false; }
|
s.set('a',1);
|
||||||
if (s.keys().next().value !== 'a') { return false; }
|
s.set('b',2);
|
||||||
if (s.values().next().value !== 4) { return false; }
|
|
||||||
|
if (s.size !== 2) { return false; }
|
||||||
|
if (s.has('a') !== true) { return false; }
|
||||||
|
|
||||||
|
var iterations = 0;
|
||||||
|
var ifForEachWorking = true;
|
||||||
|
s.forEach(function(value, key, map) {
|
||||||
|
ifForEachWorking = ifForEachWorking && map === s;
|
||||||
|
if (key==='a') {
|
||||||
|
ifForEachWorking = ifForEachWorking && value===1;
|
||||||
|
}
|
||||||
|
iterations++;
|
||||||
|
});
|
||||||
|
if (iterations !== 2) { return false; }
|
||||||
|
if (ifForEachWorking !== true) { return false; }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.emitScalar('Date(' + value + ')');
|
this.emitScalar('Date(' + value + ')');
|
||||||
} else if (j$.getType_(value) == '[object Set]') {
|
} else if (j$.getType_(value) == '[object Set]') {
|
||||||
this.emitSet(value);
|
this.emitSet(value);
|
||||||
} else if (j$.getType_(value) == '[object Map]') {
|
} else if (j$.isMap(value)) {
|
||||||
this.emitMap(value);
|
this.emitMap(value);
|
||||||
} else if (j$.isTypedArray_(value)) {
|
} else if (j$.isTypedArray_(value)) {
|
||||||
this.emitTypedArray(value);
|
this.emitTypedArray(value);
|
||||||
@@ -157,13 +157,18 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
this.append('Map( ');
|
this.append('Map( ');
|
||||||
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||||
var iter = map.entries();
|
var i = 0;
|
||||||
for (var i = 0; i < size; i++) {
|
map.forEach( function( value, key ) {
|
||||||
|
if (i >= size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
this.append(', ');
|
this.append(', ');
|
||||||
}
|
}
|
||||||
this.format(iter.next().value);
|
this.format([key,value]);
|
||||||
}
|
|
||||||
|
i++;
|
||||||
|
}, this );
|
||||||
if (map.size > size){
|
if (map.size > size){
|
||||||
this.append(', ...');
|
this.append(', ...');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return obj.nodeType > 0;
|
return obj.nodeType > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
j$.isMap = function(obj) {
|
||||||
|
return typeof jasmineGlobal.Map !== 'undefined' && obj.constructor === jasmineGlobal.Map;
|
||||||
|
};
|
||||||
|
|
||||||
j$.isPromise = function(obj) {
|
j$.isPromise = function(obj) {
|
||||||
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -253,26 +253,34 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (className == '[object Map]') {
|
} else if (j$.isMap(a) && j$.isMap(b)) {
|
||||||
if (a.size != b.size) {
|
if (a.size != b.size) {
|
||||||
diffBuilder.record(a, b);
|
diffBuilder.record(a, b);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keysA = [];
|
||||||
|
var keysB = [];
|
||||||
|
a.forEach( function( valueA, keyA ) {
|
||||||
|
keysA.push( keyA );
|
||||||
|
});
|
||||||
|
b.forEach( function( valueB, keyB ) {
|
||||||
|
keysB.push( keyB );
|
||||||
|
});
|
||||||
|
|
||||||
// For both sets of keys, check they map to equal values in both maps.
|
// For both sets of keys, check they map to equal values in both maps.
|
||||||
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
||||||
var mapKeys = [a.keys(), b.keys()];
|
var mapKeys = [keysA, keysB];
|
||||||
var cmpKeys = [b.keys(), a.keys()];
|
var cmpKeys = [keysB, keysA];
|
||||||
var mapIter, mapKeyIt, mapKey, mapValueA, mapValueB;
|
var mapIter, mapKey, mapValueA, mapValueB;
|
||||||
var cmpIter, cmpKeyIt, cmpKey;
|
var cmpIter, cmpKey;
|
||||||
for (i = 0; result && i < mapKeys.length; i++) {
|
for (i = 0; result && i < mapKeys.length; i++) {
|
||||||
mapIter = mapKeys[i];
|
mapIter = mapKeys[i];
|
||||||
cmpIter = cmpKeys[i];
|
cmpIter = cmpKeys[i];
|
||||||
mapKeyIt = mapIter.next();
|
|
||||||
cmpKeyIt = cmpIter.next();
|
for (var j = 0; result && j < mapIter.length; j++) {
|
||||||
while (result && !mapKeyIt.done) {
|
mapKey = mapIter[j];
|
||||||
mapKey = mapKeyIt.value;
|
cmpKey = cmpIter[j];
|
||||||
cmpKey = cmpKeyIt.value;
|
|
||||||
mapValueA = a.get(mapKey);
|
mapValueA = a.get(mapKey);
|
||||||
|
|
||||||
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
||||||
@@ -285,8 +293,6 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
mapValueB = b.get(mapKey);
|
mapValueB = b.get(mapKey);
|
||||||
}
|
}
|
||||||
result = eq(mapValueA, mapValueB, aStack, bStack, customTesters, j$.NullDiffBuilder());
|
result = eq(mapValueA, mapValueB, aStack, bStack, customTesters, j$.NullDiffBuilder());
|
||||||
mapKeyIt = mapIter.next();
|
|
||||||
cmpKeyIt = cmpIter.next();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user