UNPKG

1.1 kBJavaScriptView Raw
1var test = require('tape');
2var KeyTree = require('../key-tree-store');
3
4
5test('`add` should store objects', function (t) {
6 var tree = new KeyTree();
7 var one = {id: 'one'};
8 var two = {id: 'two'};
9 var three = {id: 'three'};
10 var four = {id: 'four'};
11
12 tree.add('first', one);
13 tree.add('first.second', two);
14 tree.add('first.second', three);
15 tree.add('first.second.third', four);
16
17 t.equal(Object.keys(tree.storage).length, 3);
18
19 t.equal(tree.storage['first.second'].length, 2, 'should be two for `first.second` key');
20 t.equal(tree.get('first').length, 4, 'should be 4 that match');
21 t.equal(tree.get('first.second').length, 3, 'should be 3 that match');
22 t.equal(tree.get('first.second.third').length, 1, 'should be 1 that match');
23
24 t.equal(tree.get('second.third').length, 0, 'keypaths should start at the start');
25
26 t.equal(tree.get('first.seco').length, 0, 'keypaths must be the full path, or end in a . to match');
27
28 tree.remove(two);
29 t.equal(tree.get('first').length, 3, 'should be 3 that match after removal');
30
31 t.end();
32});