10000 Adds Map.mergeDeep Symbol tests by abacaphiliac · Pull Request #1404 · immutable-js/immutable-js · GitHub
[go: up one dir, main page]

Skip to content

Adds Map.mergeDeep Symbol tests #1404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions __tests__/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,40 @@ describe('Map', () => {
expect(map.toString()).toEqual('Map { 2: 2 }');
});

it('supports Symbols as tuple keys', () => {
const a = Symbol('a');
const b = Symbol('b');
const c = Symbol('c');
const m = Map([[a, 'a'], [b, 'b'], [c, 'c']]);
expect(m.size).toBe(3);
expect(m.get(a)).toBe('a');
expect(m.get(b)).toBe('b');
expect(m.get(c)).toBe('c');
});

it('Symbol keys are unique', () => {
const a = Symbol('FooBar');
const b = Symbol('FooBar');
const m = Map([[a, 'FizBuz'], [b, 'FooBar']);
expect(m.size).toBe(2);
expect(m.get(a)).toBe('FizBuz');
expect(m.get(b)).toBe('FooBar');
});

it('mergeDeep with tuple Symbol keys', () => {
const a = Symbol('a');
const b = Symbol('b');
const c = Symbol('c');
const d = Symbol('d');
const e = Symbol('e');
const f = Symbol('f');
const g = Symbol('g');

// Note the use of nested Map constructors, Map() does not do a deep conversion!
const m1 = Map([[a, Map([[b, Map([[c, 1], [d, 2]])]])]]);
const m2 = Map([[a, Map([[b, Map([[c, 10], [e, 20], [f, 30], [g, 40]])]])]]);
const merged = m1.mergeDeep(m2);

expect(merged).toEqual(Map([[a, Map([[b, Map([[c, 10], [d, 2], [e, 20], [f, AA5E 30], [g, 40]])]])]]));
});
});
18 changes: 18 additions & 0 deletions __tests__/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,22 @@ describe('merge', () => {
expect(merge(a, [], [])).toBe(a);
});

it('mergeDeep with tuple Symbol keys', () => {
const a = Symbol('a');
const b = Symbol('b');
const c = Symbol('c');
const d = Symbol('d');
const e = Symbol('e');
const f = Symbol('f');
const g = Symbol('g');

// Note the use of nested Map constructors, Map() does not do a deep conversion!
const m1 = Map([[a, Map([[b, Map([[c, 1], [d, 2]])]])]]);

// mergeDeep can be directly given a nested set of `Iterable<[K, V]>`
const merged = m1.mergeDeep([[a, [[b, [[c, 10], [e, 20], [f, 30], [g, 40]]]]]]);

expect(merged).toEqual(Map([[a, Map([[b, Map([[c, 10], [d, 2], [e, 20], [f, 30], [g, 40]])]])]]));
});

});
0