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