| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | const assert = require('chai').assert
|
|---|
| 4 | const proxyquire = require('proxyquire')
|
|---|
| 5 | const spooks = require('spooks')
|
|---|
| 6 |
|
|---|
| 7 | const modulePath = '../../src/match'
|
|---|
| 8 |
|
|---|
| 9 | suite('match:', () => {
|
|---|
| 10 | test('require does not throw', () => {
|
|---|
| 11 | assert.doesNotThrow(() => {
|
|---|
| 12 | require(modulePath)
|
|---|
| 13 | })
|
|---|
| 14 | })
|
|---|
| 15 |
|
|---|
| 16 | test('require returns function', () => {
|
|---|
| 17 | assert.isFunction(require(modulePath))
|
|---|
| 18 | })
|
|---|
| 19 |
|
|---|
| 20 | suite('require, results.push returns true:', () => {
|
|---|
| 21 | let log, resume, results, match
|
|---|
| 22 |
|
|---|
| 23 | setup(() => {
|
|---|
| 24 | log = {}
|
|---|
| 25 | resume = spooks.fn({ name: 'resume', log })
|
|---|
| 26 | results = {
|
|---|
| 27 | walk: [
|
|---|
| 28 | {
|
|---|
| 29 | on: spooks.fn({ name: 'on', log: log }),
|
|---|
| 30 | pause: spooks.fn({ name: 'pause', log: log, results: [ resume ] })
|
|---|
| 31 | }
|
|---|
| 32 | ],
|
|---|
| 33 | push: [ true ]
|
|---|
| 34 | }
|
|---|
| 35 | match = proxyquire(modulePath, {
|
|---|
| 36 | './walk': spooks.fn({
|
|---|
| 37 | name: 'walk',
|
|---|
| 38 | log: log,
|
|---|
| 39 | results: results.walk
|
|---|
| 40 | }),
|
|---|
| 41 | './datastream': spooks.ctor({
|
|---|
| 42 | name: 'DataStream',
|
|---|
| 43 | log: log,
|
|---|
| 44 | archetype: { instance: { push: () => {}, emit: () => {} } },
|
|---|
| 45 | results: results
|
|---|
| 46 | })
|
|---|
| 47 | })
|
|---|
| 48 | })
|
|---|
| 49 |
|
|---|
| 50 | test('match expects two arguments', () => {
|
|---|
| 51 | assert.lengthOf(match, 2)
|
|---|
| 52 | })
|
|---|
| 53 |
|
|---|
| 54 | test('match does not throw with match function', () => {
|
|---|
| 55 | assert.doesNotThrow(() => match(null, () => {}))
|
|---|
| 56 | })
|
|---|
| 57 |
|
|---|
| 58 | test('match does not throw with match string', () => {
|
|---|
| 59 | assert.doesNotThrow(() => match(null, ' '))
|
|---|
| 60 | })
|
|---|
| 61 |
|
|---|
| 62 | test('match throws with empty match string', () => {
|
|---|
| 63 | assert.throws(() => match(null, ''))
|
|---|
| 64 | })
|
|---|
| 65 |
|
|---|
| 66 | test('match does not throw with match regex', () => {
|
|---|
| 67 | assert.doesNotThrow(() => match(null, /.*/))
|
|---|
| 68 | })
|
|---|
| 69 |
|
|---|
| 70 | test('match throws with invalid match arg', () => {
|
|---|
| 71 | assert.throws(() => match(null, {}))
|
|---|
| 72 | })
|
|---|
| 73 |
|
|---|
| 74 | test('match returns stream', () => {
|
|---|
| 75 | assert.isFunction(match(null, /.*/).push)
|
|---|
| 76 | assert.isFunction(match(null, /.*/).emit)
|
|---|
| 77 | })
|
|---|
| 78 |
|
|---|
| 79 | test('DataStream was not called', () => {
|
|---|
| 80 | assert.strictEqual(log.counts.DataStream, 0)
|
|---|
| 81 | })
|
|---|
| 82 |
|
|---|
| 83 | test('walk was not called', () => {
|
|---|
| 84 | assert.strictEqual(log.counts.walk, 0)
|
|---|
| 85 | })
|
|---|
| 86 |
|
|---|
| 87 | test('EventEmitter.on was not called', () => {
|
|---|
| 88 | assert.strictEqual(log.counts.on, 0)
|
|---|
| 89 | })
|
|---|
| 90 |
|
|---|
| 91 | test('EventEmitter.pause was not called', () => {
|
|---|
| 92 | assert.strictEqual(log.counts.pause, 0)
|
|---|
| 93 | })
|
|---|
| 94 |
|
|---|
| 95 | suite('match with predicate returning true:', () => {
|
|---|
| 96 | let stream, predicate, options, result
|
|---|
| 97 |
|
|---|
| 98 | setup(() => {
|
|---|
| 99 | stream = {}
|
|---|
| 100 | predicate = spooks.fn({ name: 'predicate', log, results: [ true ] })
|
|---|
| 101 | options = { foo: 'bar', highWaterMark: 42 }
|
|---|
| 102 | result = match(stream, predicate, options)
|
|---|
| 103 | })
|
|---|
| 104 |
|
|---|
| 105 | test('DataStream was called once', () => {
|
|---|
| 106 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 107 | assert.isObject(log.these.DataStream[0])
|
|---|
| 108 | })
|
|---|
| 109 |
|
|---|
| 110 | test('DataStream was called correctly', () => {
|
|---|
| 111 | assert.lengthOf(log.args.DataStream[0], 2)
|
|---|
| 112 | assert.isFunction(log.args.DataStream[0][0])
|
|---|
| 113 | assert.deepEqual(log.args.DataStream[0][1], { highWaterMark: 42 })
|
|---|
| 114 | })
|
|---|
| 115 |
|
|---|
| 116 | test('walk was called once', () => {
|
|---|
| 117 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 118 | assert.isUndefined(log.these.walk[0])
|
|---|
| 119 | })
|
|---|
| 120 |
|
|---|
| 121 | test('walk was called correctly', () => {
|
|---|
| 122 | assert.lengthOf(log.args.walk[0], 2)
|
|---|
| 123 | assert.strictEqual(log.args.walk[0][0], stream)
|
|---|
| 124 | assert.lengthOf(Object.keys(log.args.walk[0][0]), 0)
|
|---|
| 125 | assert.strictEqual(log.args.walk[0][1], options)
|
|---|
| 126 | assert.lengthOf(Object.keys(log.args.walk[0][1]), 2)
|
|---|
| 127 | })
|
|---|
| 128 |
|
|---|
| 129 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 130 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 131 | assert.strictEqual(log.these.on[0], results.walk[0])
|
|---|
| 132 | assert.strictEqual(log.these.on[1], results.walk[0])
|
|---|
| 133 | assert.strictEqual(log.these.on[2], results.walk[0])
|
|---|
| 134 | assert.strictEqual(log.these.on[3], results.walk[0])
|
|---|
| 135 | assert.strictEqual(log.these.on[4], results.walk[0])
|
|---|
| 136 | assert.strictEqual(log.these.on[5], results.walk[0])
|
|---|
| 137 | assert.strictEqual(log.these.on[6], results.walk[0])
|
|---|
| 138 | assert.strictEqual(log.these.on[7], results.walk[0])
|
|---|
| 139 | assert.strictEqual(log.these.on[8], results.walk[0])
|
|---|
| 140 | assert.strictEqual(log.these.on[9], results.walk[0])
|
|---|
| 141 | assert.strictEqual(log.these.on[10], results.walk[0])
|
|---|
| 142 | })
|
|---|
| 143 |
|
|---|
| 144 | test('EventEmitter.on was called correctly first time', () => {
|
|---|
| 145 | assert.lengthOf(log.args.on[0], 2)
|
|---|
| 146 | assert.strictEqual(log.args.on[0][0], 'arr')
|
|---|
| 147 | assert.isFunction(log.args.on[0][1])
|
|---|
| 148 | })
|
|---|
| 149 |
|
|---|
| 150 | test('EventEmitter.on was called correctly second time', () => {
|
|---|
| 151 | assert.lengthOf(log.args.on[1], 2)
|
|---|
| 152 | assert.strictEqual(log.args.on[1][0], 'obj')
|
|---|
| 153 | assert.isFunction(log.args.on[1][1])
|
|---|
| 154 | })
|
|---|
| 155 |
|
|---|
| 156 | test('EventEmitter.on was called correctly third time', () => {
|
|---|
| 157 | assert.lengthOf(log.args.on[2], 2)
|
|---|
| 158 | assert.strictEqual(log.args.on[2][0], 'pro')
|
|---|
| 159 | assert.isFunction(log.args.on[2][1])
|
|---|
| 160 | })
|
|---|
| 161 |
|
|---|
| 162 | test('EventEmitter.on was called correctly fourth time', () => {
|
|---|
| 163 | assert.lengthOf(log.args.on[3], 2)
|
|---|
| 164 | assert.strictEqual(log.args.on[3][0], 'end-arr')
|
|---|
| 165 | assert.isFunction(log.args.on[3][1])
|
|---|
| 166 | })
|
|---|
| 167 |
|
|---|
| 168 | test('EventEmitter.on was called correctly fifth time', () => {
|
|---|
| 169 | assert.lengthOf(log.args.on[4], 2)
|
|---|
| 170 | assert.strictEqual(log.args.on[4][0], 'end-obj')
|
|---|
| 171 | assert.isFunction(log.args.on[4][1])
|
|---|
| 172 | })
|
|---|
| 173 |
|
|---|
| 174 | test('EventEmitter.on was called correctly sixth time', () => {
|
|---|
| 175 | assert.lengthOf(log.args.on[5], 2)
|
|---|
| 176 | assert.strictEqual(log.args.on[5][0], 'str')
|
|---|
| 177 | assert.isFunction(log.args.on[5][1])
|
|---|
| 178 | })
|
|---|
| 179 |
|
|---|
| 180 | test('EventEmitter.on was called correctly seventh time', () => {
|
|---|
| 181 | assert.lengthOf(log.args.on[6], 2)
|
|---|
| 182 | assert.strictEqual(log.args.on[6][0], 'num')
|
|---|
| 183 | assert.isFunction(log.args.on[6][1])
|
|---|
| 184 | })
|
|---|
| 185 |
|
|---|
| 186 | test('EventEmitter.on was called correctly eighth time', () => {
|
|---|
| 187 | assert.lengthOf(log.args.on[7], 2)
|
|---|
| 188 | assert.strictEqual(log.args.on[7][0], 'lit')
|
|---|
| 189 | assert.isFunction(log.args.on[7][1])
|
|---|
| 190 | })
|
|---|
| 191 |
|
|---|
| 192 | test('EventEmitter.on was called correctly ninth time', () => {
|
|---|
| 193 | assert.lengthOf(log.args.on[8], 2)
|
|---|
| 194 | assert.strictEqual(log.args.on[8][0], 'end')
|
|---|
| 195 | assert.isFunction(log.args.on[8][1])
|
|---|
| 196 | })
|
|---|
| 197 |
|
|---|
| 198 | test('EventEmitter.on was called correctly tenth time', () => {
|
|---|
| 199 | assert.lengthOf(log.args.on[9], 2)
|
|---|
| 200 | assert.strictEqual(log.args.on[9][0], 'err')
|
|---|
| 201 | assert.isFunction(log.args.on[9][1])
|
|---|
| 202 | })
|
|---|
| 203 |
|
|---|
| 204 | test('EventEmitter.on was called correctly eleventh time', () => {
|
|---|
| 205 | assert.lengthOf(log.args.on[10], 2)
|
|---|
| 206 | assert.strictEqual(log.args.on[10][0], 'err-data')
|
|---|
| 207 | assert.isFunction(log.args.on[10][1])
|
|---|
| 208 | })
|
|---|
| 209 |
|
|---|
| 210 | suite('array event:', () => {
|
|---|
| 211 | setup(() => {
|
|---|
| 212 | log.args.on[0][1]()
|
|---|
| 213 | })
|
|---|
| 214 |
|
|---|
| 215 | test('results.push was not called', () => {
|
|---|
| 216 | assert.strictEqual(log.counts.push, 0)
|
|---|
| 217 | })
|
|---|
| 218 |
|
|---|
| 219 | suite('end event:', () => {
|
|---|
| 220 | setup(() => {
|
|---|
| 221 | log.args.on[8][1]()
|
|---|
| 222 | })
|
|---|
| 223 |
|
|---|
| 224 | test('results.push was not called', () => {
|
|---|
| 225 | assert.strictEqual(log.counts.push, 0)
|
|---|
| 226 | })
|
|---|
| 227 |
|
|---|
| 228 | suite('read stream:', () => {
|
|---|
| 229 | setup(() => {
|
|---|
| 230 | log.args.DataStream[0][0]()
|
|---|
| 231 | })
|
|---|
| 232 |
|
|---|
| 233 | test('results.push was called once', () => {
|
|---|
| 234 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 235 | })
|
|---|
| 236 |
|
|---|
| 237 | test('results.push was called correctly', () => {
|
|---|
| 238 | assert.lengthOf(log.args.push[0], 1)
|
|---|
| 239 | assert.isNull(log.args.push[0][0])
|
|---|
| 240 | })
|
|---|
| 241 |
|
|---|
| 242 | test('predicate was not called', () => {
|
|---|
| 243 | assert.strictEqual(log.counts.predicate, 0)
|
|---|
| 244 | })
|
|---|
| 245 | })
|
|---|
| 246 | })
|
|---|
| 247 |
|
|---|
| 248 | suite('endArray and end events:', () => {
|
|---|
| 249 | setup(() => {
|
|---|
| 250 | log.args.on[3][1]()
|
|---|
| 251 | log.args.on[8][1]()
|
|---|
| 252 | })
|
|---|
| 253 |
|
|---|
| 254 | test('predicate was called once', () => {
|
|---|
| 255 | assert.strictEqual(log.counts.predicate, 1)
|
|---|
| 256 | })
|
|---|
| 257 |
|
|---|
| 258 | test('predicate was called correctly', () => {
|
|---|
| 259 | assert.lengthOf(log.args.predicate[0], 3)
|
|---|
| 260 | assert.isUndefined(log.args.predicate[0][0])
|
|---|
| 261 | assert.deepEqual(log.args.predicate[0][1], [])
|
|---|
| 262 | assert.strictEqual(log.args.predicate[0][2], 0)
|
|---|
| 263 | })
|
|---|
| 264 |
|
|---|
| 265 | test('results.push was not called', () => {
|
|---|
| 266 | assert.strictEqual(log.counts.push, 0)
|
|---|
| 267 | })
|
|---|
| 268 |
|
|---|
| 269 | suite('read stream:', () => {
|
|---|
| 270 | setup(() => {
|
|---|
| 271 | log.args.DataStream[0][0]()
|
|---|
| 272 | })
|
|---|
| 273 |
|
|---|
| 274 | test('results.push was called twice', () => {
|
|---|
| 275 | assert.strictEqual(log.counts.push, 2)
|
|---|
| 276 | })
|
|---|
| 277 |
|
|---|
| 278 | test('results.push was called correctly first time', () => {
|
|---|
| 279 | assert.lengthOf(log.args.push[0], 1)
|
|---|
| 280 | assert.deepEqual(log.args.push[0][0], [])
|
|---|
| 281 | })
|
|---|
| 282 |
|
|---|
| 283 | test('results.push was called correctly second time', () => {
|
|---|
| 284 | assert.lengthOf(log.args.push[1], 1)
|
|---|
| 285 | assert.isNull(log.args.push[1][0])
|
|---|
| 286 | })
|
|---|
| 287 |
|
|---|
| 288 | test('results.emit was not called', () => {
|
|---|
| 289 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 290 | })
|
|---|
| 291 | })
|
|---|
| 292 | })
|
|---|
| 293 |
|
|---|
| 294 | suite('read stream:', () => {
|
|---|
| 295 | setup(() => {
|
|---|
| 296 | log.args.DataStream[0][0]()
|
|---|
| 297 | })
|
|---|
| 298 |
|
|---|
| 299 | test('results.push was not called', () => {
|
|---|
| 300 | assert.strictEqual(log.counts.push, 0)
|
|---|
| 301 | })
|
|---|
| 302 |
|
|---|
| 303 | suite('end event:', () => {
|
|---|
| 304 | setup(() => {
|
|---|
| 305 | log.args.on[8][1]()
|
|---|
| 306 | })
|
|---|
| 307 |
|
|---|
| 308 | test('results.push was called once', () => {
|
|---|
| 309 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 310 | })
|
|---|
| 311 |
|
|---|
| 312 | test('results.push was called correctly', () => {
|
|---|
| 313 | assert.isNull(log.args.push[0][0])
|
|---|
| 314 | })
|
|---|
| 315 |
|
|---|
| 316 | test('results.emit was not called', () => {
|
|---|
| 317 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 318 | })
|
|---|
| 319 | })
|
|---|
| 320 |
|
|---|
| 321 | suite('dataError event:', () => {
|
|---|
| 322 | setup(() => {
|
|---|
| 323 | log.args.on[10][1]('foo')
|
|---|
| 324 | })
|
|---|
| 325 |
|
|---|
| 326 | test('results.push was not called', () => {
|
|---|
| 327 | assert.strictEqual(log.counts.push, 0)
|
|---|
| 328 | })
|
|---|
| 329 |
|
|---|
| 330 | test('results.emit was called once', () => {
|
|---|
| 331 | assert.strictEqual(log.counts.emit, 1)
|
|---|
| 332 | })
|
|---|
| 333 |
|
|---|
| 334 | test('results.emit was called correctly', () => {
|
|---|
| 335 | assert.lengthOf(log.args.emit[0], 2)
|
|---|
| 336 | assert.strictEqual(log.args.emit[0][0], 'dataError')
|
|---|
| 337 | assert.strictEqual(log.args.emit[0][1], 'foo')
|
|---|
| 338 | })
|
|---|
| 339 |
|
|---|
| 340 | test('predicate was not called', () => {
|
|---|
| 341 | assert.strictEqual(log.counts.predicate, 0)
|
|---|
| 342 | })
|
|---|
| 343 | })
|
|---|
| 344 |
|
|---|
| 345 | suite('string event:', () => {
|
|---|
| 346 | setup(() => {
|
|---|
| 347 | log.args.on[5][1]('foo')
|
|---|
| 348 | })
|
|---|
| 349 |
|
|---|
| 350 | test('predicate was called once', () => {
|
|---|
| 351 | assert.strictEqual(log.counts.predicate, 1)
|
|---|
| 352 | })
|
|---|
| 353 |
|
|---|
| 354 | test('predicate was called correctly', () => {
|
|---|
| 355 | assert.lengthOf(log.args.predicate[0], 3)
|
|---|
| 356 | assert.strictEqual(log.args.predicate[0][0], 0)
|
|---|
| 357 | assert.strictEqual(log.args.predicate[0][1], 'foo')
|
|---|
| 358 | assert.strictEqual(log.args.predicate[0][2], 1)
|
|---|
| 359 | })
|
|---|
| 360 |
|
|---|
| 361 | test('results.push was called once', () => {
|
|---|
| 362 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 363 | })
|
|---|
| 364 |
|
|---|
| 365 | test('results.push was called correctly', () => {
|
|---|
| 366 | assert.strictEqual(log.args.push[0][0], 'foo')
|
|---|
| 367 | })
|
|---|
| 368 |
|
|---|
| 369 | suite('string event:', () => {
|
|---|
| 370 | setup(() => {
|
|---|
| 371 | log.args.on[5][1]('bar')
|
|---|
| 372 | })
|
|---|
| 373 |
|
|---|
| 374 | test('predicate was called once', () => {
|
|---|
| 375 | assert.strictEqual(log.counts.predicate, 2)
|
|---|
| 376 | })
|
|---|
| 377 |
|
|---|
| 378 | test('predicate was called correctly', () => {
|
|---|
| 379 | assert.strictEqual(log.args.predicate[1][0], 1)
|
|---|
| 380 | assert.strictEqual(log.args.predicate[1][1], 'bar')
|
|---|
| 381 | assert.strictEqual(log.args.predicate[1][2], 1)
|
|---|
| 382 | })
|
|---|
| 383 |
|
|---|
| 384 | test('results.push was called once', () => {
|
|---|
| 385 | assert.strictEqual(log.counts.push, 2)
|
|---|
| 386 | })
|
|---|
| 387 |
|
|---|
| 388 | test('results.push was called correctly', () => {
|
|---|
| 389 | assert.strictEqual(log.args.push[1][0], 'bar')
|
|---|
| 390 | })
|
|---|
| 391 | })
|
|---|
| 392 |
|
|---|
| 393 | suite('array event:', () => {
|
|---|
| 394 | setup(() => {
|
|---|
| 395 | log.args.on[0][1]()
|
|---|
| 396 | })
|
|---|
| 397 |
|
|---|
| 398 | test('predicate was not called', () => {
|
|---|
| 399 | assert.strictEqual(log.counts.predicate, 1)
|
|---|
| 400 | })
|
|---|
| 401 |
|
|---|
| 402 | test('results.push was not called', () => {
|
|---|
| 403 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 404 | })
|
|---|
| 405 |
|
|---|
| 406 | suite('endArray event:', () => {
|
|---|
| 407 | setup(() => {
|
|---|
| 408 | log.args.on[3][1]()
|
|---|
| 409 | })
|
|---|
| 410 |
|
|---|
| 411 | test('predicate was called once', () => {
|
|---|
| 412 | assert.strictEqual(log.counts.predicate, 2)
|
|---|
| 413 | })
|
|---|
| 414 |
|
|---|
| 415 | test('predicate was called correctly', () => {
|
|---|
| 416 | assert.strictEqual(log.args.predicate[1][0], 1)
|
|---|
| 417 | assert.deepEqual(log.args.predicate[1][1], [])
|
|---|
| 418 | assert.strictEqual(log.args.predicate[1][2], 1)
|
|---|
| 419 | })
|
|---|
| 420 |
|
|---|
| 421 | test('results.push was called once', () => {
|
|---|
| 422 | assert.strictEqual(log.counts.push, 2)
|
|---|
| 423 | })
|
|---|
| 424 |
|
|---|
| 425 | test('results.push was called correctly', () => {
|
|---|
| 426 | assert.deepEqual(log.args.push[1][0], [])
|
|---|
| 427 | })
|
|---|
| 428 |
|
|---|
| 429 | suite('endArray event:', () => {
|
|---|
| 430 | setup(() => {
|
|---|
| 431 | log.args.on[3][1]()
|
|---|
| 432 | })
|
|---|
| 433 |
|
|---|
| 434 | test('predicate was called once', () => {
|
|---|
| 435 | assert.strictEqual(log.counts.predicate, 3)
|
|---|
| 436 | })
|
|---|
| 437 |
|
|---|
| 438 | test('predicate was called correctly', () => {
|
|---|
| 439 | assert.isUndefined(log.args.predicate[2][0])
|
|---|
| 440 | assert.deepEqual(log.args.predicate[2][1], [ 'foo', [] ])
|
|---|
| 441 | assert.strictEqual(log.args.predicate[2][2], 0)
|
|---|
| 442 | })
|
|---|
| 443 |
|
|---|
| 444 | test('results.push was called once', () => {
|
|---|
| 445 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 446 | })
|
|---|
| 447 |
|
|---|
| 448 | test('results.push was called correctly', () => {
|
|---|
| 449 | assert.deepEqual(log.args.push[2][0], [ 'foo', [] ])
|
|---|
| 450 | })
|
|---|
| 451 |
|
|---|
| 452 | test('EventEmitter.pause was not called', () => {
|
|---|
| 453 | assert.strictEqual(log.counts.pause, 0)
|
|---|
| 454 | })
|
|---|
| 455 | })
|
|---|
| 456 | })
|
|---|
| 457 | })
|
|---|
| 458 |
|
|---|
| 459 | suite('object event:', () => {
|
|---|
| 460 | setup(() => {
|
|---|
| 461 | log.args.on[1][1]()
|
|---|
| 462 | })
|
|---|
| 463 |
|
|---|
| 464 | test('results.push was not called', () => {
|
|---|
| 465 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 466 | })
|
|---|
| 467 |
|
|---|
| 468 | suite('property event:', () => {
|
|---|
| 469 | setup(() => {
|
|---|
| 470 | log.args.on[2][1]('bar')
|
|---|
| 471 | })
|
|---|
| 472 |
|
|---|
| 473 | test('predicate was not called', () => {
|
|---|
| 474 | assert.strictEqual(log.counts.predicate, 1)
|
|---|
| 475 | })
|
|---|
| 476 |
|
|---|
| 477 | test('results.push was not called', () => {
|
|---|
| 478 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 479 | })
|
|---|
| 480 |
|
|---|
| 481 | suite('string event:', () => {
|
|---|
| 482 | setup(() => {
|
|---|
| 483 | log.args.on[5][1]('baz')
|
|---|
| 484 | })
|
|---|
| 485 |
|
|---|
| 486 | test('predicate was called once', () => {
|
|---|
| 487 | assert.strictEqual(log.counts.predicate, 2)
|
|---|
| 488 | })
|
|---|
| 489 |
|
|---|
| 490 | test('predicate was called correctly', () => {
|
|---|
| 491 | assert.strictEqual(log.args.predicate[1][0], 'bar')
|
|---|
| 492 | assert.strictEqual(log.args.predicate[1][1], 'baz')
|
|---|
| 493 | assert.strictEqual(log.args.predicate[1][2], 2)
|
|---|
| 494 | })
|
|---|
| 495 |
|
|---|
| 496 | test('results.push was called once', () => {
|
|---|
| 497 | assert.strictEqual(log.counts.push, 2)
|
|---|
| 498 | })
|
|---|
| 499 |
|
|---|
| 500 | test('results.push was called correctly', () => {
|
|---|
| 501 | assert.strictEqual(log.args.push[1][0], 'baz')
|
|---|
| 502 | })
|
|---|
| 503 |
|
|---|
| 504 | suite('property event:', () => {
|
|---|
| 505 | setup(() => {
|
|---|
| 506 | log.args.on[2][1]('nested')
|
|---|
| 507 | })
|
|---|
| 508 |
|
|---|
| 509 | test('results.push was not called', () => {
|
|---|
| 510 | assert.strictEqual(log.counts.push, 2)
|
|---|
| 511 | })
|
|---|
| 512 |
|
|---|
| 513 | suite('object event:', () => {
|
|---|
| 514 | setup(() => {
|
|---|
| 515 | log.args.on[1][1]()
|
|---|
| 516 | })
|
|---|
| 517 |
|
|---|
| 518 | test('predicate was not called', () => {
|
|---|
| 519 | assert.strictEqual(log.counts.predicate, 2)
|
|---|
| 520 | })
|
|---|
| 521 |
|
|---|
| 522 | test('results.push was not called', () => {
|
|---|
| 523 | assert.strictEqual(log.counts.push, 2)
|
|---|
| 524 | })
|
|---|
| 525 |
|
|---|
| 526 | suite('endObject event:', () => {
|
|---|
| 527 | setup(() => {
|
|---|
| 528 | log.args.on[4][1]()
|
|---|
| 529 | })
|
|---|
| 530 |
|
|---|
| 531 | test('predicate was called once', () => {
|
|---|
| 532 | assert.strictEqual(log.counts.predicate, 3)
|
|---|
| 533 | })
|
|---|
| 534 |
|
|---|
| 535 | test('predicate was called correctly', () => {
|
|---|
| 536 | assert.strictEqual(log.args.predicate[2][0], 'nested')
|
|---|
| 537 | assert.deepEqual(log.args.predicate[2][1], {})
|
|---|
| 538 | assert.strictEqual(log.args.predicate[2][2], 2)
|
|---|
| 539 | })
|
|---|
| 540 |
|
|---|
| 541 | test('results.push was called once', () => {
|
|---|
| 542 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 543 | })
|
|---|
| 544 |
|
|---|
| 545 | test('results.push was called correctly', () => {
|
|---|
| 546 | assert.deepEqual(log.args.push[2][0], {})
|
|---|
| 547 | })
|
|---|
| 548 |
|
|---|
| 549 | suite('endObject event:', () => {
|
|---|
| 550 | setup(() => {
|
|---|
| 551 | log.args.on[4][1]()
|
|---|
| 552 | })
|
|---|
| 553 |
|
|---|
| 554 | test('predicate was called once', () => {
|
|---|
| 555 | assert.strictEqual(log.counts.predicate, 4)
|
|---|
| 556 | })
|
|---|
| 557 |
|
|---|
| 558 | test('predicate was called correctly', () => {
|
|---|
| 559 | assert.strictEqual(log.args.predicate[3][0], 1)
|
|---|
| 560 | assert.deepEqual(log.args.predicate[3][1], { bar: 'baz', nested: {} })
|
|---|
| 561 | assert.strictEqual(log.args.predicate[3][2], 1)
|
|---|
| 562 | })
|
|---|
| 563 |
|
|---|
| 564 | test('results.push was called once', () => {
|
|---|
| 565 | assert.strictEqual(log.counts.push, 4)
|
|---|
| 566 | })
|
|---|
| 567 |
|
|---|
| 568 | test('results.push was called correctly', () => {
|
|---|
| 569 | assert.deepEqual(log.args.push[3][0], { bar: 'baz', nested: {} })
|
|---|
| 570 | })
|
|---|
| 571 |
|
|---|
| 572 | test('EventEmitter.pause was not called', () => {
|
|---|
| 573 | assert.strictEqual(log.counts.pause, 0)
|
|---|
| 574 | })
|
|---|
| 575 | })
|
|---|
| 576 | })
|
|---|
| 577 | })
|
|---|
| 578 | })
|
|---|
| 579 | })
|
|---|
| 580 | })
|
|---|
| 581 | })
|
|---|
| 582 | })
|
|---|
| 583 |
|
|---|
| 584 | suite('string events, push returns false:', () => {
|
|---|
| 585 | setup(() => {
|
|---|
| 586 | results.push[0] = false
|
|---|
| 587 | log.args.on[5][1]('foo')
|
|---|
| 588 | log.args.on[5][1]('bar')
|
|---|
| 589 | })
|
|---|
| 590 |
|
|---|
| 591 | teardown(() => {
|
|---|
| 592 | results.push[0] = true
|
|---|
| 593 | })
|
|---|
| 594 |
|
|---|
| 595 | test('predicate was called twice', () => {
|
|---|
| 596 | assert.strictEqual(log.counts.predicate, 2)
|
|---|
| 597 | })
|
|---|
| 598 |
|
|---|
| 599 | test('results.push was called once', () => {
|
|---|
| 600 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 601 | })
|
|---|
| 602 |
|
|---|
| 603 | test('results.push was called correctly', () => {
|
|---|
| 604 | assert.strictEqual(log.args.push[0][0], 'foo')
|
|---|
| 605 | })
|
|---|
| 606 |
|
|---|
| 607 | test('emitter.pause was called once', () => {
|
|---|
| 608 | assert.strictEqual(log.counts.pause, 1)
|
|---|
| 609 | assert.strictEqual(log.these.pause[0], results.walk[0])
|
|---|
| 610 | })
|
|---|
| 611 |
|
|---|
| 612 | test('emitter.pause was called correctly', () => {
|
|---|
| 613 | assert.lengthOf(log.args.pause[0], 0)
|
|---|
| 614 | })
|
|---|
| 615 |
|
|---|
| 616 | test('resume was not called', () => {
|
|---|
| 617 | assert.strictEqual(log.counts.resume, 0)
|
|---|
| 618 | })
|
|---|
| 619 |
|
|---|
| 620 | suite('read stream:', () => {
|
|---|
| 621 | setup(() => {
|
|---|
| 622 | log.args.DataStream[0][0]()
|
|---|
| 623 | })
|
|---|
| 624 |
|
|---|
| 625 | test('resume was called once', () => {
|
|---|
| 626 | assert.strictEqual(log.counts.resume, 1)
|
|---|
| 627 | assert.isUndefined(log.these.resume[0])
|
|---|
| 628 | })
|
|---|
| 629 |
|
|---|
| 630 | test('resume was called correctly', () => {
|
|---|
| 631 | assert.lengthOf(log.args.resume[0], 0)
|
|---|
| 632 | })
|
|---|
| 633 |
|
|---|
| 634 | test('results.push was called once', () => {
|
|---|
| 635 | assert.strictEqual(log.counts.push, 2)
|
|---|
| 636 | })
|
|---|
| 637 |
|
|---|
| 638 | test('results.push was called correctly', () => {
|
|---|
| 639 | assert.strictEqual(log.args.push[1][0], 'bar')
|
|---|
| 640 | })
|
|---|
| 641 | })
|
|---|
| 642 | })
|
|---|
| 643 | })
|
|---|
| 644 |
|
|---|
| 645 | suite('all events then read:', () => {
|
|---|
| 646 | setup(() => {
|
|---|
| 647 | log.args.on[1][1]()
|
|---|
| 648 | log.args.on[2][1]('foo')
|
|---|
| 649 | log.args.on[5][1]('bar')
|
|---|
| 650 | log.args.on[4][1]()
|
|---|
| 651 | log.args.on[5][1]('')
|
|---|
| 652 | log.args.on[6][1](0)
|
|---|
| 653 | log.args.on[7][1](null)
|
|---|
| 654 | log.args.on[7][1](false)
|
|---|
| 655 | log.args.on[3][1]()
|
|---|
| 656 | log.args.on[8][1]()
|
|---|
| 657 | log.args.DataStream[0][0]()
|
|---|
| 658 | })
|
|---|
| 659 |
|
|---|
| 660 | test('predicate was called six times', () => {
|
|---|
| 661 | assert.strictEqual(log.counts.predicate, 6)
|
|---|
| 662 | })
|
|---|
| 663 |
|
|---|
| 664 | test('predicate was called correctly first time', () => {
|
|---|
| 665 | assert.strictEqual(log.args.predicate[0][0], 'foo')
|
|---|
| 666 | assert.strictEqual(log.args.predicate[0][1], 'bar')
|
|---|
| 667 | assert.strictEqual(log.args.predicate[0][2], 2)
|
|---|
| 668 | })
|
|---|
| 669 |
|
|---|
| 670 | test('predicate was called correctly second time', () => {
|
|---|
| 671 | assert.strictEqual(log.args.predicate[1][0], 0)
|
|---|
| 672 | assert.deepEqual(log.args.predicate[1][1], { foo: 'bar' })
|
|---|
| 673 | assert.strictEqual(log.args.predicate[1][2], 1)
|
|---|
| 674 | })
|
|---|
| 675 |
|
|---|
| 676 | test('predicate was called correctly third time', () => {
|
|---|
| 677 | assert.strictEqual(log.args.predicate[2][0], 1)
|
|---|
| 678 | assert.strictEqual(log.args.predicate[2][1], '')
|
|---|
| 679 | assert.strictEqual(log.args.predicate[2][2], 1)
|
|---|
| 680 | })
|
|---|
| 681 |
|
|---|
| 682 | test('predicate was called correctly fourth time', () => {
|
|---|
| 683 | assert.strictEqual(log.args.predicate[3][0], 2)
|
|---|
| 684 | assert.strictEqual(log.args.predicate[3][1], 0)
|
|---|
| 685 | assert.strictEqual(log.args.predicate[3][2], 1)
|
|---|
| 686 | })
|
|---|
| 687 |
|
|---|
| 688 | test('predicate was called correctly fifth time', () => {
|
|---|
| 689 | assert.strictEqual(log.args.predicate[4][0], 4)
|
|---|
| 690 | assert.strictEqual(log.args.predicate[4][1], false)
|
|---|
| 691 | assert.strictEqual(log.args.predicate[4][2], 1)
|
|---|
| 692 | })
|
|---|
| 693 |
|
|---|
| 694 | test('predicate was called correctly sixth time', () => {
|
|---|
| 695 | assert.isUndefined(log.args.predicate[5][0])
|
|---|
| 696 | assert.deepEqual(log.args.predicate[5][1], [ { foo: 'bar' }, '', 0, null, false ])
|
|---|
| 697 | assert.strictEqual(log.args.predicate[5][2], 0)
|
|---|
| 698 | })
|
|---|
| 699 |
|
|---|
| 700 | test('results.push was called seven times', () => {
|
|---|
| 701 | assert.strictEqual(log.counts.push, 7)
|
|---|
| 702 | })
|
|---|
| 703 |
|
|---|
| 704 | test('results.push was called correctly', () => {
|
|---|
| 705 | assert.strictEqual(log.args.push[0][0], 'bar')
|
|---|
| 706 | assert.deepEqual(log.args.push[1][0], { foo: 'bar' })
|
|---|
| 707 | assert.strictEqual(log.args.push[2][0], '')
|
|---|
| 708 | assert.strictEqual(log.args.push[3][0], 0)
|
|---|
| 709 | assert.strictEqual(log.args.push[4][0], false)
|
|---|
| 710 | assert.deepEqual(log.args.push[5][0], [ { foo: 'bar' }, '', 0, null, false ])
|
|---|
| 711 | assert.isNull(log.args.push[6][0])
|
|---|
| 712 | })
|
|---|
| 713 |
|
|---|
| 714 | test('results.emit was not called', () => {
|
|---|
| 715 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 716 | })
|
|---|
| 717 | })
|
|---|
| 718 | })
|
|---|
| 719 |
|
|---|
| 720 | suite('read then all events:', () => {
|
|---|
| 721 | setup(() => {
|
|---|
| 722 | log.args.DataStream[0][0]()
|
|---|
| 723 | log.args.on[0][1]()
|
|---|
| 724 | log.args.on[1][1]()
|
|---|
| 725 | log.args.on[2][1]('foo')
|
|---|
| 726 | log.args.on[5][1]('bar')
|
|---|
| 727 | log.args.on[4][1]()
|
|---|
| 728 | log.args.on[5][1]('')
|
|---|
| 729 | log.args.on[6][1](0)
|
|---|
| 730 | log.args.on[7][1](null)
|
|---|
| 731 | log.args.on[7][1](false)
|
|---|
| 732 | log.args.on[3][1]()
|
|---|
| 733 | log.args.on[8][1]()
|
|---|
| 734 | })
|
|---|
| 735 |
|
|---|
| 736 | test('results.push was called seven times', () => {
|
|---|
| 737 | assert.strictEqual(log.counts.push, 7)
|
|---|
| 738 | })
|
|---|
| 739 |
|
|---|
| 740 | test('results.push was called correctly', () => {
|
|---|
| 741 | assert.strictEqual(log.args.push[0][0], 'bar')
|
|---|
| 742 | assert.deepEqual(log.args.push[1][0], { foo: 'bar' })
|
|---|
| 743 | assert.strictEqual(log.args.push[2][0], '')
|
|---|
| 744 | assert.strictEqual(log.args.push[3][0], 0)
|
|---|
| 745 | assert.strictEqual(log.args.push[4][0], false)
|
|---|
| 746 | assert.deepEqual(log.args.push[5][0], [ { foo: 'bar' }, '', 0, null, false ])
|
|---|
| 747 | assert.isNull(log.args.push[6][0])
|
|---|
| 748 | })
|
|---|
| 749 |
|
|---|
| 750 | test('results.emit was not called', () => {
|
|---|
| 751 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 752 | })
|
|---|
| 753 | })
|
|---|
| 754 | })
|
|---|
| 755 |
|
|---|
| 756 | suite('match with predicate returning false:', () => {
|
|---|
| 757 | let stream, predicate, options, result
|
|---|
| 758 |
|
|---|
| 759 | setup(() => {
|
|---|
| 760 | predicate = spooks.fn({ name: 'predicate', log, results: [ false ] })
|
|---|
| 761 | result = match({}, predicate, {})
|
|---|
| 762 | })
|
|---|
| 763 |
|
|---|
| 764 | test('DataStream was called once', () => {
|
|---|
| 765 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 766 | })
|
|---|
| 767 |
|
|---|
| 768 | test('walk was called once', () => {
|
|---|
| 769 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 770 | })
|
|---|
| 771 |
|
|---|
| 772 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 773 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 774 | })
|
|---|
| 775 |
|
|---|
| 776 | suite('read events:', () => {
|
|---|
| 777 | setup(() => {
|
|---|
| 778 | log.args.DataStream[0][0]()
|
|---|
| 779 | // [ { "foo": "bar" }, "baz", 1, true ]
|
|---|
| 780 | log.args.on[0][1]()
|
|---|
| 781 | log.args.on[1][1]()
|
|---|
| 782 | log.args.on[2][1]('foo')
|
|---|
| 783 | log.args.on[5][1]('bar')
|
|---|
| 784 | log.args.on[4][1]()
|
|---|
| 785 | log.args.on[5][1]('baz')
|
|---|
| 786 | log.args.on[6][1](1)
|
|---|
| 787 | log.args.on[7][1](true)
|
|---|
| 788 | log.args.on[3][1]()
|
|---|
| 789 | log.args.on[8][1]()
|
|---|
| 790 | })
|
|---|
| 791 |
|
|---|
| 792 | test('results.push was called once', () => {
|
|---|
| 793 | assert.strictEqual(log.counts.push, 1)
|
|---|
| 794 | })
|
|---|
| 795 |
|
|---|
| 796 | test('results.push was called correctly', () => {
|
|---|
| 797 | assert.isNull(log.args.push[0][0])
|
|---|
| 798 | })
|
|---|
| 799 |
|
|---|
| 800 | test('results.emit was not called', () => {
|
|---|
| 801 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 802 | })
|
|---|
| 803 | })
|
|---|
| 804 | })
|
|---|
| 805 |
|
|---|
| 806 | suite('match with string:', () => {
|
|---|
| 807 | let stream, options, result
|
|---|
| 808 |
|
|---|
| 809 | setup(() => {
|
|---|
| 810 | result = match({}, 'foo', {})
|
|---|
| 811 | })
|
|---|
| 812 |
|
|---|
| 813 | test('DataStream was called once', () => {
|
|---|
| 814 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 815 | })
|
|---|
| 816 |
|
|---|
| 817 | test('walk was called once', () => {
|
|---|
| 818 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 819 | })
|
|---|
| 820 |
|
|---|
| 821 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 822 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 823 | })
|
|---|
| 824 |
|
|---|
| 825 | suite('read events:', () => {
|
|---|
| 826 | setup(() => {
|
|---|
| 827 | log.args.DataStream[0][0]()
|
|---|
| 828 | // { "foo": "bar", "baz": "qux", "foo": "wibble" }
|
|---|
| 829 | log.args.on[1][1]()
|
|---|
| 830 | log.args.on[2][1]('foo')
|
|---|
| 831 | log.args.on[5][1]('bar')
|
|---|
| 832 | log.args.on[2][1]('baz')
|
|---|
| 833 | log.args.on[5][1]('qux')
|
|---|
| 834 | log.args.on[2][1]('foo')
|
|---|
| 835 | log.args.on[5][1]('wibble')
|
|---|
| 836 | log.args.on[4][1]()
|
|---|
| 837 | log.args.on[8][1]()
|
|---|
| 838 | })
|
|---|
| 839 |
|
|---|
| 840 | test('results.push was called three times', () => {
|
|---|
| 841 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 842 | })
|
|---|
| 843 |
|
|---|
| 844 | test('results.push was called correctly first time', () => {
|
|---|
| 845 | assert.strictEqual(log.args.push[0][0], 'bar')
|
|---|
| 846 | })
|
|---|
| 847 |
|
|---|
| 848 | test('results.push was called correctly second time', () => {
|
|---|
| 849 | assert.strictEqual(log.args.push[1][0], 'wibble')
|
|---|
| 850 | })
|
|---|
| 851 |
|
|---|
| 852 | test('results.push was called correctly third time', () => {
|
|---|
| 853 | assert.isNull(log.args.push[2][0])
|
|---|
| 854 | })
|
|---|
| 855 |
|
|---|
| 856 | test('results.emit was not called', () => {
|
|---|
| 857 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 858 | })
|
|---|
| 859 | })
|
|---|
| 860 | })
|
|---|
| 861 |
|
|---|
| 862 | suite('match with regular expression:', () => {
|
|---|
| 863 | let stream, options, result
|
|---|
| 864 |
|
|---|
| 865 | setup(() => {
|
|---|
| 866 | result = match({}, /oo/, {})
|
|---|
| 867 | })
|
|---|
| 868 |
|
|---|
| 869 | test('DataStream was called once', () => {
|
|---|
| 870 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 871 | })
|
|---|
| 872 |
|
|---|
| 873 | test('walk was called once', () => {
|
|---|
| 874 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 875 | })
|
|---|
| 876 |
|
|---|
| 877 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 878 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 879 | })
|
|---|
| 880 |
|
|---|
| 881 | suite('read events:', () => {
|
|---|
| 882 | setup(() => {
|
|---|
| 883 | log.args.DataStream[0][0]()
|
|---|
| 884 | // { "foo": "bar", "fo": "baz", "oo": "qux" }
|
|---|
| 885 | log.args.on[1][1]()
|
|---|
| 886 | log.args.on[2][1]('foo')
|
|---|
| 887 | log.args.on[5][1]('bar')
|
|---|
| 888 | log.args.on[2][1]('fo')
|
|---|
| 889 | log.args.on[5][1]('baz')
|
|---|
| 890 | log.args.on[2][1]('oo')
|
|---|
| 891 | log.args.on[5][1]('qux')
|
|---|
| 892 | log.args.on[4][1]()
|
|---|
| 893 | log.args.on[8][1]()
|
|---|
| 894 | })
|
|---|
| 895 |
|
|---|
| 896 | test('results.push was called three times', () => {
|
|---|
| 897 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 898 | })
|
|---|
| 899 |
|
|---|
| 900 | test('results.push was called correctly first time', () => {
|
|---|
| 901 | assert.strictEqual(log.args.push[0][0], 'bar')
|
|---|
| 902 | })
|
|---|
| 903 |
|
|---|
| 904 | test('results.push was called correctly second time', () => {
|
|---|
| 905 | assert.strictEqual(log.args.push[1][0], 'qux')
|
|---|
| 906 | })
|
|---|
| 907 |
|
|---|
| 908 | test('results.push was called correctly third time', () => {
|
|---|
| 909 | assert.isNull(log.args.push[2][0])
|
|---|
| 910 | })
|
|---|
| 911 |
|
|---|
| 912 | test('results.emit was not called', () => {
|
|---|
| 913 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 914 | })
|
|---|
| 915 | })
|
|---|
| 916 | })
|
|---|
| 917 |
|
|---|
| 918 | suite('match with jsonpath expression:', () => {
|
|---|
| 919 | let stream, options, result
|
|---|
| 920 |
|
|---|
| 921 | setup(() => {
|
|---|
| 922 | result = match({}, '$.foo.bar[*]', {})
|
|---|
| 923 | })
|
|---|
| 924 |
|
|---|
| 925 | test('DataStream was called once', () => {
|
|---|
| 926 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 927 | })
|
|---|
| 928 |
|
|---|
| 929 | test('walk was called once', () => {
|
|---|
| 930 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 931 | })
|
|---|
| 932 |
|
|---|
| 933 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 934 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 935 | })
|
|---|
| 936 |
|
|---|
| 937 | suite('read events:', () => {
|
|---|
| 938 | setup(() => {
|
|---|
| 939 | log.args.DataStream[0][0]()
|
|---|
| 940 | // { "foo": { "bar": [ "baz", "qux" ], "wibble": "blee" } }
|
|---|
| 941 | log.args.on[1][1]()
|
|---|
| 942 | log.args.on[2][1]('foo')
|
|---|
| 943 | log.args.on[1][1]()
|
|---|
| 944 | log.args.on[2][1]('bar')
|
|---|
| 945 | log.args.on[0][1]()
|
|---|
| 946 | log.args.on[5][1]('baz')
|
|---|
| 947 | log.args.on[5][1]('qux')
|
|---|
| 948 | log.args.on[3][1]()
|
|---|
| 949 | log.args.on[2][1]('wibble')
|
|---|
| 950 | log.args.on[5][1]('blee')
|
|---|
| 951 | log.args.on[4][1]()
|
|---|
| 952 | log.args.on[8][1]()
|
|---|
| 953 | })
|
|---|
| 954 |
|
|---|
| 955 | test('results.push was called three times', () => {
|
|---|
| 956 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 957 | })
|
|---|
| 958 |
|
|---|
| 959 | test('results.push was called correctly first time', () => {
|
|---|
| 960 | assert.strictEqual(log.args.push[0][0], 'baz')
|
|---|
| 961 | })
|
|---|
| 962 |
|
|---|
| 963 | test('results.push was called correctly second time', () => {
|
|---|
| 964 | assert.strictEqual(log.args.push[1][0], 'qux')
|
|---|
| 965 | })
|
|---|
| 966 |
|
|---|
| 967 | test('results.push was called correctly third time', () => {
|
|---|
| 968 | assert.isNull(log.args.push[2][0])
|
|---|
| 969 | })
|
|---|
| 970 |
|
|---|
| 971 | test('results.emit was not called', () => {
|
|---|
| 972 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 973 | })
|
|---|
| 974 | })
|
|---|
| 975 | })
|
|---|
| 976 |
|
|---|
| 977 | suite('match with numbers=true:', () => {
|
|---|
| 978 | let stream, options, result
|
|---|
| 979 |
|
|---|
| 980 | setup(() => {
|
|---|
| 981 | result = match({}, '1', { numbers: true })
|
|---|
| 982 | })
|
|---|
| 983 |
|
|---|
| 984 | test('DataStream was called once', () => {
|
|---|
| 985 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 986 | })
|
|---|
| 987 |
|
|---|
| 988 | test('walk was called once', () => {
|
|---|
| 989 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 990 | })
|
|---|
| 991 |
|
|---|
| 992 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 993 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 994 | })
|
|---|
| 995 |
|
|---|
| 996 | suite('read events:', () => {
|
|---|
| 997 | setup(() => {
|
|---|
| 998 | log.args.DataStream[0][0]()
|
|---|
| 999 | // { "0": "foo", "1": "bar", "2": [ "baz", "qux" ] }
|
|---|
| 1000 | log.args.on[1][1]()
|
|---|
| 1001 | log.args.on[2][1]('0')
|
|---|
| 1002 | log.args.on[5][1]('foo')
|
|---|
| 1003 | log.args.on[2][1]('1')
|
|---|
| 1004 | log.args.on[5][1]('bar')
|
|---|
| 1005 | log.args.on[2][1]('2')
|
|---|
| 1006 | log.args.on[0][1]()
|
|---|
| 1007 | log.args.on[5][1]('baz')
|
|---|
| 1008 | log.args.on[5][1]('qux')
|
|---|
| 1009 | log.args.on[3][1]()
|
|---|
| 1010 | log.args.on[4][1]()
|
|---|
| 1011 | log.args.on[8][1]()
|
|---|
| 1012 | })
|
|---|
| 1013 |
|
|---|
| 1014 | test('results.push was called three times', () => {
|
|---|
| 1015 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 1016 | })
|
|---|
| 1017 |
|
|---|
| 1018 | test('results.push was called correctly first time', () => {
|
|---|
| 1019 | assert.strictEqual(log.args.push[0][0], 'bar')
|
|---|
| 1020 | })
|
|---|
| 1021 |
|
|---|
| 1022 | test('results.push was called correctly second time', () => {
|
|---|
| 1023 | assert.strictEqual(log.args.push[1][0], 'qux')
|
|---|
| 1024 | })
|
|---|
| 1025 |
|
|---|
| 1026 | test('results.push was called correctly third time', () => {
|
|---|
| 1027 | assert.isNull(log.args.push[2][0])
|
|---|
| 1028 | })
|
|---|
| 1029 |
|
|---|
| 1030 | test('results.emit was not called', () => {
|
|---|
| 1031 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 1032 | })
|
|---|
| 1033 | })
|
|---|
| 1034 | })
|
|---|
| 1035 |
|
|---|
| 1036 | suite('match with bufferLength=3:', () => {
|
|---|
| 1037 | let stream, options, result
|
|---|
| 1038 |
|
|---|
| 1039 | setup(() => {
|
|---|
| 1040 | result = match({}, 'foo', { bufferLength: 3 })
|
|---|
| 1041 | })
|
|---|
| 1042 |
|
|---|
| 1043 | test('DataStream was called once', () => {
|
|---|
| 1044 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 1045 | })
|
|---|
| 1046 |
|
|---|
| 1047 | test('walk was called once', () => {
|
|---|
| 1048 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 1049 | })
|
|---|
| 1050 |
|
|---|
| 1051 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 1052 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 1053 | })
|
|---|
| 1054 |
|
|---|
| 1055 | suite('two matching events:', () => {
|
|---|
| 1056 | setup(() => {
|
|---|
| 1057 | log.args.on[1][1]()
|
|---|
| 1058 | log.args.on[2][1]('foo')
|
|---|
| 1059 | log.args.on[5][1]('bar')
|
|---|
| 1060 | log.args.on[2][1]('baz')
|
|---|
| 1061 | log.args.on[5][1]('qux')
|
|---|
| 1062 | log.args.on[2][1]('foo')
|
|---|
| 1063 | log.args.on[5][1]('wibble')
|
|---|
| 1064 | log.args.on[2][1]('foo')
|
|---|
| 1065 | })
|
|---|
| 1066 |
|
|---|
| 1067 | test('EventEmitter.pause was not called', () => {
|
|---|
| 1068 | assert.strictEqual(log.counts.pause, 0)
|
|---|
| 1069 | })
|
|---|
| 1070 |
|
|---|
| 1071 | suite('matching event:', () => {
|
|---|
| 1072 | setup(() => {
|
|---|
| 1073 | log.args.on[5][1]('blee')
|
|---|
| 1074 | })
|
|---|
| 1075 |
|
|---|
| 1076 | test('results.push was not called', () => {
|
|---|
| 1077 | assert.strictEqual(log.counts.push, 0)
|
|---|
| 1078 | })
|
|---|
| 1079 |
|
|---|
| 1080 | test('EventEmitter.pause was called once', () => {
|
|---|
| 1081 | assert.strictEqual(log.counts.pause, 1)
|
|---|
| 1082 | })
|
|---|
| 1083 |
|
|---|
| 1084 | test('resume was not called', () => {
|
|---|
| 1085 | assert.strictEqual(log.counts.resume, 0)
|
|---|
| 1086 | })
|
|---|
| 1087 |
|
|---|
| 1088 | suite('read:', () => {
|
|---|
| 1089 | setup(() => {
|
|---|
| 1090 | log.args.DataStream[0][0]()
|
|---|
| 1091 | })
|
|---|
| 1092 |
|
|---|
| 1093 | test('resume was called once', () => {
|
|---|
| 1094 | assert.strictEqual(log.counts.resume, 1)
|
|---|
| 1095 | })
|
|---|
| 1096 |
|
|---|
| 1097 | test('results.push was called three times', () => {
|
|---|
| 1098 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 1099 | })
|
|---|
| 1100 |
|
|---|
| 1101 | test('results.push was called correctly first time', () => {
|
|---|
| 1102 | assert.strictEqual(log.args.push[0][0], 'bar')
|
|---|
| 1103 | })
|
|---|
| 1104 |
|
|---|
| 1105 | test('results.push was called correctly second time', () => {
|
|---|
| 1106 | assert.strictEqual(log.args.push[1][0], 'wibble')
|
|---|
| 1107 | })
|
|---|
| 1108 |
|
|---|
| 1109 | test('results.push was called correctly third time', () => {
|
|---|
| 1110 | assert.strictEqual(log.args.push[2][0], 'blee')
|
|---|
| 1111 | })
|
|---|
| 1112 |
|
|---|
| 1113 | test('results.emit was not called', () => {
|
|---|
| 1114 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 1115 | })
|
|---|
| 1116 | })
|
|---|
| 1117 | })
|
|---|
| 1118 | })
|
|---|
| 1119 | })
|
|---|
| 1120 |
|
|---|
| 1121 | suite('match with minDepth=1:', () => {
|
|---|
| 1122 | let stream, predicate, options, result
|
|---|
| 1123 |
|
|---|
| 1124 | setup(() => {
|
|---|
| 1125 | predicate = spooks.fn({ name: 'predicate', log, results: [ true ] })
|
|---|
| 1126 | result = match({}, predicate, { minDepth: 1 })
|
|---|
| 1127 | })
|
|---|
| 1128 |
|
|---|
| 1129 | test('DataStream was called once', () => {
|
|---|
| 1130 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 1131 | })
|
|---|
| 1132 |
|
|---|
| 1133 | test('walk was called once', () => {
|
|---|
| 1134 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 1135 | })
|
|---|
| 1136 |
|
|---|
| 1137 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 1138 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 1139 | })
|
|---|
| 1140 |
|
|---|
| 1141 | suite('read events:', () => {
|
|---|
| 1142 | setup(() => {
|
|---|
| 1143 | log.args.DataStream[0][0]()
|
|---|
| 1144 | // { "foo": { "bar": { "baz": "qux" } } }
|
|---|
| 1145 | log.args.on[1][1]()
|
|---|
| 1146 | log.args.on[2][1]('foo')
|
|---|
| 1147 | log.args.on[1][1]()
|
|---|
| 1148 | log.args.on[2][1]('bar')
|
|---|
| 1149 | log.args.on[1][1]()
|
|---|
| 1150 | log.args.on[2][1]('baz')
|
|---|
| 1151 | log.args.on[5][1]('qux')
|
|---|
| 1152 | log.args.on[4][1]()
|
|---|
| 1153 | log.args.on[4][1]()
|
|---|
| 1154 | log.args.on[4][1]()
|
|---|
| 1155 | log.args.on[8][1]()
|
|---|
| 1156 | })
|
|---|
| 1157 |
|
|---|
| 1158 | test('results.push was called four times', () => {
|
|---|
| 1159 | assert.strictEqual(log.counts.push, 4)
|
|---|
| 1160 | })
|
|---|
| 1161 |
|
|---|
| 1162 | test('results.push was called correctly first time', () => {
|
|---|
| 1163 | const args = log.args.push[0]
|
|---|
| 1164 | assert.lengthOf(args, 1)
|
|---|
| 1165 | assert.equal(args[0], 'qux')
|
|---|
| 1166 | })
|
|---|
| 1167 |
|
|---|
| 1168 | test('results.push was called correctly second time', () => {
|
|---|
| 1169 | const args = log.args.push[1]
|
|---|
| 1170 | assert.lengthOf(args, 1)
|
|---|
| 1171 | assert.deepEqual(args[0], { baz: 'qux' })
|
|---|
| 1172 | })
|
|---|
| 1173 |
|
|---|
| 1174 | test('results.push was called correctly third time', () => {
|
|---|
| 1175 | const args = log.args.push[2]
|
|---|
| 1176 | assert.lengthOf(args, 1)
|
|---|
| 1177 | assert.deepEqual(args[0], { bar: { baz: 'qux' } })
|
|---|
| 1178 | })
|
|---|
| 1179 |
|
|---|
| 1180 | test('results.push was called correctly fourth time', () => {
|
|---|
| 1181 | const args = log.args.push[3]
|
|---|
| 1182 | assert.lengthOf(args, 1)
|
|---|
| 1183 | assert.isNull(args[0])
|
|---|
| 1184 | })
|
|---|
| 1185 |
|
|---|
| 1186 | test('results.emit was not called', () => {
|
|---|
| 1187 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 1188 | })
|
|---|
| 1189 | })
|
|---|
| 1190 | })
|
|---|
| 1191 |
|
|---|
| 1192 | suite('match with minDepth=2:', () => {
|
|---|
| 1193 | let stream, predicate, options, result
|
|---|
| 1194 |
|
|---|
| 1195 | setup(() => {
|
|---|
| 1196 | predicate = spooks.fn({ name: 'predicate', log, results: [ true ] })
|
|---|
| 1197 | result = match({}, predicate, { minDepth: 2 })
|
|---|
| 1198 | })
|
|---|
| 1199 |
|
|---|
| 1200 | test('DataStream was called once', () => {
|
|---|
| 1201 | assert.strictEqual(log.counts.DataStream, 1)
|
|---|
| 1202 | })
|
|---|
| 1203 |
|
|---|
| 1204 | test('walk was called once', () => {
|
|---|
| 1205 | assert.strictEqual(log.counts.walk, 1)
|
|---|
| 1206 | })
|
|---|
| 1207 |
|
|---|
| 1208 | test('EventEmitter.on was called eleven times', () => {
|
|---|
| 1209 | assert.strictEqual(log.counts.on, 11)
|
|---|
| 1210 | })
|
|---|
| 1211 |
|
|---|
| 1212 | suite('read events:', () => {
|
|---|
| 1213 | setup(() => {
|
|---|
| 1214 | log.args.DataStream[0][0]()
|
|---|
| 1215 | // { "foo": { "bar": { "baz": "qux" } } }
|
|---|
| 1216 | log.args.on[1][1]()
|
|---|
| 1217 | log.args.on[2][1]('foo')
|
|---|
| 1218 | log.args.on[1][1]()
|
|---|
| 1219 | log.args.on[2][1]('bar')
|
|---|
| 1220 | log.args.on[1][1]()
|
|---|
| 1221 | log.args.on[2][1]('baz')
|
|---|
| 1222 | log.args.on[5][1]('qux')
|
|---|
| 1223 | log.args.on[4][1]()
|
|---|
| 1224 | log.args.on[4][1]()
|
|---|
| 1225 | log.args.on[4][1]()
|
|---|
| 1226 | log.args.on[8][1]()
|
|---|
| 1227 | })
|
|---|
| 1228 |
|
|---|
| 1229 | test('results.push was called three times', () => {
|
|---|
| 1230 | assert.strictEqual(log.counts.push, 3)
|
|---|
| 1231 | })
|
|---|
| 1232 |
|
|---|
| 1233 | test('results.push was called correctly first time', () => {
|
|---|
| 1234 | const args = log.args.push[0]
|
|---|
| 1235 | assert.lengthOf(args, 1)
|
|---|
| 1236 | assert.equal(args[0], 'qux')
|
|---|
| 1237 | })
|
|---|
| 1238 |
|
|---|
| 1239 | test('results.push was called correctly second time', () => {
|
|---|
| 1240 | const args = log.args.push[1]
|
|---|
| 1241 | assert.lengthOf(args, 1)
|
|---|
| 1242 | assert.deepEqual(args[0], { baz: 'qux' })
|
|---|
| 1243 | })
|
|---|
| 1244 |
|
|---|
| 1245 | test('results.push was called correctly third time', () => {
|
|---|
| 1246 | const args = log.args.push[2]
|
|---|
| 1247 | assert.lengthOf(args, 1)
|
|---|
| 1248 | assert.isNull(args[0])
|
|---|
| 1249 | })
|
|---|
| 1250 |
|
|---|
| 1251 | test('results.emit was not called', () => {
|
|---|
| 1252 | assert.strictEqual(log.counts.emit, 0)
|
|---|
| 1253 | })
|
|---|
| 1254 | })
|
|---|
| 1255 | })
|
|---|
| 1256 | })
|
|---|
| 1257 | })
|
|---|