source: frontend/node_modules/bfj/test/unit/walk.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 84.7 KB
Line 
1'use strict'
2
3const assert = require('chai').assert
4const spooks = require('spooks')
5const Readable = require('stream').Readable
6const events = require('../../src/events')
7
8const modulePath = '../../src/walk'
9
10suite('walk:', () => {
11 let log
12
13 setup(() => {
14 log = {}
15 })
16
17 test('require does not throw', () => {
18 assert.doesNotThrow(() => {
19 require(modulePath)
20 })
21 })
22
23 test('require returns function', () => {
24 assert.isFunction(require(modulePath))
25 })
26
27 suite('require:', () => {
28 let walk
29
30 setup(() => {
31 walk = require(modulePath)
32 })
33
34 test('walk throws without readable stream', () => {
35 assert.throws(() => {
36 walk({ on: () => {} })
37 })
38 })
39
40 test('walk does not throw with readable stream', () => {
41 assert.doesNotThrow(() => {
42 walk(new Readable())
43 })
44 })
45
46 test('walk returns emitter', () => {
47 assert.instanceOf(walk(new Readable()), require('events').EventEmitter)
48 })
49
50 test('EventEmitter is decorated with pause method', () => {
51 assert.isFunction(walk(new Readable()).pause)
52 assert.lengthOf(walk(new Readable()).pause, 0)
53 })
54
55 test('pause method returns continue function', () => {
56 assert.isFunction(walk(new Readable()).pause())
57 assert.lengthOf(walk(new Readable()).pause(), 0)
58 })
59
60 suite('empty json:', () => {
61 let stream, emitter
62
63 setup(done => {
64 stream = new Readable()
65 stream._read = () => {}
66
67 emitter = walk(stream)
68
69 stream.push('')
70 stream.push(null)
71
72 Object.entries(events).forEach(([ key, value ]) => {
73 emitter.on(value, spooks.fn({
74 name: key,
75 log: log
76 }))
77 })
78
79 emitter.on(events.end, done)
80 })
81
82 test('end event occurred once', () => {
83 assert.strictEqual(log.counts.end, 1)
84 })
85
86 test('end event was dispatched correctly', () => {
87 assert.lengthOf(log.args.end[0], 0)
88 })
89
90 test('array event did not occur', () => {
91 assert.strictEqual(log.counts.array, 0)
92 })
93
94 test('object event did not occur', () => {
95 assert.strictEqual(log.counts.object, 0)
96 })
97
98 test('property event did not occur', () => {
99 assert.strictEqual(log.counts.property, 0)
100 })
101
102 test('string event did not occur', () => {
103 assert.strictEqual(log.counts.string, 0)
104 })
105
106 test('number event did not occur', () => {
107 assert.strictEqual(log.counts.number, 0)
108 })
109
110 test('literal event did not occur', () => {
111 assert.strictEqual(log.counts.literal, 0)
112 })
113
114 test('endArray event did not occur', () => {
115 assert.strictEqual(log.counts.endArray, 0)
116 })
117
118 test('endObject event did not occur', () => {
119 assert.strictEqual(log.counts.endObject, 0)
120 })
121
122 test('error event did not occur', () => {
123 assert.strictEqual(log.counts.error, 0)
124 })
125
126 test('dataError event did not occur', () => {
127 assert.strictEqual(log.counts.dataError, 0)
128 })
129
130 test('endLine event did not occur', () => {
131 assert.strictEqual(log.counts.endLine, 0)
132 })
133
134 test('endPrefix event did not occur', () => {
135 assert.strictEqual(log.counts.endPrefix, 0)
136 })
137 })
138
139 suite('empty array:', () => {
140 let stream, emitter
141
142 setup(done => {
143 stream = new Readable()
144 stream._read = () => {}
145
146 emitter = walk(stream)
147
148 stream.push('[]')
149 stream.push(null)
150
151 Object.entries(events).forEach(([ key, value ]) => {
152 emitter.on(value, spooks.fn({
153 name: key,
154 log: log
155 }))
156 })
157
158 emitter.on(events.end, done)
159 })
160
161 test('array event occurred once', () => {
162 assert.strictEqual(log.counts.array, 1)
163 })
164
165 test('array event was dispatched correctly', () => {
166 assert.lengthOf(log.args.array[0], 0)
167 })
168
169 test('endArray event occurred once', () => {
170 assert.strictEqual(log.counts.endArray, 1)
171 })
172
173 test('endArray event was dispatched correctly', () => {
174 assert.lengthOf(log.args.endArray[0], 0)
175 })
176
177 test('end event occurred once', () => {
178 assert.strictEqual(log.counts.end, 1)
179 })
180
181 test('object event did not occur', () => {
182 assert.strictEqual(log.counts.object, 0)
183 })
184
185 test('property event did not occur', () => {
186 assert.strictEqual(log.counts.property, 0)
187 })
188
189 test('string event did not occur', () => {
190 assert.strictEqual(log.counts.string, 0)
191 })
192
193 test('number event did not occur', () => {
194 assert.strictEqual(log.counts.number, 0)
195 })
196
197 test('literal event did not occur', () => {
198 assert.strictEqual(log.counts.literal, 0)
199 })
200
201 test('endObject event did not occur', () => {
202 assert.strictEqual(log.counts.endObject, 0)
203 })
204
205 test('error event did not occur', () => {
206 assert.strictEqual(log.counts.error, 0)
207 })
208
209 test('dataError event did not occur', () => {
210 assert.strictEqual(log.counts.dataError, 0)
211 })
212
213 test('endLine event did not occur', () => {
214 assert.strictEqual(log.counts.endLine, 0)
215 })
216
217 test('endPrefix event did not occur', () => {
218 assert.strictEqual(log.counts.endPrefix, 0)
219 })
220 })
221
222 suite('empty object:', () => {
223 let stream, emitter
224
225 setup(done => {
226 stream = new Readable()
227 stream._read = () => {}
228
229 emitter = walk(stream)
230
231 stream.push('{}')
232 stream.push(null)
233
234 Object.entries(events).forEach(([ key, value ]) => {
235 emitter.on(value, spooks.fn({
236 name: key,
237 log: log
238 }))
239 })
240
241 emitter.on(events.end, done)
242 })
243
244 test('object event occurred once', () => {
245 assert.strictEqual(log.counts.object, 1)
246 })
247
248 test('object event was dispatched correctly', () => {
249 assert.lengthOf(log.args.object[0], 0)
250 })
251
252 test('endObject event occurred once', () => {
253 assert.strictEqual(log.counts.endObject, 1)
254 })
255
256 test('endObject event was dispatched correctly', () => {
257 assert.lengthOf(log.args.endObject[0], 0)
258 })
259
260 test('end event occurred once', () => {
261 assert.strictEqual(log.counts.end, 1)
262 })
263
264 test('array event did not occur', () => {
265 assert.strictEqual(log.counts.array, 0)
266 })
267
268 test('property event did not occur', () => {
269 assert.strictEqual(log.counts.property, 0)
270 })
271
272 test('string event did not occur', () => {
273 assert.strictEqual(log.counts.string, 0)
274 })
275
276 test('number event did not occur', () => {
277 assert.strictEqual(log.counts.number, 0)
278 })
279
280 test('literal event did not occur', () => {
281 assert.strictEqual(log.counts.literal, 0)
282 })
283
284 test('endArray event did not occur', () => {
285 assert.strictEqual(log.counts.endArray, 0)
286 })
287
288 test('error event did not occur', () => {
289 assert.strictEqual(log.counts.error, 0)
290 })
291
292 test('dataError event did not occur', () => {
293 assert.strictEqual(log.counts.dataError, 0)
294 })
295
296 test('endLine event did not occur', () => {
297 assert.strictEqual(log.counts.endLine, 0)
298 })
299
300 test('endPrefix event did not occur', () => {
301 assert.strictEqual(log.counts.endPrefix, 0)
302 })
303 })
304
305 suite('string:', () => {
306 let stream, emitter
307
308 setup(done => {
309 stream = new Readable()
310 stream._read = () => {}
311
312 emitter = walk(stream)
313
314 stream.push('"\\"the quick brown fox\r\n\\tjumps\\u00a0over the lazy\\u1680dog\\""')
315 stream.push(null)
316
317 Object.entries(events).forEach(([ key, value ]) => {
318 emitter.on(value, spooks.fn({
319 name: key,
320 log: log
321 }))
322 })
323
324 emitter.on(events.end, done)
325 })
326
327 test('string event occurred once', () => {
328 assert.strictEqual(log.counts.string, 1)
329 })
330
331 test('string event was dispatched correctly', () => {
332 assert.lengthOf(log.args.string[0], 1)
333 assert.strictEqual(log.args.string[0][0], '"the quick brown fox\r\n\tjumps\u00a0over the lazy\u1680dog"')
334 })
335
336 test('end event occurred once', () => {
337 assert.strictEqual(log.counts.end, 1)
338 })
339
340 test('array event did not occur', () => {
341 assert.strictEqual(log.counts.array, 0)
342 })
343
344 test('object event did not occur', () => {
345 assert.strictEqual(log.counts.object, 0)
346 })
347
348 test('property event did not occur', () => {
349 assert.strictEqual(log.counts.property, 0)
350 })
351
352 test('number event did not occur', () => {
353 assert.strictEqual(log.counts.number, 0)
354 })
355
356 test('literal event did not occur', () => {
357 assert.strictEqual(log.counts.literal, 0)
358 })
359
360 test('endArray event did not occur', () => {
361 assert.strictEqual(log.counts.endArray, 0)
362 })
363
364 test('endObject event did not occur', () => {
365 assert.strictEqual(log.counts.endObject, 0)
366 })
367
368 test('error event did not occur', () => {
369 assert.strictEqual(log.counts.error, 0)
370 })
371
372 test('dataError event did not occur', () => {
373 assert.strictEqual(log.counts.dataError, 0)
374 })
375
376 test('endLine event did not occur', () => {
377 assert.strictEqual(log.counts.endLine, 0)
378 })
379
380 test('endPrefix event did not occur', () => {
381 assert.strictEqual(log.counts.endPrefix, 0)
382 })
383 })
384
385 suite('number:', () => {
386 let stream, emitter
387
388 setup(done => {
389 stream = new Readable()
390 stream._read = () => {}
391
392 emitter = walk(stream)
393
394 stream.push('-3.14159265359e+42')
395 stream.push(null)
396
397 Object.entries(events).forEach(([ key, value ]) => {
398 emitter.on(value, spooks.fn({
399 name: key,
400 log: log
401 }))
402 })
403
404 emitter.on(events.end, done)
405 })
406
407 test('number event occurred once', () => {
408 assert.strictEqual(log.counts.number, 1)
409 })
410
411 test('number event was dispatched correctly', () => {
412 assert.lengthOf(log.args.number[0], 1)
413 assert.strictEqual(log.args.number[0][0], -3.14159265359e+42)
414 })
415
416 test('end event occurred once', () => {
417 assert.strictEqual(log.counts.end, 1)
418 })
419
420 test('array event did not occur', () => {
421 assert.strictEqual(log.counts.array, 0)
422 })
423
424 test('object event did not occur', () => {
425 assert.strictEqual(log.counts.object, 0)
426 })
427
428 test('property event did not occur', () => {
429 assert.strictEqual(log.counts.property, 0)
430 })
431
432 test('string event did not occur', () => {
433 assert.strictEqual(log.counts.string, 0)
434 })
435
436 test('literal event did not occur', () => {
437 assert.strictEqual(log.counts.literal, 0)
438 })
439
440 test('endArray event did not occur', () => {
441 assert.strictEqual(log.counts.endArray, 0)
442 })
443
444 test('endObject event did not occur', () => {
445 assert.strictEqual(log.counts.endObject, 0)
446 })
447
448 test('error event did not occur', () => {
449 assert.strictEqual(log.counts.error, 0)
450 })
451
452 test('dataError event did not occur', () => {
453 assert.strictEqual(log.counts.dataError, 0)
454 })
455
456 test('endLine event did not occur', () => {
457 assert.strictEqual(log.counts.endLine, 0)
458 })
459
460 test('endPrefix event did not occur', () => {
461 assert.strictEqual(log.counts.endPrefix, 0)
462 })
463 })
464
465 suite('literal false:', () => {
466 let stream, emitter
467
468 setup(done => {
469 stream = new Readable()
470 stream._read = () => {}
471
472 emitter = walk(stream)
473
474 stream.push('false')
475 stream.push(null)
476
477 Object.entries(events).forEach(([ key, value ]) => {
478 emitter.on(value, spooks.fn({
479 name: key,
480 log: log
481 }))
482 })
483
484 emitter.on(events.end, done)
485 })
486
487 test('literal event occurred once', () => {
488 assert.strictEqual(log.counts.literal, 1)
489 })
490
491 test('literal event was dispatched correctly', () => {
492 assert.lengthOf(log.args.literal[0], 1)
493 assert.strictEqual(log.args.literal[0][0], false)
494 })
495
496 test('end event occurred once', () => {
497 assert.strictEqual(log.counts.end, 1)
498 })
499
500 test('array event did not occur', () => {
501 assert.strictEqual(log.counts.array, 0)
502 })
503
504 test('object event did not occur', () => {
505 assert.strictEqual(log.counts.object, 0)
506 })
507
508 test('property event did not occur', () => {
509 assert.strictEqual(log.counts.property, 0)
510 })
511
512 test('string event did not occur', () => {
513 assert.strictEqual(log.counts.string, 0)
514 })
515
516 test('number event did not occur', () => {
517 assert.strictEqual(log.counts.number, 0)
518 })
519
520 test('endArray event did not occur', () => {
521 assert.strictEqual(log.counts.endArray, 0)
522 })
523
524 test('endObject event did not occur', () => {
525 assert.strictEqual(log.counts.endObject, 0)
526 })
527
528 test('error event did not occur', () => {
529 assert.strictEqual(log.counts.error, 0)
530 })
531
532 test('dataError event did not occur', () => {
533 assert.strictEqual(log.counts.dataError, 0)
534 })
535
536 test('endLine event did not occur', () => {
537 assert.strictEqual(log.counts.endLine, 0)
538 })
539
540 test('endPrefix event did not occur', () => {
541 assert.strictEqual(log.counts.endPrefix, 0)
542 })
543 })
544
545 suite('literal null:', () => {
546 let stream, emitter
547
548 setup(done => {
549 stream = new Readable()
550 stream._read = () => {}
551
552 emitter = walk(stream)
553
554 stream.push('null')
555 stream.push(null)
556
557 Object.entries(events).forEach(([ key, value ]) => {
558 emitter.on(value, spooks.fn({
559 name: key,
560 log: log
561 }))
562 })
563
564 emitter.on(events.end, done)
565 })
566
567 test('literal event occurred once', () => {
568 assert.strictEqual(log.counts.literal, 1)
569 })
570
571 test('literal event was dispatched correctly', () => {
572 assert.strictEqual(log.args.literal[0][0], null)
573 })
574
575 test('end event occurred once', () => {
576 assert.strictEqual(log.counts.end, 1)
577 })
578
579 test('array event did not occur', () => {
580 assert.strictEqual(log.counts.array, 0)
581 })
582
583 test('object event did not occur', () => {
584 assert.strictEqual(log.counts.object, 0)
585 })
586
587 test('property event did not occur', () => {
588 assert.strictEqual(log.counts.property, 0)
589 })
590
591 test('string event did not occur', () => {
592 assert.strictEqual(log.counts.string, 0)
593 })
594
595 test('number event did not occur', () => {
596 assert.strictEqual(log.counts.number, 0)
597 })
598
599 test('endArray event did not occur', () => {
600 assert.strictEqual(log.counts.endArray, 0)
601 })
602
603 test('endObject event did not occur', () => {
604 assert.strictEqual(log.counts.endObject, 0)
605 })
606
607 test('error event did not occur', () => {
608 assert.strictEqual(log.counts.error, 0)
609 })
610
611 test('dataError event did not occur', () => {
612 assert.strictEqual(log.counts.dataError, 0)
613 })
614
615 test('endLine event did not occur', () => {
616 assert.strictEqual(log.counts.endLine, 0)
617 })
618
619 test('endPrefix event did not occur', () => {
620 assert.strictEqual(log.counts.endPrefix, 0)
621 })
622 })
623
624 suite('literal true:', () => {
625 let stream, emitter
626
627 setup(done => {
628 stream = new Readable()
629 stream._read = () => {}
630
631 emitter = walk(stream)
632
633 stream.push('true')
634 stream.push(null)
635
636 Object.entries(events).forEach(([ key, value ]) => {
637 emitter.on(value, spooks.fn({
638 name: key,
639 log: log
640 }))
641 })
642
643 emitter.on(events.end, done)
644 })
645
646 test('literal event occurred once', () => {
647 assert.strictEqual(log.counts.literal, 1)
648 })
649
650 test('literal event was dispatched correctly', () => {
651 assert.strictEqual(log.args.literal[0][0], true)
652 })
653
654 test('end event occurred once', () => {
655 assert.strictEqual(log.counts.end, 1)
656 })
657
658 test('array event did not occur', () => {
659 assert.strictEqual(log.counts.array, 0)
660 })
661
662 test('object event did not occur', () => {
663 assert.strictEqual(log.counts.object, 0)
664 })
665
666 test('property event did not occur', () => {
667 assert.strictEqual(log.counts.property, 0)
668 })
669
670 test('string event did not occur', () => {
671 assert.strictEqual(log.counts.string, 0)
672 })
673
674 test('number event did not occur', () => {
675 assert.strictEqual(log.counts.number, 0)
676 })
677
678 test('endArray event did not occur', () => {
679 assert.strictEqual(log.counts.endArray, 0)
680 })
681
682 test('endObject event did not occur', () => {
683 assert.strictEqual(log.counts.endObject, 0)
684 })
685
686 test('error event did not occur', () => {
687 assert.strictEqual(log.counts.error, 0)
688 })
689
690 test('dataError event did not occur', () => {
691 assert.strictEqual(log.counts.dataError, 0)
692 })
693
694 test('endLine event did not occur', () => {
695 assert.strictEqual(log.counts.endLine, 0)
696 })
697
698 test('endPrefix event did not occur', () => {
699 assert.strictEqual(log.counts.endPrefix, 0)
700 })
701 })
702
703 suite('badly-closed array:', () => {
704 let stream, emitter
705
706 setup(done => {
707 stream = new Readable()
708 stream._read = () => {}
709
710 emitter = walk(stream)
711
712 stream.push('[}')
713 stream.push(null)
714
715 Object.entries(events).forEach(([ key, value ]) => {
716 emitter.on(value, spooks.fn({
717 name: key,
718 log: log
719 }))
720 })
721
722 emitter.on(events.end, done)
723 })
724
725 test('array event occurred once', () => {
726 assert.strictEqual(log.counts.array, 1)
727 })
728
729 test('dataError event occurred twice', () => {
730 assert.strictEqual(log.counts.dataError, 2)
731 })
732
733 test('dataError event was dispatched correctly first time', () => {
734 assert.lengthOf(log.args.dataError[0], 1)
735 assert.instanceOf(log.args.dataError[0][0], Error)
736 assert.strictEqual(log.args.dataError[0][0].actual, '}')
737 assert.strictEqual(log.args.dataError[0][0].expected, 'value')
738 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
739 assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
740 })
741
742 test('dataError event was dispatched correctly second time', () => {
743 assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
744 assert.strictEqual(log.args.dataError[1][0].expected, ']')
745 assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
746 assert.strictEqual(log.args.dataError[1][0].columnNumber, 3)
747 })
748
749 test('end event occurred once', () => {
750 assert.strictEqual(log.counts.end, 1)
751 })
752
753 test('object event did not occur', () => {
754 assert.strictEqual(log.counts.object, 0)
755 })
756
757 test('endArray event did not occur', () => {
758 assert.strictEqual(log.counts.endArray, 0)
759 })
760
761 test('endObject event did not occur', () => {
762 assert.strictEqual(log.counts.endObject, 0)
763 })
764 })
765
766 suite('badly-closed object:', () => {
767 let stream, emitter
768
769 setup(done => {
770 stream = new Readable()
771 stream._read = () => {}
772
773 emitter = walk(stream)
774
775 stream.push('{]')
776 stream.push(null)
777
778 Object.entries(events).forEach(([ key, value ]) => {
779 emitter.on(value, spooks.fn({
780 name: key,
781 log: log
782 }))
783 })
784
785 emitter.on(events.end, done)
786 })
787
788 test('object event occurred once', () => {
789 assert.strictEqual(log.counts.object, 1)
790 })
791
792 test('dataError event occurred three times', () => {
793 assert.strictEqual(log.counts.dataError, 3)
794 })
795
796 test('dataError event was dispatched correctly first time', () => {
797 assert.strictEqual(log.args.dataError[0][0].actual, ']')
798 assert.strictEqual(log.args.dataError[0][0].expected, '"')
799 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
800 assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
801 })
802
803 test('dataError event was dispatched correctly second time', () => {
804 assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
805 assert.strictEqual(log.args.dataError[1][0].expected, '"')
806 assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
807 assert.strictEqual(log.args.dataError[1][0].columnNumber, 3)
808 })
809
810 test('dataError event was dispatched correctly third time', () => {
811 assert.strictEqual(log.args.dataError[2][0].actual, 'EOF')
812 assert.strictEqual(log.args.dataError[2][0].expected, '}')
813 assert.strictEqual(log.args.dataError[2][0].lineNumber, 1)
814 assert.strictEqual(log.args.dataError[2][0].columnNumber, 3)
815 })
816
817 test('end event occurred once', () => {
818 assert.strictEqual(log.counts.end, 1)
819 })
820
821 test('array event did not occur', () => {
822 assert.strictEqual(log.counts.array, 0)
823 })
824
825 test('endArray event did not occur', () => {
826 assert.strictEqual(log.counts.endArray, 0)
827 })
828
829 test('endObject event did not occur', () => {
830 assert.strictEqual(log.counts.endObject, 0)
831 })
832 })
833
834 suite('string containing bad escape sequence:', () => {
835 let stream, emitter
836
837 setup(done => {
838 stream = new Readable()
839 stream._read = () => {}
840
841 emitter = walk(stream)
842
843 stream.push('"\\"the quick brown fox\r\n\\tjumps over the lazy\\xdog\\""')
844 stream.push(null)
845
846 Object.entries(events).forEach(([ key, value ]) => {
847 emitter.on(value, spooks.fn({
848 name: key,
849 log: log
850 }))
851 })
852
853 emitter.on(events.end, done)
854 })
855
856 test('dataError event occurred once', () => {
857 assert.strictEqual(log.counts.dataError, 1)
858 })
859
860 test('dataError event was dispatched correctly', () => {
861 assert.strictEqual(log.args.dataError[0][0].actual, 'x')
862 assert.strictEqual(log.args.dataError[0][0].expected, 'escape character')
863 assert.strictEqual(log.args.dataError[0][0].lineNumber, 2)
864 assert.strictEqual(log.args.dataError[0][0].columnNumber, 23)
865 })
866
867 test('string event occurred once', () => {
868 assert.strictEqual(log.counts.string, 1)
869 })
870
871 test('string event was dispatched correctly', () => {
872 assert.strictEqual(log.args.string[0][0], '"the quick brown fox\r\n\tjumps over the lazy\\xdog"')
873 })
874
875 test('end event occurred once', () => {
876 assert.strictEqual(log.counts.end, 1)
877 })
878 })
879
880 suite('string containing bad unicode escape sequence:', () => {
881 let stream, emitter
882
883 setup(done => {
884 stream = new Readable()
885 stream._read = () => {}
886
887 emitter = walk(stream)
888
889 stream.push('"\\u012g"')
890 stream.push(null)
891
892 Object.entries(events).forEach(([ key, value ]) => {
893 emitter.on(value, spooks.fn({
894 name: key,
895 log: log
896 }))
897 })
898
899 emitter.on(events.end, done)
900 })
901
902 test('dataError event occurred once', () => {
903 assert.strictEqual(log.counts.dataError, 1)
904 })
905
906 test('dataError event was dispatched correctly', () => {
907 assert.strictEqual(log.args.dataError[0][0].actual, 'g')
908 assert.strictEqual(log.args.dataError[0][0].expected, 'hex digit')
909 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
910 assert.strictEqual(log.args.dataError[0][0].columnNumber, 7)
911 })
912
913 test('string event occurred once', () => {
914 assert.strictEqual(log.counts.string, 1)
915 })
916
917 test('string event was dispatched correctly', () => {
918 assert.strictEqual(log.args.string[0][0], '\\u012g')
919 })
920
921 test('end event occurred once', () => {
922 assert.strictEqual(log.counts.end, 1)
923 })
924 })
925
926 suite('unterminated string:', () => {
927 let stream, emitter
928
929 setup(done => {
930 stream = new Readable()
931 stream._read = () => {}
932
933 emitter = walk(stream)
934
935 stream.push('"foo')
936 stream.push(null)
937
938 Object.entries(events).forEach(([ key, value ]) => {
939 emitter.on(value, spooks.fn({
940 name: key,
941 log: log
942 }))
943 })
944
945 emitter.on(events.end, done)
946 })
947
948 test('dataError event occurred once', () => {
949 assert.strictEqual(log.counts.dataError, 1)
950 })
951
952 test('dataError event was dispatched correctly', () => {
953 assert.strictEqual(log.args.dataError[0][0].actual, 'EOF')
954 assert.strictEqual(log.args.dataError[0][0].expected, '"')
955 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
956 assert.strictEqual(log.args.dataError[0][0].columnNumber, 5)
957 })
958
959 test('end event occurred once', () => {
960 assert.strictEqual(log.counts.end, 1)
961 })
962
963 test('string event did not occur', () => {
964 assert.strictEqual(log.counts.string, 0)
965 })
966 })
967
968 suite('bad number:', () => {
969 let stream, emitter
970
971 setup(done => {
972 stream = new Readable()
973 stream._read = () => {}
974
975 emitter = walk(stream)
976
977 stream.push('1e')
978 stream.push(null)
979
980 Object.entries(events).forEach(([ key, value ]) => {
981 emitter.on(value, spooks.fn({
982 name: key,
983 log: log
984 }))
985 })
986
987 emitter.on(events.end, done)
988 })
989
990 test('number event did not occur', () => {
991 assert.strictEqual(log.counts.number, 0)
992 })
993
994 test('dataError event occurred once', () => {
995 assert.strictEqual(log.counts.dataError, 1)
996 })
997
998 test('dataError event was dispatched correctly first time', () => {
999 assert.strictEqual(log.args.dataError[0][0].actual, 'EOF')
1000 assert.strictEqual(log.args.dataError[0][0].expected, 'exponent')
1001 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
1002 assert.strictEqual(log.args.dataError[0][0].columnNumber, 3)
1003 })
1004
1005 test('end event occurred once', () => {
1006 assert.strictEqual(log.counts.end, 1)
1007 })
1008
1009 test('literal event did not occur', () => {
1010 assert.strictEqual(log.counts.literal, 0)
1011 })
1012 })
1013
1014 suite('alternative bad number:', () => {
1015 let stream, emitter
1016
1017 setup(done => {
1018 stream = new Readable()
1019 stream._read = () => {}
1020
1021 emitter = walk(stream)
1022
1023 stream.push('42f')
1024 stream.push(null)
1025
1026 Object.entries(events).forEach(([ key, value ]) => {
1027 emitter.on(value, spooks.fn({
1028 name: key,
1029 log: log
1030 }))
1031 })
1032
1033 emitter.on(events.end, done)
1034 })
1035
1036 test('number event occurred once', () => {
1037 assert.strictEqual(log.counts.number, 1)
1038 })
1039
1040 test('number event was dispatched correctly', () => {
1041 assert.strictEqual(log.args.number[0][0], 42)
1042 })
1043
1044 test('dataError event occurred twice', () => {
1045 assert.strictEqual(log.counts.dataError, 2)
1046 })
1047
1048 test('dataError event was dispatched correctly first time', () => {
1049 assert.strictEqual(log.args.dataError[0][0].actual, 'f')
1050 assert.strictEqual(log.args.dataError[0][0].expected, 'EOF')
1051 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
1052 assert.strictEqual(log.args.dataError[0][0].columnNumber, 3)
1053 })
1054
1055 test('dataError event was dispatched correctly second time', () => {
1056 assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
1057 assert.strictEqual(log.args.dataError[1][0].expected, 'a')
1058 assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
1059 assert.strictEqual(log.args.dataError[1][0].columnNumber, 4)
1060 })
1061
1062 test('end event occurred once', () => {
1063 assert.strictEqual(log.counts.end, 1)
1064 })
1065
1066 test('literal event did not occur', () => {
1067 assert.strictEqual(log.counts.literal, 0)
1068 })
1069 })
1070
1071 suite('bad literal false:', () => {
1072 let stream, emitter
1073
1074 setup(done => {
1075 stream = new Readable()
1076 stream._read = () => {}
1077
1078 emitter = walk(stream)
1079
1080 stream.push('falsd')
1081 stream.push(null)
1082
1083 Object.entries(events).forEach(([ key, value ]) => {
1084 emitter.on(value, spooks.fn({
1085 name: key,
1086 log: log
1087 }))
1088 })
1089
1090 emitter.on(events.end, done)
1091 })
1092
1093 test('dataError event occurred once', () => {
1094 assert.strictEqual(log.counts.dataError, 1)
1095 })
1096
1097 test('dataError event was dispatched correctly', () => {
1098 assert.strictEqual(log.args.dataError[0][0].actual, 'd')
1099 assert.strictEqual(log.args.dataError[0][0].expected, 'e')
1100 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
1101 assert.strictEqual(log.args.dataError[0][0].columnNumber, 5)
1102 })
1103
1104 test('end event occurred once', () => {
1105 assert.strictEqual(log.counts.end, 1)
1106 })
1107
1108 test('literal event did not occur', () => {
1109 assert.strictEqual(log.counts.literal, 0)
1110 })
1111 })
1112
1113 suite('bad literal null:', () => {
1114 let stream, emitter
1115
1116 setup(done => {
1117 stream = new Readable()
1118 stream._read = () => {}
1119
1120 emitter = walk(stream)
1121
1122 stream.push('nul')
1123 stream.push(null)
1124
1125 Object.entries(events).forEach(([ key, value ]) => {
1126 emitter.on(value, spooks.fn({
1127 name: key,
1128 log: log
1129 }))
1130 })
1131
1132 emitter.on(events.end, done)
1133 })
1134
1135 test('dataError event occurred once', () => {
1136 assert.strictEqual(log.counts.dataError, 1)
1137 })
1138
1139 test('dataError event was dispatched correctly', () => {
1140 assert.strictEqual(log.args.dataError[0][0].actual, 'EOF')
1141 assert.strictEqual(log.args.dataError[0][0].expected, 'l')
1142 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
1143 assert.strictEqual(log.args.dataError[0][0].columnNumber, 4)
1144 })
1145
1146 test('end event occurred once', () => {
1147 assert.strictEqual(log.counts.end, 1)
1148 })
1149
1150 test('literal event did not occur', () => {
1151 assert.strictEqual(log.counts.literal, 0)
1152 })
1153 })
1154
1155 suite('bad literal true:', () => {
1156 let stream, emitter
1157
1158 setup(done => {
1159 stream = new Readable()
1160 stream._read = () => {}
1161
1162 emitter = walk(stream)
1163
1164 stream.push('tRue')
1165 stream.push(null)
1166
1167 Object.entries(events).forEach(([ key, value ]) => {
1168 emitter.on(value, spooks.fn({
1169 name: key,
1170 log: log
1171 }))
1172 })
1173
1174 emitter.on(events.end, done)
1175 })
1176
1177 test('dataError event occurred four times', () => {
1178 assert.strictEqual(log.counts.dataError, 4)
1179 })
1180
1181 test('dataError event was dispatched correctly first time', () => {
1182 assert.strictEqual(log.args.dataError[0][0].actual, 'R')
1183 assert.strictEqual(log.args.dataError[0][0].expected, 'r')
1184 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
1185 assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
1186 })
1187
1188 test('dataError event was dispatched correctly second time', () => {
1189 assert.strictEqual(log.args.dataError[1][0].actual, 'u')
1190 assert.strictEqual(log.args.dataError[1][0].expected, 'EOF')
1191 assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
1192 assert.strictEqual(log.args.dataError[1][0].columnNumber, 3)
1193 })
1194
1195 test('dataError event was dispatched correctly third time', () => {
1196 assert.strictEqual(log.args.dataError[2][0].actual, 'u')
1197 assert.strictEqual(log.args.dataError[2][0].expected, 'value')
1198 assert.strictEqual(log.args.dataError[2][0].lineNumber, 1)
1199 assert.strictEqual(log.args.dataError[2][0].columnNumber, 3)
1200 })
1201
1202 test('dataError event was dispatched correctly fourth time', () => {
1203 assert.strictEqual(log.args.dataError[3][0].actual, 'e')
1204 assert.strictEqual(log.args.dataError[3][0].expected, 'value')
1205 assert.strictEqual(log.args.dataError[3][0].lineNumber, 1)
1206 assert.strictEqual(log.args.dataError[3][0].columnNumber, 4)
1207 })
1208
1209 test('end event occurred once', () => {
1210 assert.strictEqual(log.counts.end, 1)
1211 })
1212
1213 test('literal event did not occur', () => {
1214 assert.strictEqual(log.counts.literal, 0)
1215 })
1216 })
1217
1218 suite('array inside array:', () => {
1219 let stream, emitter
1220
1221 setup(done => {
1222 stream = new Readable()
1223 stream._read = () => {}
1224
1225 emitter = walk(stream)
1226
1227 stream.push('[[]]')
1228 stream.push(null)
1229
1230 Object.entries(events).forEach(([ key, value ]) => {
1231 emitter.on(value, spooks.fn({
1232 name: key,
1233 log: log
1234 }))
1235 })
1236
1237 emitter.on(events.end, done)
1238 })
1239
1240 test('array event occurred twice', () => {
1241 assert.strictEqual(log.counts.array, 2)
1242 })
1243
1244 test('endArray event occurred twice', () => {
1245 assert.strictEqual(log.counts.endArray, 2)
1246 })
1247
1248 test('end event occurred once', () => {
1249 assert.strictEqual(log.counts.end, 1)
1250 })
1251
1252 test('error event did not occur', () => {
1253 assert.strictEqual(log.counts.error, 0)
1254 })
1255
1256 test('dataError event did not occur', () => {
1257 assert.strictEqual(log.counts.dataError, 0)
1258 })
1259
1260 test('endLine event did not occur', () => {
1261 assert.strictEqual(log.counts.endLine, 0)
1262 })
1263 })
1264
1265 suite('two arrays inside array:', () => {
1266 let stream, emitter
1267
1268 setup(done => {
1269 stream = new Readable()
1270 stream._read = () => {}
1271
1272 emitter = walk(stream)
1273
1274 stream.push('[[],[]]')
1275 stream.push(null)
1276
1277 Object.entries(events).forEach(([ key, value ]) => {
1278 emitter.on(value, spooks.fn({
1279 name: key,
1280 log: log
1281 }))
1282 })
1283
1284 emitter.on(events.end, done)
1285 })
1286
1287 test('array event occurred three times', () => {
1288 assert.strictEqual(log.counts.array, 3)
1289 })
1290
1291 test('endArray event occurred three times', () => {
1292 assert.strictEqual(log.counts.endArray, 3)
1293 })
1294
1295 test('end event occurred once', () => {
1296 assert.strictEqual(log.counts.end, 1)
1297 })
1298
1299 test('error event did not occur', () => {
1300 assert.strictEqual(log.counts.error, 0)
1301 })
1302
1303 test('dataError event did not occur', () => {
1304 assert.strictEqual(log.counts.dataError, 0)
1305 })
1306 })
1307
1308 suite('two arrays inside array with whitespace:', () => {
1309 let stream, emitter
1310
1311 setup(done => {
1312 stream = new Readable()
1313 stream._read = () => {}
1314
1315 emitter = walk(stream)
1316
1317 stream.push(' [ [] , [] ] ')
1318 stream.push(null)
1319
1320 Object.entries(events).forEach(([ key, value ]) => {
1321 emitter.on(value, spooks.fn({
1322 name: key,
1323 log: log
1324 }))
1325 })
1326
1327 emitter.on(events.end, done)
1328 })
1329
1330 test('array event occurred three times', () => {
1331 assert.strictEqual(log.counts.array, 3)
1332 })
1333
1334 test('endArray event occurred three times', () => {
1335 assert.strictEqual(log.counts.endArray, 3)
1336 })
1337
1338 test('end event occurred once', () => {
1339 assert.strictEqual(log.counts.end, 1)
1340 })
1341
1342 test('error event did not occur', () => {
1343 assert.strictEqual(log.counts.error, 0)
1344 })
1345
1346 test('dataError event did not occur', () => {
1347 assert.strictEqual(log.counts.dataError, 0)
1348 })
1349 })
1350
1351 suite('two arrays inside array without comma:', () => {
1352 let stream, emitter
1353
1354 setup(done => {
1355 stream = new Readable()
1356 stream._read = () => {}
1357
1358 emitter = walk(stream)
1359
1360 stream.push('[[][]]')
1361 stream.push(null)
1362
1363 Object.entries(events).forEach(([ key, value ]) => {
1364 emitter.on(value, spooks.fn({
1365 name: key,
1366 log: log
1367 }))
1368 })
1369
1370 emitter.on(events.end, done)
1371 })
1372
1373 test('array event occurred three times', () => {
1374 assert.strictEqual(log.counts.array, 3)
1375 })
1376
1377 test('endArray event occurred three times', () => {
1378 assert.strictEqual(log.counts.endArray, 3)
1379 })
1380
1381 test('dataError event occurred once', () => {
1382 assert.strictEqual(log.counts.dataError, 1)
1383 })
1384
1385 test('dataError event was dispatched correctly', () => {
1386 assert.strictEqual(log.args.dataError[0][0].actual, '[')
1387 assert.strictEqual(log.args.dataError[0][0].expected, ',')
1388 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
1389 assert.strictEqual(log.args.dataError[0][0].columnNumber, 4)
1390 })
1391
1392 test('end event occurred once', () => {
1393 assert.strictEqual(log.counts.end, 1)
1394 })
1395
1396 test('endObject event did not occur', () => {
1397 assert.strictEqual(log.counts.endObject, 0)
1398 })
1399 })
1400
1401 suite('object inside array:', () => {
1402 let stream, emitter
1403
1404 setup(done => {
1405 stream = new Readable()
1406 stream._read = () => {}
1407
1408 emitter = walk(stream)
1409
1410 stream.push('[{}]')
1411 stream.push(null)
1412
1413 Object.entries(events).forEach(([ key, value ]) => {
1414 emitter.on(value, spooks.fn({
1415 name: key,
1416 log: log
1417 }))
1418 })
1419
1420 emitter.on(events.end, done)
1421 })
1422
1423 test('array event occurred once', () => {
1424 assert.strictEqual(log.counts.array, 1)
1425 })
1426
1427 test('object event occurred once', () => {
1428 assert.strictEqual(log.counts.object, 1)
1429 })
1430
1431 test('endObject event occurred once', () => {
1432 assert.strictEqual(log.counts.endObject, 1)
1433 })
1434
1435 test('endArray event occurred once', () => {
1436 assert.strictEqual(log.counts.endArray, 1)
1437 })
1438
1439 test('end event occurred once', () => {
1440 assert.strictEqual(log.counts.end, 1)
1441 })
1442
1443 test('error event did not occur', () => {
1444 assert.strictEqual(log.counts.error, 0)
1445 })
1446
1447 test('dataError event did not occur', () => {
1448 assert.strictEqual(log.counts.dataError, 0)
1449 })
1450
1451 test('endLine event did not occur', () => {
1452 assert.strictEqual(log.counts.endLine, 0)
1453 })
1454 })
1455
1456 suite('two objects inside array:', () => {
1457 let stream, emitter
1458
1459 setup(done => {
1460 stream = new Readable()
1461 stream._read = () => {}
1462
1463 emitter = walk(stream)
1464
1465 stream.push('[{},{}]')
1466 stream.push(null)
1467
1468 Object.entries(events).forEach(([ key, value ]) => {
1469 emitter.on(value, spooks.fn({
1470 name: key,
1471 log: log
1472 }))
1473 })
1474
1475 emitter.on(events.end, done)
1476 })
1477
1478 test('array event occurred once', () => {
1479 assert.strictEqual(log.counts.array, 1)
1480 })
1481
1482 test('object event occurred twice', () => {
1483 assert.strictEqual(log.counts.object, 2)
1484 })
1485
1486 test('endObject event occurred twice', () => {
1487 assert.strictEqual(log.counts.endObject, 2)
1488 })
1489
1490 test('endArray event occurred once', () => {
1491 assert.strictEqual(log.counts.endArray, 1)
1492 })
1493
1494 test('end event occurred once', () => {
1495 assert.strictEqual(log.counts.end, 1)
1496 })
1497
1498 test('error event did not occur', () => {
1499 assert.strictEqual(log.counts.error, 0)
1500 })
1501
1502 test('dataError event did not occur', () => {
1503 assert.strictEqual(log.counts.dataError, 0)
1504 })
1505 })
1506
1507 suite('two objects inside array with whitespace:', () => {
1508 let stream, emitter
1509
1510 setup(done => {
1511 stream = new Readable()
1512 stream._read = () => {}
1513
1514 emitter = walk(stream)
1515
1516 stream.push('\t[\t{}\t,\r{}\n]\r\n')
1517 stream.push(null)
1518
1519 Object.entries(events).forEach(([ key, value ]) => {
1520 emitter.on(value, spooks.fn({
1521 name: key,
1522 log: log
1523 }))
1524 })
1525
1526 emitter.on(events.end, done)
1527 })
1528
1529 test('array event occurred once', () => {
1530 assert.strictEqual(log.counts.array, 1)
1531 })
1532
1533 test('object event occurred twice', () => {
1534 assert.strictEqual(log.counts.object, 2)
1535 })
1536
1537 test('endObject event occurred twice', () => {
1538 assert.strictEqual(log.counts.endObject, 2)
1539 })
1540
1541 test('endArray event occurred once', () => {
1542 assert.strictEqual(log.counts.endArray, 1)
1543 })
1544
1545 test('end event occurred once', () => {
1546 assert.strictEqual(log.counts.end, 1)
1547 })
1548
1549 test('error event did not occur', () => {
1550 assert.strictEqual(log.counts.error, 0)
1551 })
1552
1553 test('dataError event did not occur', () => {
1554 assert.strictEqual(log.counts.dataError, 0)
1555 })
1556 })
1557
1558 suite('two objects inside array without comma:', () => {
1559 let stream, emitter
1560
1561 setup(done => {
1562 stream = new Readable()
1563 stream._read = () => {}
1564
1565 emitter = walk(stream)
1566
1567 stream.push('[ {} {} ]')
1568 stream.push(null)
1569
1570 Object.entries(events).forEach(([ key, value ]) => {
1571 emitter.on(value, spooks.fn({
1572 name: key,
1573 log: log
1574 }))
1575 })
1576
1577 emitter.on(events.end, done)
1578 })
1579
1580 test('array event occurred once', () => {
1581 assert.strictEqual(log.counts.array, 1)
1582 })
1583
1584 test('object event occurred twice', () => {
1585 assert.strictEqual(log.counts.object, 2)
1586 })
1587
1588 test('endObject event occurred twice', () => {
1589 assert.strictEqual(log.counts.endObject, 2)
1590 })
1591
1592 test('dataError event occurred once', () => {
1593 assert.strictEqual(log.counts.dataError, 1)
1594 })
1595
1596 test('dataError event was dispatched correctly', () => {
1597 assert.strictEqual(log.args.dataError[0][0].actual, '{')
1598 assert.strictEqual(log.args.dataError[0][0].expected, ',')
1599 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
1600 assert.strictEqual(log.args.dataError[0][0].columnNumber, 6)
1601 })
1602
1603 test('endArray event occurred once', () => {
1604 assert.strictEqual(log.counts.endArray, 1)
1605 })
1606
1607 test('end event occurred once', () => {
1608 assert.strictEqual(log.counts.end, 1)
1609 })
1610 })
1611
1612 suite('string inside array:', () => {
1613 let stream, emitter
1614
1615 setup(done => {
1616 stream = new Readable()
1617 stream._read = () => {}
1618
1619 emitter = walk(stream)
1620
1621 stream.push('["foo"]')
1622 stream.push(null)
1623
1624 Object.entries(events).forEach(([ key, value ]) => {
1625 emitter.on(value, spooks.fn({
1626 name: key,
1627 log: log
1628 }))
1629 })
1630
1631 emitter.on(events.end, done)
1632 })
1633
1634 test('array event occurred once', () => {
1635 assert.strictEqual(log.counts.array, 1)
1636 })
1637
1638 test('string event occurred once', () => {
1639 assert.strictEqual(log.counts.string, 1)
1640 })
1641
1642 test('string event was dispatched correctly', () => {
1643 assert.strictEqual(log.args.string[0][0], 'foo')
1644 })
1645
1646 test('endArray event occurred once', () => {
1647 assert.strictEqual(log.counts.endArray, 1)
1648 })
1649
1650 test('end event occurred once', () => {
1651 assert.strictEqual(log.counts.end, 1)
1652 })
1653
1654 test('object event did not occur', () => {
1655 assert.strictEqual(log.counts.object, 0)
1656 })
1657
1658 test('error event did not occur', () => {
1659 assert.strictEqual(log.counts.error, 0)
1660 })
1661
1662 test('dataError event did not occur', () => {
1663 assert.strictEqual(log.counts.dataError, 0)
1664 })
1665
1666 test('endLine event did not occur', () => {
1667 assert.strictEqual(log.counts.endLine, 0)
1668 })
1669 })
1670
1671 suite('two strings inside array:', () => {
1672 let stream, emitter
1673
1674 setup(done => {
1675 stream = new Readable()
1676 stream._read = () => {}
1677
1678 emitter = walk(stream)
1679
1680 stream.push('["foo","bar"]')
1681 stream.push(null)
1682
1683 Object.entries(events).forEach(([ key, value ]) => {
1684 emitter.on(value, spooks.fn({
1685 name: key,
1686 log: log
1687 }))
1688 })
1689
1690 emitter.on(events.end, done)
1691 })
1692
1693 test('array event occurred once', () => {
1694 assert.strictEqual(log.counts.array, 1)
1695 })
1696
1697 test('string event occurred twice', () => {
1698 assert.strictEqual(log.counts.string, 2)
1699 })
1700
1701 test('string event was dispatched correctly first time', () => {
1702 assert.strictEqual(log.args.string[0][0], 'foo')
1703 })
1704
1705 test('string event was dispatched correctly second time', () => {
1706 assert.strictEqual(log.args.string[1][0], 'bar')
1707 })
1708
1709 test('endArray event occurred once', () => {
1710 assert.strictEqual(log.counts.endArray, 1)
1711 })
1712
1713 test('end event occurred once', () => {
1714 assert.strictEqual(log.counts.end, 1)
1715 })
1716
1717 test('error event did not occur', () => {
1718 assert.strictEqual(log.counts.error, 0)
1719 })
1720
1721 test('dataError event did not occur', () => {
1722 assert.strictEqual(log.counts.dataError, 0)
1723 })
1724 })
1725
1726 suite('two strings inside array with whitespace:', () => {
1727 let stream, emitter
1728
1729 setup(done => {
1730 stream = new Readable()
1731 stream._read = () => {}
1732
1733 emitter = walk(stream)
1734
1735 stream.push(' [ "baz" , "qux" ] ')
1736 stream.push(null)
1737
1738 Object.entries(events).forEach(([ key, value ]) => {
1739 emitter.on(value, spooks.fn({
1740 name: key,
1741 log: log
1742 }))
1743 })
1744
1745 emitter.on(events.end, done)
1746 })
1747
1748 test('array event occurred once', () => {
1749 assert.strictEqual(log.counts.array, 1)
1750 })
1751
1752 test('string event occurred twice', () => {
1753 assert.strictEqual(log.counts.string, 2)
1754 })
1755
1756 test('string event was dispatched correctly first time', () => {
1757 assert.strictEqual(log.args.string[0][0], 'baz')
1758 })
1759
1760 test('string event was dispatched correctly second time', () => {
1761 assert.strictEqual(log.args.string[1][0], 'qux')
1762 })
1763
1764 test('endArray event occurred once', () => {
1765 assert.strictEqual(log.counts.endArray, 1)
1766 })
1767
1768 test('end event occurred once', () => {
1769 assert.strictEqual(log.counts.end, 1)
1770 })
1771
1772 test('error event did not occur', () => {
1773 assert.strictEqual(log.counts.error, 0)
1774 })
1775
1776 test('dataError event did not occur', () => {
1777 assert.strictEqual(log.counts.dataError, 0)
1778 })
1779 })
1780
1781 suite('literal inside array:', () => {
1782 let stream, emitter
1783
1784 setup(done => {
1785 stream = new Readable()
1786 stream._read = () => {}
1787
1788 emitter = walk(stream)
1789
1790 stream.push('[false]')
1791 stream.push(null)
1792
1793 Object.entries(events).forEach(([ key, value ]) => {
1794 emitter.on(value, spooks.fn({
1795 name: key,
1796 log: log
1797 }))
1798 })
1799
1800 emitter.on(events.end, done)
1801 })
1802
1803 test('array event occurred once', () => {
1804 assert.strictEqual(log.counts.array, 1)
1805 })
1806
1807 test('literal event occurred once', () => {
1808 assert.strictEqual(log.counts.literal, 1)
1809 })
1810
1811 test('literal event was dispatched correctly', () => {
1812 assert.strictEqual(log.args.literal[0][0], false)
1813 })
1814
1815 test('endArray event occurred once', () => {
1816 assert.strictEqual(log.counts.endArray, 1)
1817 })
1818
1819 test('end event occurred once', () => {
1820 assert.strictEqual(log.counts.end, 1)
1821 })
1822
1823 test('error event did not occur', () => {
1824 assert.strictEqual(log.counts.error, 0)
1825 })
1826
1827 test('dataError event did not occur', () => {
1828 assert.strictEqual(log.counts.dataError, 0)
1829 })
1830 })
1831
1832 suite('two literals inside array:', () => {
1833 let stream, emitter
1834
1835 setup(done => {
1836 stream = new Readable()
1837 stream._read = () => {}
1838
1839 emitter = walk(stream)
1840
1841 stream.push('[true,null]')
1842 stream.push(null)
1843
1844 Object.entries(events).forEach(([ key, value ]) => {
1845 emitter.on(value, spooks.fn({
1846 name: key,
1847 log: log
1848 }))
1849 })
1850
1851 emitter.on(events.end, done)
1852 })
1853
1854 test('array event occurred once', () => {
1855 assert.strictEqual(log.counts.array, 1)
1856 })
1857
1858 test('literal event occurred twice', () => {
1859 assert.strictEqual(log.counts.literal, 2)
1860 })
1861
1862 test('literal event was dispatched correctly first time', () => {
1863 assert.strictEqual(log.args.literal[0][0], true)
1864 })
1865
1866 test('literal event was dispatched correctly second time', () => {
1867 assert.strictEqual(log.args.literal[1][0], null)
1868 })
1869
1870 test('endArray event occurred once', () => {
1871 assert.strictEqual(log.counts.endArray, 1)
1872 })
1873
1874 test('end event occurred once', () => {
1875 assert.strictEqual(log.counts.end, 1)
1876 })
1877
1878 test('error event did not occur', () => {
1879 assert.strictEqual(log.counts.error, 0)
1880 })
1881
1882 test('dataError event did not occur', () => {
1883 assert.strictEqual(log.counts.dataError, 0)
1884 })
1885 })
1886
1887 suite('two literals inside array with whitespace:', () => {
1888 let stream, emitter
1889
1890 setup(done => {
1891 stream = new Readable()
1892 stream._read = () => {}
1893
1894 emitter = walk(stream)
1895
1896 stream.push('[ null , false ]')
1897 stream.push(null)
1898
1899 Object.entries(events).forEach(([ key, value ]) => {
1900 emitter.on(value, spooks.fn({
1901 name: key,
1902 log: log
1903 }))
1904 })
1905
1906 emitter.on(events.end, done)
1907 })
1908
1909 test('array event occurred once', () => {
1910 assert.strictEqual(log.counts.array, 1)
1911 })
1912
1913 test('literal event occurred twice', () => {
1914 assert.strictEqual(log.counts.literal, 2)
1915 })
1916
1917 test('literal event was dispatched correctly first time', () => {
1918 assert.strictEqual(log.args.literal[0][0], null)
1919 })
1920
1921 test('literal event was dispatched correctly second time', () => {
1922 assert.strictEqual(log.args.literal[1][0], false)
1923 })
1924
1925 test('endArray event occurred once', () => {
1926 assert.strictEqual(log.counts.endArray, 1)
1927 })
1928
1929 test('end event occurred once', () => {
1930 assert.strictEqual(log.counts.end, 1)
1931 })
1932
1933 test('error event did not occur', () => {
1934 assert.strictEqual(log.counts.error, 0)
1935 })
1936
1937 test('dataError event did not occur', () => {
1938 assert.strictEqual(log.counts.dataError, 0)
1939 })
1940 })
1941
1942 suite('number inside array:', () => {
1943 let stream, emitter
1944
1945 setup(done => {
1946 stream = new Readable()
1947 stream._read = () => {}
1948
1949 emitter = walk(stream)
1950
1951 stream.push('[0]')
1952 stream.push(null)
1953
1954 Object.entries(events).forEach(([ key, value ]) => {
1955 emitter.on(value, spooks.fn({
1956 name: key,
1957 log: log
1958 }))
1959 })
1960
1961 emitter.on(events.end, done)
1962 })
1963
1964 test('array event occurred once', () => {
1965 assert.strictEqual(log.counts.array, 1)
1966 })
1967
1968 test('number event occurred once', () => {
1969 assert.strictEqual(log.counts.number, 1)
1970 })
1971
1972 test('number event was dispatched correctly', () => {
1973 assert.strictEqual(log.args.number[0][0], 0)
1974 })
1975
1976 test('endArray event occurred once', () => {
1977 assert.strictEqual(log.counts.endArray, 1)
1978 })
1979
1980 test('end event occurred once', () => {
1981 assert.strictEqual(log.counts.end, 1)
1982 })
1983
1984 test('error event did not occur', () => {
1985 assert.strictEqual(log.counts.error, 0)
1986 })
1987
1988 test('dataError event did not occur', () => {
1989 assert.strictEqual(log.counts.dataError, 0)
1990 })
1991 })
1992
1993 suite('two numbers inside array:', () => {
1994 let stream, emitter
1995
1996 setup(done => {
1997 stream = new Readable()
1998 stream._read = () => {}
1999
2000 emitter = walk(stream)
2001
2002 stream.push('[1,2]')
2003 stream.push(null)
2004
2005 Object.entries(events).forEach(([ key, value ]) => {
2006 emitter.on(value, spooks.fn({
2007 name: key,
2008 log: log
2009 }))
2010 })
2011
2012 emitter.on(events.end, done)
2013 })
2014
2015 test('array event occurred once', () => {
2016 assert.strictEqual(log.counts.array, 1)
2017 })
2018
2019 test('number event occurred twice', () => {
2020 assert.strictEqual(log.counts.number, 2)
2021 })
2022
2023 test('number event was dispatched correctly first time', () => {
2024 assert.strictEqual(log.args.number[0][0], 1)
2025 })
2026
2027 test('number event was dispatched correctly second time', () => {
2028 assert.strictEqual(log.args.number[1][0], 2)
2029 })
2030
2031 test('endArray event occurred once', () => {
2032 assert.strictEqual(log.counts.endArray, 1)
2033 })
2034
2035 test('end event occurred once', () => {
2036 assert.strictEqual(log.counts.end, 1)
2037 })
2038
2039 test('error event did not occur', () => {
2040 assert.strictEqual(log.counts.error, 0)
2041 })
2042
2043 test('dataError event did not occur', () => {
2044 assert.strictEqual(log.counts.dataError, 0)
2045 })
2046 })
2047
2048 suite('two numbers inside array with whitespace:', () => {
2049 let stream, emitter
2050
2051 setup(done => {
2052 stream = new Readable()
2053 stream._read = () => {}
2054
2055 emitter = walk(stream)
2056
2057 stream.push('[ 1977 , -1977 ]')
2058 stream.push(null)
2059
2060 Object.entries(events).forEach(([ key, value ]) => {
2061 emitter.on(value, spooks.fn({
2062 name: key,
2063 log: log
2064 }))
2065 })
2066
2067 emitter.on(events.end, done)
2068 })
2069
2070 test('array event occurred once', () => {
2071 assert.strictEqual(log.counts.array, 1)
2072 })
2073
2074 test('number event occurred twice', () => {
2075 assert.strictEqual(log.counts.number, 2)
2076 })
2077
2078 test('number event was dispatched correctly first time', () => {
2079 assert.strictEqual(log.args.number[0][0], 1977)
2080 })
2081
2082 test('number event was dispatched correctly second time', () => {
2083 assert.strictEqual(log.args.number[1][0], -1977)
2084 })
2085
2086 test('endArray event occurred once', () => {
2087 assert.strictEqual(log.counts.endArray, 1)
2088 })
2089
2090 test('end event occurred once', () => {
2091 assert.strictEqual(log.counts.end, 1)
2092 })
2093
2094 test('error event did not occur', () => {
2095 assert.strictEqual(log.counts.error, 0)
2096 })
2097
2098 test('dataError event did not occur', () => {
2099 assert.strictEqual(log.counts.dataError, 0)
2100 })
2101 })
2102
2103 suite('object inside object:', () => {
2104 let stream, emitter
2105
2106 setup(done => {
2107 stream = new Readable()
2108 stream._read = () => {}
2109
2110 emitter = walk(stream)
2111
2112 stream.push('{"foo":{}}')
2113 stream.push(null)
2114
2115 Object.entries(events).forEach(([ key, value ]) => {
2116 emitter.on(value, spooks.fn({
2117 name: key,
2118 log: log
2119 }))
2120 })
2121
2122 emitter.on(events.end, done)
2123 })
2124
2125 test('object event occurred twice', () => {
2126 assert.strictEqual(log.counts.object, 2)
2127 })
2128
2129 test('property event occurred once', () => {
2130 assert.strictEqual(log.counts.property, 1)
2131 })
2132
2133 test('property event was dispatched correctly', () => {
2134 assert.lengthOf(log.args.property[0], 1)
2135 assert.strictEqual(log.args.property[0][0], 'foo')
2136 })
2137
2138 test('endObject event occurred twice', () => {
2139 assert.strictEqual(log.counts.endObject, 2)
2140 })
2141
2142 test('end event occurred once', () => {
2143 assert.strictEqual(log.counts.end, 1)
2144 })
2145
2146 test('error event did not occur', () => {
2147 assert.strictEqual(log.counts.error, 0)
2148 })
2149
2150 test('dataError event did not occur', () => {
2151 assert.strictEqual(log.counts.dataError, 0)
2152 })
2153 })
2154
2155 suite('array and object inside object:', () => {
2156 let stream, emitter
2157
2158 setup(done => {
2159 stream = new Readable()
2160 stream._read = () => {}
2161
2162 emitter = walk(stream)
2163
2164 stream.push('{"wibble wobble":[],"jelly on the plate":{}}')
2165 stream.push(null)
2166
2167 Object.entries(events).forEach(([ key, value ]) => {
2168 emitter.on(value, spooks.fn({
2169 name: key,
2170 log: log
2171 }))
2172 })
2173
2174 emitter.on(events.end, done)
2175 })
2176
2177 test('object event occurred twice', () => {
2178 assert.strictEqual(log.counts.object, 2)
2179 })
2180
2181 test('property event occurred twice', () => {
2182 assert.strictEqual(log.counts.property, 2)
2183 })
2184
2185 test('property event was dispatched correctly first time', () => {
2186 assert.strictEqual(log.args.property[0][0], 'wibble wobble')
2187 })
2188
2189 test('property event was dispatched correctly second time', () => {
2190 assert.strictEqual(log.args.property[1][0], 'jelly on the plate')
2191 })
2192
2193 test('array event occurred once', () => {
2194 assert.strictEqual(log.counts.array, 1)
2195 })
2196
2197 test('endArray event occurred once', () => {
2198 assert.strictEqual(log.counts.endArray, 1)
2199 })
2200
2201 test('endObject event occurred twice', () => {
2202 assert.strictEqual(log.counts.endObject, 2)
2203 })
2204
2205 test('end event occurred once', () => {
2206 assert.strictEqual(log.counts.end, 1)
2207 })
2208
2209 test('error event did not occur', () => {
2210 assert.strictEqual(log.counts.error, 0)
2211 })
2212
2213 test('dataError event did not occur', () => {
2214 assert.strictEqual(log.counts.dataError, 0)
2215 })
2216 })
2217
2218 suite('string, literal and number inside object with whitespace:', () => {
2219 let stream, emitter
2220
2221 setup(done => {
2222 stream = new Readable()
2223 stream._read = () => {}
2224
2225 emitter = walk(stream)
2226
2227 stream.push(' { "foo" : "bar" ,\t"baz"\t:\tnull\t,\r\n"qux"\r\n:\r\n3.14159265359\r\n} ')
2228 stream.push(null)
2229
2230 Object.entries(events).forEach(([ key, value ]) => {
2231 emitter.on(value, spooks.fn({
2232 name: key,
2233 log: log
2234 }))
2235 })
2236
2237 emitter.on(events.end, done)
2238 })
2239
2240 test('object event occurred once', () => {
2241 assert.strictEqual(log.counts.object, 1)
2242 })
2243
2244 test('property event occurred three times', () => {
2245 assert.strictEqual(log.counts.property, 3)
2246 })
2247
2248 test('property event was dispatched correctly first time', () => {
2249 assert.strictEqual(log.args.property[0][0], 'foo')
2250 })
2251
2252 test('property event was dispatched correctly second time', () => {
2253 assert.strictEqual(log.args.property[1][0], 'baz')
2254 })
2255
2256 test('property event was dispatched correctly third time', () => {
2257 assert.strictEqual(log.args.property[2][0], 'qux')
2258 })
2259
2260 test('string event occurred once', () => {
2261 assert.strictEqual(log.counts.string, 1)
2262 })
2263
2264 test('string event was dispatched correctly', () => {
2265 assert.strictEqual(log.args.string[0][0], 'bar')
2266 })
2267
2268 test('literal event occurred once', () => {
2269 assert.strictEqual(log.counts.literal, 1)
2270 })
2271
2272 test('literal event was dispatched correctly', () => {
2273 assert.isNull(log.args.literal[0][0])
2274 })
2275
2276 test('number event occurred once', () => {
2277 assert.strictEqual(log.counts.number, 1)
2278 })
2279
2280 test('number event was dispatched correctly', () => {
2281 assert.strictEqual(log.args.number[0][0], 3.14159265359)
2282 })
2283
2284 test('endObject event occurred once', () => {
2285 assert.strictEqual(log.counts.endObject, 1)
2286 })
2287
2288 test('end event occurred once', () => {
2289 assert.strictEqual(log.counts.end, 1)
2290 })
2291
2292 test('error event did not occur', () => {
2293 assert.strictEqual(log.counts.error, 0)
2294 })
2295
2296 test('dataError event did not occur', () => {
2297 assert.strictEqual(log.counts.dataError, 0)
2298 })
2299 })
2300
2301 suite('two objects inside object without comma:', () => {
2302 let stream, emitter
2303
2304 setup(done => {
2305 stream = new Readable()
2306 stream._read = () => {}
2307
2308 emitter = walk(stream)
2309
2310 stream.push('{"foo":{}"bar":{}}')
2311 stream.push(null)
2312
2313 Object.entries(events).forEach(([ key, value ]) => {
2314 emitter.on(value, spooks.fn({
2315 name: key,
2316 log: log
2317 }))
2318 })
2319
2320 emitter.on(events.end, done)
2321 })
2322
2323 test('object event occurred three times', () => {
2324 assert.strictEqual(log.counts.object, 3)
2325 })
2326
2327 test('property event occurred twice', () => {
2328 assert.strictEqual(log.counts.property, 2)
2329 })
2330
2331 test('property event was dispatched correctly first time', () => {
2332 assert.strictEqual(log.args.property[0][0], 'foo')
2333 })
2334
2335 test('property event was dispatched correctly second time', () => {
2336 assert.strictEqual(log.args.property[1][0], 'bar')
2337 })
2338
2339 test('dataError event occurred once', () => {
2340 assert.strictEqual(log.counts.dataError, 1)
2341 })
2342
2343 test('dataError event was dispatched correctly', () => {
2344 assert.strictEqual(log.args.dataError[0][0].actual, '"')
2345 assert.strictEqual(log.args.dataError[0][0].expected, ',')
2346 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
2347 assert.strictEqual(log.args.dataError[0][0].columnNumber, 10)
2348 })
2349
2350 test('endObject event occurred three times', () => {
2351 assert.strictEqual(log.counts.endObject, 3)
2352 })
2353
2354 test('end event occurred once', () => {
2355 assert.strictEqual(log.counts.end, 1)
2356 })
2357 })
2358
2359 suite('unquoted property:', () => {
2360 let stream, emitter
2361
2362 setup(done => {
2363 stream = new Readable()
2364 stream._read = () => {}
2365
2366 emitter = walk(stream)
2367
2368 stream.push('{foo:{}}')
2369 stream.push(null)
2370
2371 Object.entries(events).forEach(([ key, value ]) => {
2372 emitter.on(value, spooks.fn({
2373 name: key,
2374 log: log
2375 }))
2376 })
2377
2378 emitter.on(events.end, done)
2379 })
2380
2381 test('object event occurred once', () => {
2382 assert.strictEqual(log.counts.object, 1)
2383 })
2384
2385 test('dataError event occurred once', () => {
2386 assert.strictEqual(log.counts.dataError, 3)
2387 })
2388
2389 test('dataError event was dispatched correctly first time', () => {
2390 assert.strictEqual(log.args.dataError[0][0].actual, 'f')
2391 assert.strictEqual(log.args.dataError[0][0].expected, '"')
2392 assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
2393 assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
2394 })
2395
2396 test('dataError event was dispatched correctly second time', () => {
2397 assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
2398 assert.strictEqual(log.args.dataError[1][0].expected, '"')
2399 assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
2400 assert.strictEqual(log.args.dataError[1][0].columnNumber, 9)
2401 })
2402
2403 test('dataError event was dispatched correctly third time', () => {
2404 assert.strictEqual(log.args.dataError[2][0].actual, 'EOF')
2405 assert.strictEqual(log.args.dataError[2][0].expected, '}')
2406 assert.strictEqual(log.args.dataError[2][0].lineNumber, 1)
2407 assert.strictEqual(log.args.dataError[2][0].columnNumber, 9)
2408 })
2409
2410 test('end event occurred once', () => {
2411 assert.strictEqual(log.counts.end, 1)
2412 })
2413 })
2414
2415 suite('duplicate property:', () => {
2416 let stream, emitter
2417
2418 setup(done => {
2419 stream = new Readable()
2420 stream._read = () => {}
2421
2422 emitter = walk(stream)
2423
2424 // NOTE: RFC 7159 is wishy washy on the subject of duplicates:
2425 //
2426 // "The names within an object SHOULD be unique
2427 //
2428 // ...
2429 //
2430 // An object whose names are all unique is interoperable
2431 // in the sense that all software implementations receiving
2432 // that object will agree on the name/value mappings. When
2433 // the names within an object are not unique, the behavior
2434 // of software that receives such an object is unpredictable.
2435 // Many implementations report the last name/value pair only.
2436 // Other implementations report an error or fail to parse the
2437 // object, and some implementations report all of the name/value
2438 // pairs, including duplicates."
2439 //
2440 // https://tools.ietf.org/html/rfc7159#section-4
2441 stream.push('{"foo":{},"foo":{}}')
2442 stream.push(null)
2443
2444 Object.entries(events).forEach(([ key, value ]) => {
2445 emitter.on(value, spooks.fn({
2446 name: key,
2447 log: log
2448 }))
2449 })
2450
2451 emitter.on(events.end, done)
2452 })
2453
2454 test('object event occurred three times', () => {
2455 assert.strictEqual(log.counts.object, 3)
2456 })
2457
2458 test('property event occurred twice', () => {
2459 assert.strictEqual(log.counts.property, 2)
2460 })
2461
2462 test('property event was dispatched correctly first time', () => {
2463 assert.strictEqual(log.args.property[0][0], 'foo')
2464 })
2465
2466 test('property event was dispatched correctly second time', () => {
2467 assert.strictEqual(log.args.property[1][0], 'foo')
2468 })
2469
2470 test('endObject event occurred three times', () => {
2471 assert.strictEqual(log.counts.endObject, 3)
2472 })
2473
2474 test('end event occurred once', () => {
2475 assert.strictEqual(log.counts.end, 1)
2476 })
2477
2478 test('error event did not occur', () => {
2479 assert.strictEqual(log.counts.error, 0)
2480 })
2481
2482 test('dataError event did not occur', () => {
2483 assert.strictEqual(log.counts.dataError, 0)
2484 })
2485 })
2486
2487 suite('empty array containing whitespace:', () => {
2488 let stream, emitter
2489
2490 setup(done => {
2491 stream = new Readable()
2492 stream._read = () => {}
2493
2494 emitter = walk(stream)
2495
2496 stream.push('[ ]')
2497 stream.push(null)
2498
2499 Object.entries(events).forEach(([ key, value ]) => {
2500 emitter.on(value, spooks.fn({
2501 name: key,
2502 log: log
2503 }))
2504 })
2505
2506 emitter.on(events.end, done)
2507 })
2508
2509 test('array event occurred once', () => {
2510 assert.strictEqual(log.counts.array, 1)
2511 })
2512
2513 test('endArray event occurred once', () => {
2514 assert.strictEqual(log.counts.endArray, 1)
2515 })
2516
2517 test('end event occurred once', () => {
2518 assert.strictEqual(log.counts.end, 1)
2519 })
2520
2521 test('error event did not occur', () => {
2522 assert.strictEqual(log.counts.error, 0)
2523 })
2524
2525 test('dataError event did not occur', () => {
2526 assert.strictEqual(log.counts.dataError, 0)
2527 })
2528 })
2529
2530 suite('chunked empty array:', () => {
2531 let stream, emitter
2532
2533 setup(done => {
2534 stream = new Readable()
2535 stream._read = () => {}
2536
2537 emitter = walk(stream)
2538
2539 stream.push('[')
2540
2541 Object.entries(events).forEach(([ key, value ]) => {
2542 emitter.on(value, spooks.fn({
2543 name: key,
2544 log: log
2545 }))
2546 })
2547
2548 emitter.on(events.end, done)
2549 emitter.on(events.array, stream.push.bind(stream, ']'))
2550 emitter.on(events.endArray, stream.push.bind(stream, null))
2551 })
2552
2553 test('array event occurred once', () => {
2554 assert.strictEqual(log.counts.array, 1)
2555 })
2556
2557 test('endArray event occurred once', () => {
2558 assert.strictEqual(log.counts.endArray, 1)
2559 })
2560
2561 test('end event occurred once', () => {
2562 assert.strictEqual(log.counts.end, 1)
2563 })
2564
2565 test('error event did not occur', () => {
2566 assert.strictEqual(log.counts.error, 0)
2567 })
2568
2569 test('dataError event did not occur', () => {
2570 assert.strictEqual(log.counts.dataError, 0)
2571 })
2572 })
2573
2574 suite('chunked empty object with whitespace:', () => {
2575 let stream, emitter
2576
2577 setup(done => {
2578 stream = new Readable()
2579 stream._read = () => {}
2580
2581 emitter = walk(stream)
2582
2583 stream.push(' {')
2584
2585 Object.entries(events).forEach(([ key, value ]) => {
2586 emitter.on(value, spooks.fn({
2587 name: key,
2588 log: log
2589 }))
2590 })
2591
2592 emitter.on(events.end, done)
2593
2594 emitter.on(events.object, () => {
2595 setTimeout(stream.push.bind(stream, ' }'), 20)
2596 })
2597
2598 emitter.on(events.endObject, () => {
2599 setTimeout(stream.push.bind(stream, null), 20)
2600 })
2601 })
2602
2603 test('object event occurred once', () => {
2604 assert.strictEqual(log.counts.object, 1)
2605 })
2606
2607 test('endObject event occurred once', () => {
2608 assert.strictEqual(log.counts.endObject, 1)
2609 })
2610
2611 test('end event occurred once', () => {
2612 assert.strictEqual(log.counts.end, 1)
2613 })
2614
2615 test('error event did not occur', () => {
2616 assert.strictEqual(log.counts.error, 0)
2617 })
2618
2619 test('dataError event did not occur', () => {
2620 assert.strictEqual(log.counts.dataError, 0)
2621 })
2622 })
2623
2624 suite('chunked string:', () => {
2625 let stream, emitter
2626
2627 setup(done => {
2628 stream = new Readable()
2629 stream._read = () => {}
2630
2631 emitter = walk(stream)
2632
2633 stream.push('"')
2634
2635 Object.entries(events).forEach(([ key, value ]) => {
2636 emitter.on(value, spooks.fn({
2637 name: key,
2638 log: log
2639 }))
2640 })
2641
2642 emitter.on(events.end, done)
2643
2644 emitter.on(events.string, () => {
2645 setTimeout(stream.push.bind(stream, null), 20)
2646 })
2647
2648 setTimeout(stream.push.bind(stream, '\\'), 20)
2649 setTimeout(stream.push.bind(stream, 't\\u'), 40)
2650 setTimeout(stream.push.bind(stream, '00'), 60)
2651 setTimeout(stream.push.bind(stream, 'a0'), 80)
2652 setTimeout(stream.push.bind(stream, '"'), 100)
2653 })
2654
2655 test('string event occurred once', () => {
2656 assert.strictEqual(log.counts.string, 1)
2657 })
2658
2659 test('string event was dispatched correctly', () => {
2660 assert.strictEqual(log.args.string[0][0], '\t\u00a0')
2661 })
2662
2663 test('end event occurred once', () => {
2664 assert.strictEqual(log.counts.end, 1)
2665 })
2666
2667 test('error event did not occur', () => {
2668 assert.strictEqual(log.counts.error, 0)
2669 })
2670
2671 test('dataError event did not occur', () => {
2672 assert.strictEqual(log.counts.dataError, 0)
2673 })
2674 })
2675
2676 suite('chunked number:', () => {
2677 let stream, emitter
2678
2679 setup(done => {
2680 stream = new Readable()
2681 stream._read = () => {}
2682
2683 emitter = walk(stream)
2684
2685 stream.push('-')
2686
2687 Object.entries(events).forEach(([ key, value ]) => {
2688 emitter.on(value, spooks.fn({
2689 name: key,
2690 log: log
2691 }))
2692 })
2693
2694 emitter.on(events.end, done)
2695
2696 setTimeout(stream.push.bind(stream, '3'), 20)
2697 setTimeout(stream.push.bind(stream, '.'), 40)
2698 setTimeout(stream.push.bind(stream, '14159'), 60)
2699 setTimeout(stream.push.bind(stream, '265359'), 80)
2700 setTimeout(stream.push.bind(stream, 'e'), 100)
2701 setTimeout(stream.push.bind(stream, '-'), 120)
2702 setTimeout(stream.push.bind(stream, '7'), 140)
2703 setTimeout(stream.push.bind(stream, null), 160)
2704 })
2705
2706 test('number event occurred once', () => {
2707 assert.strictEqual(log.counts.number, 1)
2708 })
2709
2710 test('number event was dispatched correctly', () => {
2711 assert.strictEqual(log.args.number[0][0], -3.14159265359e-7)
2712 })
2713
2714 test('end event occurred once', () => {
2715 assert.strictEqual(log.counts.end, 1)
2716 })
2717
2718 test('error event did not occur', () => {
2719 assert.strictEqual(log.counts.error, 0)
2720 })
2721
2722 test('dataError event did not occur', () => {
2723 assert.strictEqual(log.counts.dataError, 0)
2724 })
2725 })
2726
2727 suite('chunked literal:', () => {
2728 let stream, emitter
2729
2730 setup(done => {
2731 stream = new Readable()
2732 stream._read = () => {}
2733
2734 emitter = walk(stream)
2735
2736 stream.push('n')
2737
2738 Object.entries(events).forEach(([ key, value ]) => {
2739 emitter.on(value, spooks.fn({
2740 name: key,
2741 log: log
2742 }))
2743 })
2744
2745 emitter.on(events.end, done)
2746
2747 setTimeout(stream.push.bind(stream, 'u'), 20)
2748 setTimeout(stream.push.bind(stream, 'l'), 40)
2749 setTimeout(stream.push.bind(stream, 'l'), 60)
2750 setTimeout(stream.push.bind(stream, null), 80)
2751 })
2752
2753 test('literal event occurred once', () => {
2754 assert.strictEqual(log.counts.literal, 1)
2755 })
2756
2757 test('literal event was dispatched correctly', () => {
2758 assert.strictEqual(log.args.literal[0][0], null)
2759 })
2760
2761 test('end event occurred once', () => {
2762 assert.strictEqual(log.counts.end, 1)
2763 })
2764
2765 test('error event did not occur', () => {
2766 assert.strictEqual(log.counts.error, 0)
2767 })
2768
2769 test('dataError event did not occur', () => {
2770 assert.strictEqual(log.counts.dataError, 0)
2771 })
2772 })
2773
2774 suite('populated array with discard=1:', () => {
2775 let stream, emitter
2776
2777 setup(done => {
2778 stream = new Readable()
2779 stream._read = () => {}
2780
2781 emitter = walk(stream, { discard: 1 })
2782
2783 stream.push(' ')
2784
2785 Object.entries(events).forEach(([ key, value ]) => {
2786 emitter.on(value, spooks.fn({
2787 name: key,
2788 log: log
2789 }))
2790 })
2791
2792 emitter.on(events.end, done)
2793
2794 emitter.on(events.array, () => {
2795 stream.push(' ""')
2796 })
2797
2798 emitter.on(events.string, () => {
2799 stream.push(' ]')
2800 })
2801
2802 emitter.on(events.endArray, () => {
2803 stream.push(null)
2804 })
2805
2806 setImmediate(stream.push.bind(stream, '['))
2807 })
2808
2809 test('array event occurred once', () => {
2810 assert.strictEqual(log.counts.array, 1)
2811 })
2812
2813 test('string event was dispatched correctly', () => {
2814 assert.strictEqual(log.args.string[0][0], "")
2815 })
2816
2817 test('endArray event occurred once', () => {
2818 assert.strictEqual(log.counts.endArray, 1)
2819 })
2820
2821 test('end event occurred once', () => {
2822 assert.strictEqual(log.counts.end, 1)
2823 })
2824
2825 test('string event occurred once', () => {
2826 assert.strictEqual(log.counts.string, 1)
2827 })
2828
2829 test('error event did not occur', () => {
2830 assert.strictEqual(log.counts.error, 0)
2831 })
2832
2833 test('dataError event did not occur', () => {
2834 assert.strictEqual(log.counts.dataError, 0)
2835 })
2836 })
2837
2838 suite('throw errors from event handlers:', () => {
2839 let stream, emitter
2840
2841 setup(done => {
2842 stream = new Readable()
2843 stream._read = () => {}
2844
2845 emitter = walk(stream)
2846
2847 stream.push('[null,false,true,0,"",{"foo":"bar"}]')
2848 stream.push(null)
2849
2850 Object.entries(events).forEach(([ key, value ]) => {
2851 emitter.on(value, spooks.fn({
2852 name: key,
2853 log: log
2854 }))
2855 if (value !== events.end) {
2856 emitter.on(value, () => { throw 0 })
2857 }
2858 })
2859
2860 emitter.on(events.end, done)
2861 })
2862
2863 test('array event occurred once', () => {
2864 assert.strictEqual(log.counts.array, 1)
2865 })
2866
2867 test('endArray event occurred once', () => {
2868 assert.strictEqual(log.counts.endArray, 1)
2869 })
2870
2871 test('literal event occurred three times', () => {
2872 assert.strictEqual(log.counts.literal, 3)
2873 })
2874
2875 test('number event occurred once', () => {
2876 assert.strictEqual(log.counts.number, 1)
2877 })
2878
2879 test('string event occurred twice', () => {
2880 assert.strictEqual(log.counts.string, 2)
2881 })
2882
2883 test('property event occurred once', () => {
2884 assert.strictEqual(log.counts.property, 1)
2885 })
2886
2887 test('object event occurred once', () => {
2888 assert.strictEqual(log.counts.object, 1)
2889 })
2890
2891 test('endObject event occurred once', () => {
2892 assert.strictEqual(log.counts.endObject, 1)
2893 })
2894
2895 test('error event occurred eleven times', () => {
2896 assert.strictEqual(log.counts.error, 11)
2897 })
2898
2899 test('end event occurred once', () => {
2900 assert.strictEqual(log.counts.end, 1)
2901 })
2902
2903 test('dataError event did not occur', () => {
2904 assert.strictEqual(log.counts.dataError, 0)
2905 })
2906 })
2907
2908 suite('error occurs on stream:', () => {
2909 let stream, emitter
2910
2911 setup(done => {
2912 stream = new Readable()
2913 stream._read = () => {}
2914
2915 emitter = walk(stream)
2916
2917 Object.entries(events).forEach(([ key, value ]) => {
2918 emitter.on(value, spooks.fn({
2919 name: key,
2920 log: log
2921 }))
2922 })
2923
2924 stream.emit('error', new Error('wibble'))
2925 stream.push(null)
2926
2927 emitter.on(events.end, done)
2928 })
2929
2930 test('error event occurred once', () => {
2931 assert.strictEqual(log.counts.error, 1)
2932 })
2933
2934 test('error event was dispatched correctly', () => {
2935 assert.strictEqual(log.args.error[0][0].message, 'wibble')
2936 assert.isUndefined(log.args.error[0][0].actual)
2937 assert.isUndefined(log.args.error[0][0].expected)
2938 assert.isUndefined(log.args.error[0][0].lineNumber)
2939 assert.isUndefined(log.args.error[0][0].columnNumber)
2940 })
2941
2942 test('end event occurred once', () => {
2943 assert.strictEqual(log.counts.end, 1)
2944 })
2945
2946 test('dataError event did not occur', () => {
2947 assert.strictEqual(log.counts.dataError, 0)
2948 })
2949 })
2950
2951 suite('two values separated by newline:', () => {
2952 let stream, emitter
2953
2954 setup(done => {
2955 stream = new Readable()
2956 stream._read = () => {}
2957
2958 emitter = walk(stream)
2959
2960 stream.push('[]\n"foo"')
2961 stream.push(null)
2962
2963 Object.entries(events).forEach(([ key, value ]) => {
2964 emitter.on(value, spooks.fn({
2965 name: key,
2966 log: log
2967 }))
2968 })
2969
2970 emitter.on(events.end, done)
2971 })
2972
2973 test('array event occurred once', () => {
2974 assert.strictEqual(log.counts.array, 1)
2975 })
2976
2977 test('endArray event occurred once', () => {
2978 assert.strictEqual(log.counts.endArray, 1)
2979 })
2980
2981 test('string event occurred once', () => {
2982 assert.strictEqual(log.counts.string, 1)
2983 })
2984
2985 test('dataError event occurred once', () => {
2986 assert.strictEqual(log.counts.dataError, 1)
2987 })
2988
2989 test('end event occurred once', () => {
2990 assert.strictEqual(log.counts.end, 1)
2991 })
2992
2993 test('endLine event did not occur', () => {
2994 assert.strictEqual(log.counts.endLine, 0)
2995 })
2996 })
2997
2998 suite('two values separated by newline, ndjson=true:', () => {
2999 let stream, emitter
3000
3001 setup(done => {
3002 stream = new Readable()
3003 stream._read = () => {}
3004
3005 emitter = walk(stream, { ndjson: true })
3006
3007 stream.push('[]\n"foo"')
3008 stream.push(null)
3009
3010 Object.entries(events).forEach(([ key, value ]) => {
3011 emitter.on(value, spooks.fn({
3012 name: key,
3013 log: log
3014 }))
3015 })
3016
3017 emitter.on(events.end, done)
3018 })
3019
3020 test('array event occurred once', () => {
3021 assert.strictEqual(log.counts.array, 1)
3022 })
3023
3024 test('endArray event occurred once', () => {
3025 assert.strictEqual(log.counts.endArray, 1)
3026 })
3027
3028 test('string event occurred once', () => {
3029 assert.strictEqual(log.counts.string, 1)
3030 })
3031
3032 test('endLine event occurred once', () => {
3033 assert.strictEqual(log.counts.endLine, 1)
3034 })
3035
3036 test('end event occurred once', () => {
3037 assert.strictEqual(log.counts.end, 1)
3038 })
3039
3040 test('error event did not occur', () => {
3041 assert.strictEqual(log.counts.error, 0)
3042 })
3043
3044 test('dataError event did not occur', () => {
3045 assert.strictEqual(log.counts.dataError, 0)
3046 })
3047 })
3048
3049 suite('two values separated by newline, ndjson=true, with embedded newlines in a value:', () => {
3050 let stream, emitter
3051
3052 setup(done => {
3053 stream = new Readable()
3054 stream._read = () => {}
3055
3056 emitter = walk(stream, { ndjson: true })
3057
3058 stream.push('[\n\n\n"foo"\n\n,\n"bar"]\n"baz"')
3059 stream.push(null)
3060
3061 Object.entries(events).forEach(([ key, value ]) => {
3062 emitter.on(value, spooks.fn({
3063 name: key,
3064 log: log
3065 }))
3066 })
3067
3068 emitter.on(events.end, done)
3069 })
3070
3071 test('array event occurred once', () => {
3072 assert.strictEqual(log.counts.array, 1)
3073 })
3074
3075 test('endArray event occurred once', () => {
3076 assert.strictEqual(log.counts.endArray, 1)
3077 })
3078
3079 test('string event occurred three times', () => {
3080 assert.strictEqual(log.counts.string, 3)
3081 })
3082
3083 test('endLine event occurred once', () => {
3084 assert.strictEqual(log.counts.endLine, 1)
3085 })
3086
3087 test('end event occurred once', () => {
3088 assert.strictEqual(log.counts.end, 1)
3089 })
3090
3091 test('error event did not occur', () => {
3092 assert.strictEqual(log.counts.error, 0)
3093 })
3094
3095 test('dataError event did not occur', () => {
3096 assert.strictEqual(log.counts.dataError, 0)
3097 })
3098 })
3099
3100 suite('two values not separated by newline, ndjson=true:', () => {
3101 let stream, emitter
3102
3103 setup(done => {
3104 stream = new Readable()
3105 stream._read = () => {}
3106
3107 emitter = walk(stream, { ndjson: true })
3108
3109 stream.push('[]"foo"')
3110 stream.push(null)
3111
3112 Object.entries(events).forEach(([ key, value ]) => {
3113 emitter.on(value, spooks.fn({
3114 name: key,
3115 log: log
3116 }))
3117 })
3118
3119 emitter.on(events.end, done)
3120 })
3121
3122 test('array event occurred once', () => {
3123 assert.strictEqual(log.counts.array, 1)
3124 })
3125
3126 test('endArray event occurred once', () => {
3127 assert.strictEqual(log.counts.endArray, 1)
3128 })
3129
3130 test('end event occurred once', () => {
3131 assert.strictEqual(log.counts.end, 1)
3132 })
3133
3134 test('dataError event occurred five times', () => {
3135 assert.strictEqual(log.counts.dataError, 5)
3136 })
3137
3138 test('string event did not occurr', () => {
3139 assert.strictEqual(log.counts.string, 0)
3140 })
3141
3142 test('endLine event did not occur', () => {
3143 assert.strictEqual(log.counts.endLine, 0)
3144 })
3145 })
3146
3147 suite('two values separated by two newlines, ndjson=true:', () => {
3148 let stream, emitter
3149
3150 setup(done => {
3151 stream = new Readable()
3152 stream._read = () => {}
3153
3154 emitter = walk(stream, { ndjson: true })
3155
3156 stream.push('[]\r\n\r\n"foo"')
3157 stream.push(null)
3158
3159 Object.entries(events).forEach(([ key, value ]) => {
3160 emitter.on(value, spooks.fn({
3161 name: key,
3162 log: log
3163 }))
3164 })
3165
3166 emitter.on(events.end, done)
3167 })
3168
3169 test('array event occurred once', () => {
3170 assert.strictEqual(log.counts.array, 1)
3171 })
3172
3173 test('endArray event occurred once', () => {
3174 assert.strictEqual(log.counts.endArray, 1)
3175 })
3176
3177 test('string event occurred once', () => {
3178 assert.strictEqual(log.counts.string, 1)
3179 })
3180
3181 test('endLine event occurred twice', () => {
3182 assert.strictEqual(log.counts.endLine, 2)
3183 })
3184
3185 test('end event occurred once', () => {
3186 assert.strictEqual(log.counts.end, 1)
3187 })
3188
3189 test('error event did not occur', () => {
3190 assert.strictEqual(log.counts.error, 0)
3191 })
3192
3193 test('dataError event did not occur', () => {
3194 assert.strictEqual(log.counts.dataError, 0)
3195 })
3196 })
3197
3198 suite('chunked ndjson:', () => {
3199 let stream, emitter
3200
3201 setup(done => {
3202 stream = new Readable()
3203 stream._read = () => {}
3204
3205 emitter = walk(stream, { ndjson: true })
3206
3207 stream.push('[]')
3208
3209 Object.entries(events).forEach(([ key, value ]) => {
3210 emitter.on(value, spooks.fn({
3211 name: key,
3212 log: log
3213 }))
3214 })
3215
3216 emitter.on(events.end, done)
3217
3218 setTimeout(stream.push.bind(stream, ' '), 20)
3219 setTimeout(stream.push.bind(stream, '\n'), 40)
3220 setTimeout(stream.push.bind(stream, ' '), 60)
3221 setTimeout(stream.push.bind(stream, '"'), 80)
3222 setTimeout(stream.push.bind(stream, 'foo"'), 100)
3223 setTimeout(stream.push.bind(stream, null), 120)
3224 })
3225
3226 test('array event occurred once', () => {
3227 assert.strictEqual(log.counts.array, 1)
3228 })
3229
3230 test('endArray event occurred once', () => {
3231 assert.strictEqual(log.counts.endArray, 1)
3232 })
3233
3234 test('endLine event occurred once', () => {
3235 assert.strictEqual(log.counts.endLine, 1)
3236 })
3237
3238 test('string event occurred once', () => {
3239 assert.strictEqual(log.counts.string, 1)
3240 })
3241
3242 test('end event occurred once', () => {
3243 assert.strictEqual(log.counts.end, 1)
3244 })
3245
3246 test('error event did not occur', () => {
3247 assert.strictEqual(log.counts.error, 0)
3248 })
3249
3250 test('dataError event did not occur', () => {
3251 assert.strictEqual(log.counts.dataError, 0)
3252 })
3253 })
3254 })
3255})
Note: See TracBrowser for help on using the repository browser.