git ssb

0+

wanderer🌟 / referenceMap



Tree: ad8282197e35e6d2049fcc7591a51a069351cefc

Files: ad8282197e35e6d2049fcc7591a51a069351cefc / tests / index.js

836 bytesRaw
1const tape = require('tape')
2const ReferanceMap = require('../index.js')
3
4tape('referance mapping', t => {
5 t.plan(6)
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 const foundObj1 = referanceMap.get(ref1)
15 const foundObj2 = referanceMap.get(ref2)
16
17 t.equals(foundObj1, obj1, 'should get the correct object')
18 t.equals(foundObj2, obj2, 'should get the correct object')
19
20 referanceMap.delete(ref1)
21 try {
22 referanceMap.get(ref1)
23 } catch (e) {
24 t.true(true, 'should delete refances')
25 }
26
27 referanceMap.clear()
28 try {
29 referanceMap.get(ref2)
30 } catch (e) {
31 t.true(true, 'should clear refances')
32 }
33})
34

Built with git-ssb-web