-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxyMap.js
57 lines (41 loc) · 1.33 KB
/
proxyMap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint-env mocha */
export default (should, M) => () => {
const p = M.proxyMap
it('size', () => {
const map = p(M.Map.fromObject({a: 1, b: 2, c: 3}))
map.size.should.be.exactly(3)
})
it('get() / set() / delete() / clear()', () => {
const map1 = p(M.Map.fromObject({a: 1, b: 2, c: 3}))
const map2 = map1.set('b', 50)
map1.get('b').should.be.exactly(2)
map2.get('b').should.be.exactly(50)
const map3 = map2.delete('c')
map2.get('c').should.be.exactly(3)
map3.has('c').should.be.exactly(false)
const map4 = map3.clear()
map3.size.should.be.exactly(2)
map4.size.should.be.exactly(0)
})
it('entries()', () => {
const map = p(M.Map.fromObject({a: 1, b: 2, c: 3}))
;[...map.entries()].should.eql([['a', 1], ['b', 2], ['c', 3]])
})
it('values() / keys() / [@@iterator]()', () => {
const map = p(M.Map.fromObject({a: 1, b: 2, c: 3}))
;[...map.values()].should.eql([1, 2, 3])
;[...map.keys()].should.eql(['a', 'b', 'c'])
;[...map[Symbol.iterator]()].should.eql([['a', 1], ['b', 2], ['c', 3]])
})
it('forEach()', () => {
const map = p(M.Map.fromObject({a: 1, b: 2, c: 3}))
let sum = 0
let keys = ''
map.forEach((v, k) => {
sum += v
keys += k.toUpperCase()
})
sum.should.be.exactly(6)
keys.should.be.exactly('ABC')
})
}