Files: 31b26dc43440dd6bb683c2f0e63e413890f26274 / tests / index.js
904 bytesRaw
1 | const tape = require('tape') |
2 | const ReferanceMap = require('../index.js') |
3 | |
4 | tape('referance mapping', t => { |
5 | t.plan(7) |
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 | t.equals(referanceMap.size, 2, 'should return the correct size') |
21 | |
22 | referanceMap.delete(ref1) |
23 | try { |
24 | referanceMap.get(ref1) |
25 | } catch (e) { |
26 | t.true(true, 'should delete refances') |
27 | } |
28 | |
29 | referanceMap.clear() |
30 | try { |
31 | referanceMap.get(ref2) |
32 | } catch (e) { |
33 | t.true(true, 'should clear refances') |
34 | } |
35 | }) |
36 |
Built with git-ssb-web