git ssb

0+

cel / pull-kvdiff



Tree: 93f33e1b056d798cd81e1e99a65e2b8c4cc81da3

Files: 93f33e1b056d798cd81e1e99a65e2b8c4cc81da3 / test.js

2077 bytesRaw
1var test = require('tape')
2var pull = require('pull-stream')
3var kvdiff = require('.')
4
5test('kvdiff', function (t) {
6 pull(
7 kvdiff([
8 pull.values([
9 {key: 'a', value: 1},
10 {key: 'b', value: 2},
11 {key: 'c', value: 3},
12 ]),
13 pull.values([
14 {key: 'a', value: 1},
15 {key: 'b', value: 2},
16 {key: 'c', value: 4},
17 ]),
18 pull.values([
19 {key: 'a', value: 1},
20 {key: 'b', value: 2},
21 {key: 'd', value: 3},
22 ])
23 ],
24 'key'
25 ),
26 pull.collect(function (err, diff) {
27 t.error(err, 'collect')
28 t.deepEquals(diff, [
29 {
30 diff: {
31 key: [ 'c', , ],
32 value: [ 3, 4, ]
33 },
34 key: 'c',
35 values: [ { key: 'c', value: 3 }, { key: 'c', value: 4 }, ] },
36 {
37 diff: {
38 key: [ , , 'd' ],
39 value: [ , , 3 ]
40 },
41 key: 'd',
42 values: [ , , { key: 'd', value: 3 } ] }
43
44 ], 'values')
45 t.end()
46 }))
47})
48
49test('kvdiff 2', function (t) {
50 pull(
51 kvdiff([
52 pull.values([
53 {key: 'a', value: 1},
54 {key: 'b', value: 2},
55 {key: 'c', value: 3},
56 ]),
57 pull.values([
58 {key: 'a', value: 1},
59 {key: 'b', value: 3},
60 {key: 'd', value: 3},
61 ])
62 ], 'key'),
63 pull.collect(function (err, diff) {
64 t.error(err, 'collect')
65 t.deepEquals(diff, [
66 { key: 'b',
67 values: [ { key: 'b', value: 2 }, { key: 'b', value: 3 } ],
68 diff: { value: [ 2, 3 ] } },
69 { key: 'c',
70 values: [ { key: 'c', value: 3 }, ],
71 diff: { key: [ 'c', ], value: [ 3, ] } },
72 { key: 'd',
73 values: [ , { key: 'd', value: 3 } ],
74 diff: { key: [ , 'd' ], value: [ , 3 ] } }
75 ])
76 t.end()
77 })
78 )
79})
80
81test('pass through source error', function (t) {
82 pull(
83 kvdiff([
84 pull.values([
85 {key: 'c', value: 3},
86 ]),
87 pull.error(new Error('blah'))
88 ], 'key'),
89 pull.collect(function (err, diff) {
90 t.ok(err, 'got error')
91 t.end()
92 })
93 )
94})
95

Built with git-ssb-web