git ssb

0+

wanderer🌟 / referenceMap



Tree: 41ded6aabd6fa84c1a968c7d48defe3964a969e1

Files: 41ded6aabd6fa84c1a968c7d48defe3964a969e1 / tests / index.js

1068 bytesRaw
1const tape = require('tape')
2const ReferanceMap = require('../index.js')
3
4tape('referance mapping', t => {
5 t.plan(9)
6 const referanceMap = new ReferanceMap()
7 const obj1 = {}
8 const obj2 = {}
9 const ref1 = referanceMap.add(obj1)
10 const ref2 = referanceMap.add(obj2)
11 t.equals(ref1, 0, 'should produce correct refs')
12 t.equals(ref2, 1, 'should produce correct refs')
13
14 t.equals(referanceMap.has(ref1), true, 'should detect if it has the ref')
15
16 const foundObj1 = referanceMap.get(ref1)
17 const foundObj2 = referanceMap.get(ref2)
18
19 t.equals(foundObj1, obj1, 'should get the correct object')
20 t.equals(foundObj2, obj2, 'should get the correct object')
21
22 t.equals(referanceMap.size, 2, 'should return the correct size')
23
24 referanceMap.delete(ref1)
25 try {
26 referanceMap.get(ref1)
27 } catch (e) {
28 t.true(true, 'should delete refances')
29 }
30
31 t.equals(referanceMap.has(ref1), false, 'should detect if it does not has the ref')
32
33 referanceMap.clear()
34 try {
35 referanceMap.get(ref2)
36 } catch (e) {
37 t.true(true, 'should clear refances')
38 }
39})
40

Built with git-ssb-web