refactor: kill MapWrapper
This commit is contained in:
parent
ec92f4b198
commit
2a3f4d7b17
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
import {SpyObject} from '@angular/core/testing/testing_internal';
|
import {SpyObject} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {MapWrapper} from '../../platform-browser/src/facade/collection';
|
|
||||||
|
|
||||||
class TestObj {
|
class TestObj {
|
||||||
prop: any;
|
prop: any;
|
||||||
constructor(prop: any) { this.prop = prop; }
|
constructor(prop: any) { this.prop = prop; }
|
||||||
@ -25,9 +23,9 @@ export function main() {
|
|||||||
describe('testing', () => {
|
describe('testing', () => {
|
||||||
describe('equality', () => {
|
describe('equality', () => {
|
||||||
it('should structurally compare objects', () => {
|
it('should structurally compare objects', () => {
|
||||||
var expected = new TestObj(new TestObj({'one': [1, 2]}));
|
const expected = new TestObj(new TestObj({'one': [1, 2]}));
|
||||||
var actual = new TestObj(new TestObj({'one': [1, 2]}));
|
const actual = new TestObj(new TestObj({'one': [1, 2]}));
|
||||||
var falseActual = new TestObj(new TestObj({'one': [1, 3]}));
|
const falseActual = new TestObj(new TestObj({'one': [1, 3]}));
|
||||||
|
|
||||||
expect(actual).toEqual(expected);
|
expect(actual).toEqual(expected);
|
||||||
expect(falseActual).not.toEqual(expected);
|
expect(falseActual).not.toEqual(expected);
|
||||||
@ -36,7 +34,8 @@ export function main() {
|
|||||||
|
|
||||||
describe('toEqual for Maps', () => {
|
describe('toEqual for Maps', () => {
|
||||||
it('should detect equality for same reference', () => {
|
it('should detect equality for same reference', () => {
|
||||||
var m1 = MapWrapper.createFromStringMap({'a': 1});
|
const m1: Map<string, number> = new Map();
|
||||||
|
m1.set('a', 1);
|
||||||
expect(m1).toEqual(m1);
|
expect(m1).toEqual(m1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -49,15 +48,18 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should detect missing entries', () => {
|
it('should detect missing entries', () => {
|
||||||
expect(MapWrapper.createFromStringMap({
|
const m1: Map<string, number> = new Map();
|
||||||
'a': 1
|
m1.set('a', 1);
|
||||||
})).not.toEqual(MapWrapper.createFromStringMap({}));
|
const m2: Map<string, number> = new Map();
|
||||||
|
expect(m1).not.toEqual(m2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect different values', () => {
|
it('should detect different values', () => {
|
||||||
expect(MapWrapper.createFromStringMap({
|
const m1: Map<string, number> = new Map();
|
||||||
'a': 1
|
m1.set('a', 1);
|
||||||
})).not.toEqual(MapWrapper.createFromStringMap({'a': 2}));
|
const m2: Map<string, number> = new Map();
|
||||||
|
m2.set('a', 2);
|
||||||
|
expect(m1).not.toEqual(m2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect additional entries', () => {
|
it('should detect additional entries', () => {
|
||||||
|
@ -8,16 +8,6 @@
|
|||||||
|
|
||||||
import {getSymbolIterator, isJsObject, isPresent} from './lang';
|
import {getSymbolIterator, isJsObject, isPresent} from './lang';
|
||||||
|
|
||||||
export class MapWrapper {
|
|
||||||
static createFromStringMap<T>(stringMap: {[key: string]: T}): Map<string, T> {
|
|
||||||
const result = new Map<string, T>();
|
|
||||||
for (let prop in stringMap) {
|
|
||||||
result.set(prop, stringMap[prop]);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps Javascript Objects
|
* Wraps Javascript Objects
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user