-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
159 lines (132 loc) · 3.09 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
var concat = require('concat-stream')
, test = require('tape')
, createStream = require('./significant-stream')
, runTest = function (input, callback) {
var stream = createStream()
stream.pipe(concat({ encoding: 'object' }, callback))
input.forEach(function (data) { stream.write(data) })
stream.end()
}
test('empty', function (t) {
runTest([], function (actual) {
t.deepEqual(actual, [])
t.end()
})
})
test('one revision', function (t) {
var inputs = [ 'Hello, world', ]
runTest(inputs, function (actual) {
t.deepEqual(actual, inputs)
t.end()
})
})
test('multiple compatible actual', function (t) {
var inputs = [
'Hello'
, 'Hello, world'
, 'Hello, world!'
]
runTest(inputs, function (actual) {
t.deepEqual(actual, [ inputs[2] ])
t.end()
})
})
test('more complex, but compatible actual', function (t) {
var inputs = [
'Hello'
, 'world!'
, 'Hello, world!'
]
runTest(inputs, function (actual) {
t.deepEqual(actual, [ inputs[2] ])
t.end()
})
})
test('removing', function (t) {
var inputs = [
'Hello, world!'
, 'Hello'
]
runTest(inputs, function (actual) {
t.deepEqual(actual, inputs)
t.end()
})
})
test('multiple deletes', function (t) {
var inputs = [
'Hello, world!'
, 'Hello, world'
, 'Hello'
]
runTest(inputs, function (actual) {
t.deepEqual(actual, [ inputs[0], inputs[2] ])
t.end()
})
})
test('deletes & inserts', function (t) {
var inputs = [
'beep boop'
, 'Hello, world!'
, 'Hello, world'
, 'Hello'
, 'Hello2'
]
runTest(inputs, function (actual) {
t.deepEqual(actual, [ inputs[0], inputs[1], inputs[4] ])
t.end()
})
})
test('multiple ends with remove', function (t) {
var inputs = [
'Hello'
, 'Foo'
, ''
]
runTest(inputs, function (actual) {
t.deepEqual(actual, inputs)
t.end()
})
})
test('unchanged', function (t) {
var inputs = [
'Hello'
, 'Hello'
]
runTest(inputs, function (actual) {
t.deepEqual(actual, [ inputs[1] ])
t.end()
})
})
test('lots of inputs', function (t) {
var inputs = [
'Hello'
, 'Hello'
, 'Hello, world!'
, 'foo'
, 'foobar'
]
runTest(inputs, function (actual) {
t.deepEqual(actual, [ inputs[2], inputs[4] ])
t.end()
})
})
test('object as input', function (t) {
var input = [ { data: 'hej' }, { data: 'hejhopp' } ]
, stream = createStream({ key: 'data' })
stream.pipe(concat({ encoding: 'object' }, function (array) {
t.deepEqual(array, [ input[1] ])
t.end()
}))
input.forEach(function (row) { stream.write(row) })
stream.end()
})
test('with cache', function (t) {
var input = [ 'beep', 'beep boop' ]
, stream = createStream({ cache: { max: 500 } })
stream.pipe(concat({ encoding: 'object' }, function (array) {
t.deepEqual(array, [ input[1] ])
t.end()
}))
input.forEach(function (row) { stream.write(row) })
stream.end()
})