walk.js 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256
  1. 'use strict'
  2. const assert = require('chai').assert
  3. const spooks = require('spooks')
  4. const Readable = require('stream').Readable
  5. const events = require('../../src/events')
  6. const modulePath = '../../src/walk'
  7. suite('walk:', () => {
  8. let log
  9. setup(() => {
  10. log = {}
  11. })
  12. test('require does not throw', () => {
  13. assert.doesNotThrow(() => {
  14. require(modulePath)
  15. })
  16. })
  17. test('require returns function', () => {
  18. assert.isFunction(require(modulePath))
  19. })
  20. suite('require:', () => {
  21. let walk
  22. setup(() => {
  23. walk = require(modulePath)
  24. })
  25. test('walk throws without readable stream', () => {
  26. assert.throws(() => {
  27. walk({ on: () => {} })
  28. })
  29. })
  30. test('walk does not throw with readable stream', () => {
  31. assert.doesNotThrow(() => {
  32. walk(new Readable())
  33. })
  34. })
  35. test('walk returns emitter', () => {
  36. assert.instanceOf(walk(new Readable()), require('events').EventEmitter)
  37. })
  38. test('EventEmitter is decorated with pause method', () => {
  39. assert.isFunction(walk(new Readable()).pause)
  40. assert.lengthOf(walk(new Readable()).pause, 0)
  41. })
  42. test('pause method returns continue function', () => {
  43. assert.isFunction(walk(new Readable()).pause())
  44. assert.lengthOf(walk(new Readable()).pause(), 0)
  45. })
  46. suite('empty json:', () => {
  47. let stream, emitter
  48. setup(done => {
  49. stream = new Readable()
  50. stream._read = () => {}
  51. emitter = walk(stream)
  52. stream.push('')
  53. stream.push(null)
  54. Object.keys(events).forEach(key => {
  55. emitter.on(events[key], spooks.fn({
  56. name: key,
  57. log: log
  58. }))
  59. })
  60. emitter.on(events.end, done)
  61. })
  62. test('end event occurred once', () => {
  63. assert.strictEqual(log.counts.end, 1)
  64. })
  65. test('end event was dispatched correctly', () => {
  66. assert.lengthOf(log.args.end[0], 0)
  67. })
  68. test('array event did not occur', () => {
  69. assert.strictEqual(log.counts.array, 0)
  70. })
  71. test('object event did not occur', () => {
  72. assert.strictEqual(log.counts.object, 0)
  73. })
  74. test('property event did not occur', () => {
  75. assert.strictEqual(log.counts.property, 0)
  76. })
  77. test('string event did not occur', () => {
  78. assert.strictEqual(log.counts.string, 0)
  79. })
  80. test('number event did not occur', () => {
  81. assert.strictEqual(log.counts.number, 0)
  82. })
  83. test('literal event did not occur', () => {
  84. assert.strictEqual(log.counts.literal, 0)
  85. })
  86. test('endArray event did not occur', () => {
  87. assert.strictEqual(log.counts.endArray, 0)
  88. })
  89. test('endObject event did not occur', () => {
  90. assert.strictEqual(log.counts.endObject, 0)
  91. })
  92. test('error event did not occur', () => {
  93. assert.strictEqual(log.counts.error, 0)
  94. })
  95. test('dataError event did not occur', () => {
  96. assert.strictEqual(log.counts.dataError, 0)
  97. })
  98. test('endLine event did not occur', () => {
  99. assert.strictEqual(log.counts.endLine, 0)
  100. })
  101. test('endPrefix event did not occur', () => {
  102. assert.strictEqual(log.counts.endPrefix, 0)
  103. })
  104. })
  105. suite('empty array:', () => {
  106. let stream, emitter
  107. setup(done => {
  108. stream = new Readable()
  109. stream._read = () => {}
  110. emitter = walk(stream)
  111. stream.push('[]')
  112. stream.push(null)
  113. Object.keys(events).forEach(key => {
  114. emitter.on(events[key], spooks.fn({
  115. name: key,
  116. log: log
  117. }))
  118. })
  119. emitter.on(events.end, done)
  120. })
  121. test('array event occurred once', () => {
  122. assert.strictEqual(log.counts.array, 1)
  123. })
  124. test('array event was dispatched correctly', () => {
  125. assert.lengthOf(log.args.array[0], 0)
  126. })
  127. test('endArray event occurred once', () => {
  128. assert.strictEqual(log.counts.endArray, 1)
  129. })
  130. test('endArray event was dispatched correctly', () => {
  131. assert.lengthOf(log.args.endArray[0], 0)
  132. })
  133. test('end event occurred once', () => {
  134. assert.strictEqual(log.counts.end, 1)
  135. })
  136. test('object event did not occur', () => {
  137. assert.strictEqual(log.counts.object, 0)
  138. })
  139. test('property event did not occur', () => {
  140. assert.strictEqual(log.counts.property, 0)
  141. })
  142. test('string event did not occur', () => {
  143. assert.strictEqual(log.counts.string, 0)
  144. })
  145. test('number event did not occur', () => {
  146. assert.strictEqual(log.counts.number, 0)
  147. })
  148. test('literal event did not occur', () => {
  149. assert.strictEqual(log.counts.literal, 0)
  150. })
  151. test('endObject event did not occur', () => {
  152. assert.strictEqual(log.counts.endObject, 0)
  153. })
  154. test('error event did not occur', () => {
  155. assert.strictEqual(log.counts.error, 0)
  156. })
  157. test('dataError event did not occur', () => {
  158. assert.strictEqual(log.counts.dataError, 0)
  159. })
  160. test('endLine event did not occur', () => {
  161. assert.strictEqual(log.counts.endLine, 0)
  162. })
  163. test('endPrefix event did not occur', () => {
  164. assert.strictEqual(log.counts.endPrefix, 0)
  165. })
  166. })
  167. suite('empty object:', () => {
  168. let stream, emitter
  169. setup(done => {
  170. stream = new Readable()
  171. stream._read = () => {}
  172. emitter = walk(stream)
  173. stream.push('{}')
  174. stream.push(null)
  175. Object.keys(events).forEach(key => {
  176. emitter.on(events[key], spooks.fn({
  177. name: key,
  178. log: log
  179. }))
  180. })
  181. emitter.on(events.end, done)
  182. })
  183. test('object event occurred once', () => {
  184. assert.strictEqual(log.counts.object, 1)
  185. })
  186. test('object event was dispatched correctly', () => {
  187. assert.lengthOf(log.args.object[0], 0)
  188. })
  189. test('endObject event occurred once', () => {
  190. assert.strictEqual(log.counts.endObject, 1)
  191. })
  192. test('endObject event was dispatched correctly', () => {
  193. assert.lengthOf(log.args.endObject[0], 0)
  194. })
  195. test('end event occurred once', () => {
  196. assert.strictEqual(log.counts.end, 1)
  197. })
  198. test('array event did not occur', () => {
  199. assert.strictEqual(log.counts.array, 0)
  200. })
  201. test('property event did not occur', () => {
  202. assert.strictEqual(log.counts.property, 0)
  203. })
  204. test('string event did not occur', () => {
  205. assert.strictEqual(log.counts.string, 0)
  206. })
  207. test('number event did not occur', () => {
  208. assert.strictEqual(log.counts.number, 0)
  209. })
  210. test('literal event did not occur', () => {
  211. assert.strictEqual(log.counts.literal, 0)
  212. })
  213. test('endArray event did not occur', () => {
  214. assert.strictEqual(log.counts.endArray, 0)
  215. })
  216. test('error event did not occur', () => {
  217. assert.strictEqual(log.counts.error, 0)
  218. })
  219. test('dataError event did not occur', () => {
  220. assert.strictEqual(log.counts.dataError, 0)
  221. })
  222. test('endLine event did not occur', () => {
  223. assert.strictEqual(log.counts.endLine, 0)
  224. })
  225. test('endPrefix event did not occur', () => {
  226. assert.strictEqual(log.counts.endPrefix, 0)
  227. })
  228. })
  229. suite('string:', () => {
  230. let stream, emitter
  231. setup(done => {
  232. stream = new Readable()
  233. stream._read = () => {}
  234. emitter = walk(stream)
  235. stream.push('"\\"the quick brown fox\r\n\\tjumps\\u00a0over the lazy\\u1680dog\\""')
  236. stream.push(null)
  237. Object.keys(events).forEach(key => {
  238. emitter.on(events[key], spooks.fn({
  239. name: key,
  240. log: log
  241. }))
  242. })
  243. emitter.on(events.end, done)
  244. })
  245. test('string event occurred once', () => {
  246. assert.strictEqual(log.counts.string, 1)
  247. })
  248. test('string event was dispatched correctly', () => {
  249. assert.lengthOf(log.args.string[0], 1)
  250. assert.strictEqual(log.args.string[0][0], '"the quick brown fox\r\n\tjumps\u00a0over the lazy\u1680dog"')
  251. })
  252. test('end event occurred once', () => {
  253. assert.strictEqual(log.counts.end, 1)
  254. })
  255. test('array event did not occur', () => {
  256. assert.strictEqual(log.counts.array, 0)
  257. })
  258. test('object event did not occur', () => {
  259. assert.strictEqual(log.counts.object, 0)
  260. })
  261. test('property event did not occur', () => {
  262. assert.strictEqual(log.counts.property, 0)
  263. })
  264. test('number event did not occur', () => {
  265. assert.strictEqual(log.counts.number, 0)
  266. })
  267. test('literal event did not occur', () => {
  268. assert.strictEqual(log.counts.literal, 0)
  269. })
  270. test('endArray event did not occur', () => {
  271. assert.strictEqual(log.counts.endArray, 0)
  272. })
  273. test('endObject event did not occur', () => {
  274. assert.strictEqual(log.counts.endObject, 0)
  275. })
  276. test('error event did not occur', () => {
  277. assert.strictEqual(log.counts.error, 0)
  278. })
  279. test('dataError event did not occur', () => {
  280. assert.strictEqual(log.counts.dataError, 0)
  281. })
  282. test('endLine event did not occur', () => {
  283. assert.strictEqual(log.counts.endLine, 0)
  284. })
  285. test('endPrefix event did not occur', () => {
  286. assert.strictEqual(log.counts.endPrefix, 0)
  287. })
  288. })
  289. suite('number:', () => {
  290. let stream, emitter
  291. setup(done => {
  292. stream = new Readable()
  293. stream._read = () => {}
  294. emitter = walk(stream)
  295. stream.push('-3.14159265359e+42')
  296. stream.push(null)
  297. Object.keys(events).forEach(key => {
  298. emitter.on(events[key], spooks.fn({
  299. name: key,
  300. log: log
  301. }))
  302. })
  303. emitter.on(events.end, done)
  304. })
  305. test('number event occurred once', () => {
  306. assert.strictEqual(log.counts.number, 1)
  307. })
  308. test('number event was dispatched correctly', () => {
  309. assert.lengthOf(log.args.number[0], 1)
  310. assert.strictEqual(log.args.number[0][0], -3.14159265359e+42)
  311. })
  312. test('end event occurred once', () => {
  313. assert.strictEqual(log.counts.end, 1)
  314. })
  315. test('array event did not occur', () => {
  316. assert.strictEqual(log.counts.array, 0)
  317. })
  318. test('object event did not occur', () => {
  319. assert.strictEqual(log.counts.object, 0)
  320. })
  321. test('property event did not occur', () => {
  322. assert.strictEqual(log.counts.property, 0)
  323. })
  324. test('string event did not occur', () => {
  325. assert.strictEqual(log.counts.string, 0)
  326. })
  327. test('literal event did not occur', () => {
  328. assert.strictEqual(log.counts.literal, 0)
  329. })
  330. test('endArray event did not occur', () => {
  331. assert.strictEqual(log.counts.endArray, 0)
  332. })
  333. test('endObject event did not occur', () => {
  334. assert.strictEqual(log.counts.endObject, 0)
  335. })
  336. test('error event did not occur', () => {
  337. assert.strictEqual(log.counts.error, 0)
  338. })
  339. test('dataError event did not occur', () => {
  340. assert.strictEqual(log.counts.dataError, 0)
  341. })
  342. test('endLine event did not occur', () => {
  343. assert.strictEqual(log.counts.endLine, 0)
  344. })
  345. test('endPrefix event did not occur', () => {
  346. assert.strictEqual(log.counts.endPrefix, 0)
  347. })
  348. })
  349. suite('literal false:', () => {
  350. let stream, emitter
  351. setup(done => {
  352. stream = new Readable()
  353. stream._read = () => {}
  354. emitter = walk(stream)
  355. stream.push('false')
  356. stream.push(null)
  357. Object.keys(events).forEach(key => {
  358. emitter.on(events[key], spooks.fn({
  359. name: key,
  360. log: log
  361. }))
  362. })
  363. emitter.on(events.end, done)
  364. })
  365. test('literal event occurred once', () => {
  366. assert.strictEqual(log.counts.literal, 1)
  367. })
  368. test('literal event was dispatched correctly', () => {
  369. assert.lengthOf(log.args.literal[0], 1)
  370. assert.strictEqual(log.args.literal[0][0], false)
  371. })
  372. test('end event occurred once', () => {
  373. assert.strictEqual(log.counts.end, 1)
  374. })
  375. test('array event did not occur', () => {
  376. assert.strictEqual(log.counts.array, 0)
  377. })
  378. test('object event did not occur', () => {
  379. assert.strictEqual(log.counts.object, 0)
  380. })
  381. test('property event did not occur', () => {
  382. assert.strictEqual(log.counts.property, 0)
  383. })
  384. test('string event did not occur', () => {
  385. assert.strictEqual(log.counts.string, 0)
  386. })
  387. test('number event did not occur', () => {
  388. assert.strictEqual(log.counts.number, 0)
  389. })
  390. test('endArray event did not occur', () => {
  391. assert.strictEqual(log.counts.endArray, 0)
  392. })
  393. test('endObject event did not occur', () => {
  394. assert.strictEqual(log.counts.endObject, 0)
  395. })
  396. test('error event did not occur', () => {
  397. assert.strictEqual(log.counts.error, 0)
  398. })
  399. test('dataError event did not occur', () => {
  400. assert.strictEqual(log.counts.dataError, 0)
  401. })
  402. test('endLine event did not occur', () => {
  403. assert.strictEqual(log.counts.endLine, 0)
  404. })
  405. test('endPrefix event did not occur', () => {
  406. assert.strictEqual(log.counts.endPrefix, 0)
  407. })
  408. })
  409. suite('literal null:', () => {
  410. let stream, emitter
  411. setup(done => {
  412. stream = new Readable()
  413. stream._read = () => {}
  414. emitter = walk(stream)
  415. stream.push('null')
  416. stream.push(null)
  417. Object.keys(events).forEach(key => {
  418. emitter.on(events[key], spooks.fn({
  419. name: key,
  420. log: log
  421. }))
  422. })
  423. emitter.on(events.end, done)
  424. })
  425. test('literal event occurred once', () => {
  426. assert.strictEqual(log.counts.literal, 1)
  427. })
  428. test('literal event was dispatched correctly', () => {
  429. assert.strictEqual(log.args.literal[0][0], null)
  430. })
  431. test('end event occurred once', () => {
  432. assert.strictEqual(log.counts.end, 1)
  433. })
  434. test('array event did not occur', () => {
  435. assert.strictEqual(log.counts.array, 0)
  436. })
  437. test('object event did not occur', () => {
  438. assert.strictEqual(log.counts.object, 0)
  439. })
  440. test('property event did not occur', () => {
  441. assert.strictEqual(log.counts.property, 0)
  442. })
  443. test('string event did not occur', () => {
  444. assert.strictEqual(log.counts.string, 0)
  445. })
  446. test('number event did not occur', () => {
  447. assert.strictEqual(log.counts.number, 0)
  448. })
  449. test('endArray event did not occur', () => {
  450. assert.strictEqual(log.counts.endArray, 0)
  451. })
  452. test('endObject event did not occur', () => {
  453. assert.strictEqual(log.counts.endObject, 0)
  454. })
  455. test('error event did not occur', () => {
  456. assert.strictEqual(log.counts.error, 0)
  457. })
  458. test('dataError event did not occur', () => {
  459. assert.strictEqual(log.counts.dataError, 0)
  460. })
  461. test('endLine event did not occur', () => {
  462. assert.strictEqual(log.counts.endLine, 0)
  463. })
  464. test('endPrefix event did not occur', () => {
  465. assert.strictEqual(log.counts.endPrefix, 0)
  466. })
  467. })
  468. suite('literal true:', () => {
  469. let stream, emitter
  470. setup(done => {
  471. stream = new Readable()
  472. stream._read = () => {}
  473. emitter = walk(stream)
  474. stream.push('true')
  475. stream.push(null)
  476. Object.keys(events).forEach(key => {
  477. emitter.on(events[key], spooks.fn({
  478. name: key,
  479. log: log
  480. }))
  481. })
  482. emitter.on(events.end, done)
  483. })
  484. test('literal event occurred once', () => {
  485. assert.strictEqual(log.counts.literal, 1)
  486. })
  487. test('literal event was dispatched correctly', () => {
  488. assert.strictEqual(log.args.literal[0][0], true)
  489. })
  490. test('end event occurred once', () => {
  491. assert.strictEqual(log.counts.end, 1)
  492. })
  493. test('array event did not occur', () => {
  494. assert.strictEqual(log.counts.array, 0)
  495. })
  496. test('object event did not occur', () => {
  497. assert.strictEqual(log.counts.object, 0)
  498. })
  499. test('property event did not occur', () => {
  500. assert.strictEqual(log.counts.property, 0)
  501. })
  502. test('string event did not occur', () => {
  503. assert.strictEqual(log.counts.string, 0)
  504. })
  505. test('number event did not occur', () => {
  506. assert.strictEqual(log.counts.number, 0)
  507. })
  508. test('endArray event did not occur', () => {
  509. assert.strictEqual(log.counts.endArray, 0)
  510. })
  511. test('endObject event did not occur', () => {
  512. assert.strictEqual(log.counts.endObject, 0)
  513. })
  514. test('error event did not occur', () => {
  515. assert.strictEqual(log.counts.error, 0)
  516. })
  517. test('dataError event did not occur', () => {
  518. assert.strictEqual(log.counts.dataError, 0)
  519. })
  520. test('endLine event did not occur', () => {
  521. assert.strictEqual(log.counts.endLine, 0)
  522. })
  523. test('endPrefix event did not occur', () => {
  524. assert.strictEqual(log.counts.endPrefix, 0)
  525. })
  526. })
  527. suite('badly-closed array:', () => {
  528. let stream, emitter
  529. setup(done => {
  530. stream = new Readable()
  531. stream._read = () => {}
  532. emitter = walk(stream)
  533. stream.push('[}')
  534. stream.push(null)
  535. Object.keys(events).forEach(key => {
  536. emitter.on(events[key], spooks.fn({
  537. name: key,
  538. log: log
  539. }))
  540. })
  541. emitter.on(events.end, done)
  542. })
  543. test('array event occurred once', () => {
  544. assert.strictEqual(log.counts.array, 1)
  545. })
  546. test('dataError event occurred twice', () => {
  547. assert.strictEqual(log.counts.dataError, 2)
  548. })
  549. test('dataError event was dispatched correctly first time', () => {
  550. assert.lengthOf(log.args.dataError[0], 1)
  551. assert.instanceOf(log.args.dataError[0][0], Error)
  552. assert.strictEqual(log.args.dataError[0][0].actual, '}')
  553. assert.strictEqual(log.args.dataError[0][0].expected, 'value')
  554. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  555. assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
  556. })
  557. test('dataError event was dispatched correctly second time', () => {
  558. assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
  559. assert.strictEqual(log.args.dataError[1][0].expected, ']')
  560. assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
  561. assert.strictEqual(log.args.dataError[1][0].columnNumber, 3)
  562. })
  563. test('end event occurred once', () => {
  564. assert.strictEqual(log.counts.end, 1)
  565. })
  566. test('object event did not occur', () => {
  567. assert.strictEqual(log.counts.object, 0)
  568. })
  569. test('endArray event did not occur', () => {
  570. assert.strictEqual(log.counts.endArray, 0)
  571. })
  572. test('endObject event did not occur', () => {
  573. assert.strictEqual(log.counts.endObject, 0)
  574. })
  575. })
  576. suite('badly-closed object:', () => {
  577. let stream, emitter
  578. setup(done => {
  579. stream = new Readable()
  580. stream._read = () => {}
  581. emitter = walk(stream)
  582. stream.push('{]')
  583. stream.push(null)
  584. Object.keys(events).forEach(key => {
  585. emitter.on(events[key], spooks.fn({
  586. name: key,
  587. log: log
  588. }))
  589. })
  590. emitter.on(events.end, done)
  591. })
  592. test('object event occurred once', () => {
  593. assert.strictEqual(log.counts.object, 1)
  594. })
  595. test('dataError event occurred three times', () => {
  596. assert.strictEqual(log.counts.dataError, 3)
  597. })
  598. test('dataError event was dispatched correctly first time', () => {
  599. assert.strictEqual(log.args.dataError[0][0].actual, ']')
  600. assert.strictEqual(log.args.dataError[0][0].expected, '"')
  601. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  602. assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
  603. })
  604. test('dataError event was dispatched correctly second time', () => {
  605. assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
  606. assert.strictEqual(log.args.dataError[1][0].expected, '"')
  607. assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
  608. assert.strictEqual(log.args.dataError[1][0].columnNumber, 3)
  609. })
  610. test('dataError event was dispatched correctly third time', () => {
  611. assert.strictEqual(log.args.dataError[2][0].actual, 'EOF')
  612. assert.strictEqual(log.args.dataError[2][0].expected, '}')
  613. assert.strictEqual(log.args.dataError[2][0].lineNumber, 1)
  614. assert.strictEqual(log.args.dataError[2][0].columnNumber, 3)
  615. })
  616. test('end event occurred once', () => {
  617. assert.strictEqual(log.counts.end, 1)
  618. })
  619. test('array event did not occur', () => {
  620. assert.strictEqual(log.counts.array, 0)
  621. })
  622. test('endArray event did not occur', () => {
  623. assert.strictEqual(log.counts.endArray, 0)
  624. })
  625. test('endObject event did not occur', () => {
  626. assert.strictEqual(log.counts.endObject, 0)
  627. })
  628. })
  629. suite('string containing bad escape sequence:', () => {
  630. let stream, emitter
  631. setup(done => {
  632. stream = new Readable()
  633. stream._read = () => {}
  634. emitter = walk(stream)
  635. stream.push('"\\"the quick brown fox\r\n\\tjumps over the lazy\\xdog\\""')
  636. stream.push(null)
  637. Object.keys(events).forEach(key => {
  638. emitter.on(events[key], spooks.fn({
  639. name: key,
  640. log: log
  641. }))
  642. })
  643. emitter.on(events.end, done)
  644. })
  645. test('dataError event occurred once', () => {
  646. assert.strictEqual(log.counts.dataError, 1)
  647. })
  648. test('dataError event was dispatched correctly', () => {
  649. assert.strictEqual(log.args.dataError[0][0].actual, 'x')
  650. assert.strictEqual(log.args.dataError[0][0].expected, 'escape character')
  651. assert.strictEqual(log.args.dataError[0][0].lineNumber, 2)
  652. assert.strictEqual(log.args.dataError[0][0].columnNumber, 23)
  653. })
  654. test('string event occurred once', () => {
  655. assert.strictEqual(log.counts.string, 1)
  656. })
  657. test('string event was dispatched correctly', () => {
  658. assert.strictEqual(log.args.string[0][0], '"the quick brown fox\r\n\tjumps over the lazy\\xdog"')
  659. })
  660. test('end event occurred once', () => {
  661. assert.strictEqual(log.counts.end, 1)
  662. })
  663. })
  664. suite('string containing bad unicode escape sequence:', () => {
  665. let stream, emitter
  666. setup(done => {
  667. stream = new Readable()
  668. stream._read = () => {}
  669. emitter = walk(stream)
  670. stream.push('"\\u012g"')
  671. stream.push(null)
  672. Object.keys(events).forEach(key => {
  673. emitter.on(events[key], spooks.fn({
  674. name: key,
  675. log: log
  676. }))
  677. })
  678. emitter.on(events.end, done)
  679. })
  680. test('dataError event occurred once', () => {
  681. assert.strictEqual(log.counts.dataError, 1)
  682. })
  683. test('dataError event was dispatched correctly', () => {
  684. assert.strictEqual(log.args.dataError[0][0].actual, 'g')
  685. assert.strictEqual(log.args.dataError[0][0].expected, 'hex digit')
  686. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  687. assert.strictEqual(log.args.dataError[0][0].columnNumber, 7)
  688. })
  689. test('string event occurred once', () => {
  690. assert.strictEqual(log.counts.string, 1)
  691. })
  692. test('string event was dispatched correctly', () => {
  693. assert.strictEqual(log.args.string[0][0], '\\u012g')
  694. })
  695. test('end event occurred once', () => {
  696. assert.strictEqual(log.counts.end, 1)
  697. })
  698. })
  699. suite('unterminated string:', () => {
  700. let stream, emitter
  701. setup(done => {
  702. stream = new Readable()
  703. stream._read = () => {}
  704. emitter = walk(stream)
  705. stream.push('"foo')
  706. stream.push(null)
  707. Object.keys(events).forEach(key => {
  708. emitter.on(events[key], spooks.fn({
  709. name: key,
  710. log: log
  711. }))
  712. })
  713. emitter.on(events.end, done)
  714. })
  715. test('dataError event occurred once', () => {
  716. assert.strictEqual(log.counts.dataError, 1)
  717. })
  718. test('dataError event was dispatched correctly', () => {
  719. assert.strictEqual(log.args.dataError[0][0].actual, 'EOF')
  720. assert.strictEqual(log.args.dataError[0][0].expected, '"')
  721. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  722. assert.strictEqual(log.args.dataError[0][0].columnNumber, 5)
  723. })
  724. test('end event occurred once', () => {
  725. assert.strictEqual(log.counts.end, 1)
  726. })
  727. test('string event did not occur', () => {
  728. assert.strictEqual(log.counts.string, 0)
  729. })
  730. })
  731. suite('bad number:', () => {
  732. let stream, emitter
  733. setup(done => {
  734. stream = new Readable()
  735. stream._read = () => {}
  736. emitter = walk(stream)
  737. stream.push('1e')
  738. stream.push(null)
  739. Object.keys(events).forEach(key => {
  740. emitter.on(events[key], spooks.fn({
  741. name: key,
  742. log: log
  743. }))
  744. })
  745. emitter.on(events.end, done)
  746. })
  747. test('number event did not occur', () => {
  748. assert.strictEqual(log.counts.number, 0)
  749. })
  750. test('dataError event occurred once', () => {
  751. assert.strictEqual(log.counts.dataError, 1)
  752. })
  753. test('dataError event was dispatched correctly first time', () => {
  754. assert.strictEqual(log.args.dataError[0][0].actual, 'EOF')
  755. assert.strictEqual(log.args.dataError[0][0].expected, 'exponent')
  756. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  757. assert.strictEqual(log.args.dataError[0][0].columnNumber, 3)
  758. })
  759. test('end event occurred once', () => {
  760. assert.strictEqual(log.counts.end, 1)
  761. })
  762. test('literal event did not occur', () => {
  763. assert.strictEqual(log.counts.literal, 0)
  764. })
  765. })
  766. suite('alternative bad number:', () => {
  767. let stream, emitter
  768. setup(done => {
  769. stream = new Readable()
  770. stream._read = () => {}
  771. emitter = walk(stream)
  772. stream.push('42f')
  773. stream.push(null)
  774. Object.keys(events).forEach(key => {
  775. emitter.on(events[key], spooks.fn({
  776. name: key,
  777. log: log
  778. }))
  779. })
  780. emitter.on(events.end, done)
  781. })
  782. test('number event occurred once', () => {
  783. assert.strictEqual(log.counts.number, 1)
  784. })
  785. test('number event was dispatched correctly', () => {
  786. assert.strictEqual(log.args.number[0][0], 42)
  787. })
  788. test('dataError event occurred twice', () => {
  789. assert.strictEqual(log.counts.dataError, 2)
  790. })
  791. test('dataError event was dispatched correctly first time', () => {
  792. assert.strictEqual(log.args.dataError[0][0].actual, 'f')
  793. assert.strictEqual(log.args.dataError[0][0].expected, 'EOF')
  794. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  795. assert.strictEqual(log.args.dataError[0][0].columnNumber, 3)
  796. })
  797. test('dataError event was dispatched correctly second time', () => {
  798. assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
  799. assert.strictEqual(log.args.dataError[1][0].expected, 'a')
  800. assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
  801. assert.strictEqual(log.args.dataError[1][0].columnNumber, 4)
  802. })
  803. test('end event occurred once', () => {
  804. assert.strictEqual(log.counts.end, 1)
  805. })
  806. test('literal event did not occur', () => {
  807. assert.strictEqual(log.counts.literal, 0)
  808. })
  809. })
  810. suite('bad literal false:', () => {
  811. let stream, emitter
  812. setup(done => {
  813. stream = new Readable()
  814. stream._read = () => {}
  815. emitter = walk(stream)
  816. stream.push('falsd')
  817. stream.push(null)
  818. Object.keys(events).forEach(key => {
  819. emitter.on(events[key], spooks.fn({
  820. name: key,
  821. log: log
  822. }))
  823. })
  824. emitter.on(events.end, done)
  825. })
  826. test('dataError event occurred once', () => {
  827. assert.strictEqual(log.counts.dataError, 1)
  828. })
  829. test('dataError event was dispatched correctly', () => {
  830. assert.strictEqual(log.args.dataError[0][0].actual, 'd')
  831. assert.strictEqual(log.args.dataError[0][0].expected, 'e')
  832. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  833. assert.strictEqual(log.args.dataError[0][0].columnNumber, 5)
  834. })
  835. test('end event occurred once', () => {
  836. assert.strictEqual(log.counts.end, 1)
  837. })
  838. test('literal event did not occur', () => {
  839. assert.strictEqual(log.counts.literal, 0)
  840. })
  841. })
  842. suite('bad literal null:', () => {
  843. let stream, emitter
  844. setup(done => {
  845. stream = new Readable()
  846. stream._read = () => {}
  847. emitter = walk(stream)
  848. stream.push('nul')
  849. stream.push(null)
  850. Object.keys(events).forEach(key => {
  851. emitter.on(events[key], spooks.fn({
  852. name: key,
  853. log: log
  854. }))
  855. })
  856. emitter.on(events.end, done)
  857. })
  858. test('dataError event occurred once', () => {
  859. assert.strictEqual(log.counts.dataError, 1)
  860. })
  861. test('dataError event was dispatched correctly', () => {
  862. assert.strictEqual(log.args.dataError[0][0].actual, 'EOF')
  863. assert.strictEqual(log.args.dataError[0][0].expected, 'l')
  864. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  865. assert.strictEqual(log.args.dataError[0][0].columnNumber, 4)
  866. })
  867. test('end event occurred once', () => {
  868. assert.strictEqual(log.counts.end, 1)
  869. })
  870. test('literal event did not occur', () => {
  871. assert.strictEqual(log.counts.literal, 0)
  872. })
  873. })
  874. suite('bad literal true:', () => {
  875. let stream, emitter
  876. setup(done => {
  877. stream = new Readable()
  878. stream._read = () => {}
  879. emitter = walk(stream)
  880. stream.push('tRue')
  881. stream.push(null)
  882. Object.keys(events).forEach(key => {
  883. emitter.on(events[key], spooks.fn({
  884. name: key,
  885. log: log
  886. }))
  887. })
  888. emitter.on(events.end, done)
  889. })
  890. test('dataError event occurred four times', () => {
  891. assert.strictEqual(log.counts.dataError, 4)
  892. })
  893. test('dataError event was dispatched correctly first time', () => {
  894. assert.strictEqual(log.args.dataError[0][0].actual, 'R')
  895. assert.strictEqual(log.args.dataError[0][0].expected, 'r')
  896. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  897. assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
  898. })
  899. test('dataError event was dispatched correctly second time', () => {
  900. assert.strictEqual(log.args.dataError[1][0].actual, 'u')
  901. assert.strictEqual(log.args.dataError[1][0].expected, 'EOF')
  902. assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
  903. assert.strictEqual(log.args.dataError[1][0].columnNumber, 3)
  904. })
  905. test('dataError event was dispatched correctly third time', () => {
  906. assert.strictEqual(log.args.dataError[2][0].actual, 'u')
  907. assert.strictEqual(log.args.dataError[2][0].expected, 'value')
  908. assert.strictEqual(log.args.dataError[2][0].lineNumber, 1)
  909. assert.strictEqual(log.args.dataError[2][0].columnNumber, 3)
  910. })
  911. test('dataError event was dispatched correctly fourth time', () => {
  912. assert.strictEqual(log.args.dataError[3][0].actual, 'e')
  913. assert.strictEqual(log.args.dataError[3][0].expected, 'value')
  914. assert.strictEqual(log.args.dataError[3][0].lineNumber, 1)
  915. assert.strictEqual(log.args.dataError[3][0].columnNumber, 4)
  916. })
  917. test('end event occurred once', () => {
  918. assert.strictEqual(log.counts.end, 1)
  919. })
  920. test('literal event did not occur', () => {
  921. assert.strictEqual(log.counts.literal, 0)
  922. })
  923. })
  924. suite('array inside array:', () => {
  925. let stream, emitter
  926. setup(done => {
  927. stream = new Readable()
  928. stream._read = () => {}
  929. emitter = walk(stream)
  930. stream.push('[[]]')
  931. stream.push(null)
  932. Object.keys(events).forEach(key => {
  933. emitter.on(events[key], spooks.fn({
  934. name: key,
  935. log: log
  936. }))
  937. })
  938. emitter.on(events.end, done)
  939. })
  940. test('array event occurred twice', () => {
  941. assert.strictEqual(log.counts.array, 2)
  942. })
  943. test('endArray event occurred twice', () => {
  944. assert.strictEqual(log.counts.endArray, 2)
  945. })
  946. test('end event occurred once', () => {
  947. assert.strictEqual(log.counts.end, 1)
  948. })
  949. test('error event did not occur', () => {
  950. assert.strictEqual(log.counts.error, 0)
  951. })
  952. test('dataError event did not occur', () => {
  953. assert.strictEqual(log.counts.dataError, 0)
  954. })
  955. test('endLine event did not occur', () => {
  956. assert.strictEqual(log.counts.endLine, 0)
  957. })
  958. })
  959. suite('two arrays inside array:', () => {
  960. let stream, emitter
  961. setup(done => {
  962. stream = new Readable()
  963. stream._read = () => {}
  964. emitter = walk(stream)
  965. stream.push('[[],[]]')
  966. stream.push(null)
  967. Object.keys(events).forEach(key => {
  968. emitter.on(events[key], spooks.fn({
  969. name: key,
  970. log: log
  971. }))
  972. })
  973. emitter.on(events.end, done)
  974. })
  975. test('array event occurred three times', () => {
  976. assert.strictEqual(log.counts.array, 3)
  977. })
  978. test('endArray event occurred three times', () => {
  979. assert.strictEqual(log.counts.endArray, 3)
  980. })
  981. test('end event occurred once', () => {
  982. assert.strictEqual(log.counts.end, 1)
  983. })
  984. test('error event did not occur', () => {
  985. assert.strictEqual(log.counts.error, 0)
  986. })
  987. test('dataError event did not occur', () => {
  988. assert.strictEqual(log.counts.dataError, 0)
  989. })
  990. })
  991. suite('two arrays inside array with whitespace:', () => {
  992. let stream, emitter
  993. setup(done => {
  994. stream = new Readable()
  995. stream._read = () => {}
  996. emitter = walk(stream)
  997. stream.push(' [ [] , [] ] ')
  998. stream.push(null)
  999. Object.keys(events).forEach(key => {
  1000. emitter.on(events[key], spooks.fn({
  1001. name: key,
  1002. log: log
  1003. }))
  1004. })
  1005. emitter.on(events.end, done)
  1006. })
  1007. test('array event occurred three times', () => {
  1008. assert.strictEqual(log.counts.array, 3)
  1009. })
  1010. test('endArray event occurred three times', () => {
  1011. assert.strictEqual(log.counts.endArray, 3)
  1012. })
  1013. test('end event occurred once', () => {
  1014. assert.strictEqual(log.counts.end, 1)
  1015. })
  1016. test('error event did not occur', () => {
  1017. assert.strictEqual(log.counts.error, 0)
  1018. })
  1019. test('dataError event did not occur', () => {
  1020. assert.strictEqual(log.counts.dataError, 0)
  1021. })
  1022. })
  1023. suite('two arrays inside array without comma:', () => {
  1024. let stream, emitter
  1025. setup(done => {
  1026. stream = new Readable()
  1027. stream._read = () => {}
  1028. emitter = walk(stream)
  1029. stream.push('[[][]]')
  1030. stream.push(null)
  1031. Object.keys(events).forEach(key => {
  1032. emitter.on(events[key], spooks.fn({
  1033. name: key,
  1034. log: log
  1035. }))
  1036. })
  1037. emitter.on(events.end, done)
  1038. })
  1039. test('array event occurred three times', () => {
  1040. assert.strictEqual(log.counts.array, 3)
  1041. })
  1042. test('endArray event occurred three times', () => {
  1043. assert.strictEqual(log.counts.endArray, 3)
  1044. })
  1045. test('dataError event occurred once', () => {
  1046. assert.strictEqual(log.counts.dataError, 1)
  1047. })
  1048. test('dataError event was dispatched correctly', () => {
  1049. assert.strictEqual(log.args.dataError[0][0].actual, '[')
  1050. assert.strictEqual(log.args.dataError[0][0].expected, ',')
  1051. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  1052. assert.strictEqual(log.args.dataError[0][0].columnNumber, 4)
  1053. })
  1054. test('end event occurred once', () => {
  1055. assert.strictEqual(log.counts.end, 1)
  1056. })
  1057. test('endObject event did not occur', () => {
  1058. assert.strictEqual(log.counts.endObject, 0)
  1059. })
  1060. })
  1061. suite('object inside array:', () => {
  1062. let stream, emitter
  1063. setup(done => {
  1064. stream = new Readable()
  1065. stream._read = () => {}
  1066. emitter = walk(stream)
  1067. stream.push('[{}]')
  1068. stream.push(null)
  1069. Object.keys(events).forEach(key => {
  1070. emitter.on(events[key], spooks.fn({
  1071. name: key,
  1072. log: log
  1073. }))
  1074. })
  1075. emitter.on(events.end, done)
  1076. })
  1077. test('array event occurred once', () => {
  1078. assert.strictEqual(log.counts.array, 1)
  1079. })
  1080. test('object event occurred once', () => {
  1081. assert.strictEqual(log.counts.object, 1)
  1082. })
  1083. test('endObject event occurred once', () => {
  1084. assert.strictEqual(log.counts.endObject, 1)
  1085. })
  1086. test('endArray event occurred once', () => {
  1087. assert.strictEqual(log.counts.endArray, 1)
  1088. })
  1089. test('end event occurred once', () => {
  1090. assert.strictEqual(log.counts.end, 1)
  1091. })
  1092. test('error event did not occur', () => {
  1093. assert.strictEqual(log.counts.error, 0)
  1094. })
  1095. test('dataError event did not occur', () => {
  1096. assert.strictEqual(log.counts.dataError, 0)
  1097. })
  1098. test('endLine event did not occur', () => {
  1099. assert.strictEqual(log.counts.endLine, 0)
  1100. })
  1101. })
  1102. suite('two objects inside array:', () => {
  1103. let stream, emitter
  1104. setup(done => {
  1105. stream = new Readable()
  1106. stream._read = () => {}
  1107. emitter = walk(stream)
  1108. stream.push('[{},{}]')
  1109. stream.push(null)
  1110. Object.keys(events).forEach(key => {
  1111. emitter.on(events[key], spooks.fn({
  1112. name: key,
  1113. log: log
  1114. }))
  1115. })
  1116. emitter.on(events.end, done)
  1117. })
  1118. test('array event occurred once', () => {
  1119. assert.strictEqual(log.counts.array, 1)
  1120. })
  1121. test('object event occurred twice', () => {
  1122. assert.strictEqual(log.counts.object, 2)
  1123. })
  1124. test('endObject event occurred twice', () => {
  1125. assert.strictEqual(log.counts.endObject, 2)
  1126. })
  1127. test('endArray event occurred once', () => {
  1128. assert.strictEqual(log.counts.endArray, 1)
  1129. })
  1130. test('end event occurred once', () => {
  1131. assert.strictEqual(log.counts.end, 1)
  1132. })
  1133. test('error event did not occur', () => {
  1134. assert.strictEqual(log.counts.error, 0)
  1135. })
  1136. test('dataError event did not occur', () => {
  1137. assert.strictEqual(log.counts.dataError, 0)
  1138. })
  1139. })
  1140. suite('two objects inside array with whitespace:', () => {
  1141. let stream, emitter
  1142. setup(done => {
  1143. stream = new Readable()
  1144. stream._read = () => {}
  1145. emitter = walk(stream)
  1146. stream.push('\t[\t{}\t,\r{}\n]\r\n')
  1147. stream.push(null)
  1148. Object.keys(events).forEach(key => {
  1149. emitter.on(events[key], spooks.fn({
  1150. name: key,
  1151. log: log
  1152. }))
  1153. })
  1154. emitter.on(events.end, done)
  1155. })
  1156. test('array event occurred once', () => {
  1157. assert.strictEqual(log.counts.array, 1)
  1158. })
  1159. test('object event occurred twice', () => {
  1160. assert.strictEqual(log.counts.object, 2)
  1161. })
  1162. test('endObject event occurred twice', () => {
  1163. assert.strictEqual(log.counts.endObject, 2)
  1164. })
  1165. test('endArray event occurred once', () => {
  1166. assert.strictEqual(log.counts.endArray, 1)
  1167. })
  1168. test('end event occurred once', () => {
  1169. assert.strictEqual(log.counts.end, 1)
  1170. })
  1171. test('error event did not occur', () => {
  1172. assert.strictEqual(log.counts.error, 0)
  1173. })
  1174. test('dataError event did not occur', () => {
  1175. assert.strictEqual(log.counts.dataError, 0)
  1176. })
  1177. })
  1178. suite('two objects inside array without comma:', () => {
  1179. let stream, emitter
  1180. setup(done => {
  1181. stream = new Readable()
  1182. stream._read = () => {}
  1183. emitter = walk(stream)
  1184. stream.push('[ {} {} ]')
  1185. stream.push(null)
  1186. Object.keys(events).forEach(key => {
  1187. emitter.on(events[key], spooks.fn({
  1188. name: key,
  1189. log: log
  1190. }))
  1191. })
  1192. emitter.on(events.end, done)
  1193. })
  1194. test('array event occurred once', () => {
  1195. assert.strictEqual(log.counts.array, 1)
  1196. })
  1197. test('object event occurred twice', () => {
  1198. assert.strictEqual(log.counts.object, 2)
  1199. })
  1200. test('endObject event occurred twice', () => {
  1201. assert.strictEqual(log.counts.endObject, 2)
  1202. })
  1203. test('dataError event occurred once', () => {
  1204. assert.strictEqual(log.counts.dataError, 1)
  1205. })
  1206. test('dataError event was dispatched correctly', () => {
  1207. assert.strictEqual(log.args.dataError[0][0].actual, '{')
  1208. assert.strictEqual(log.args.dataError[0][0].expected, ',')
  1209. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  1210. assert.strictEqual(log.args.dataError[0][0].columnNumber, 6)
  1211. })
  1212. test('endArray event occurred once', () => {
  1213. assert.strictEqual(log.counts.endArray, 1)
  1214. })
  1215. test('end event occurred once', () => {
  1216. assert.strictEqual(log.counts.end, 1)
  1217. })
  1218. })
  1219. suite('string inside array:', () => {
  1220. let stream, emitter
  1221. setup(done => {
  1222. stream = new Readable()
  1223. stream._read = () => {}
  1224. emitter = walk(stream)
  1225. stream.push('["foo"]')
  1226. stream.push(null)
  1227. Object.keys(events).forEach(key => {
  1228. emitter.on(events[key], spooks.fn({
  1229. name: key,
  1230. log: log
  1231. }))
  1232. })
  1233. emitter.on(events.end, done)
  1234. })
  1235. test('array event occurred once', () => {
  1236. assert.strictEqual(log.counts.array, 1)
  1237. })
  1238. test('string event occurred once', () => {
  1239. assert.strictEqual(log.counts.string, 1)
  1240. })
  1241. test('string event was dispatched correctly', () => {
  1242. assert.strictEqual(log.args.string[0][0], 'foo')
  1243. })
  1244. test('endArray event occurred once', () => {
  1245. assert.strictEqual(log.counts.endArray, 1)
  1246. })
  1247. test('end event occurred once', () => {
  1248. assert.strictEqual(log.counts.end, 1)
  1249. })
  1250. test('object event did not occur', () => {
  1251. assert.strictEqual(log.counts.object, 0)
  1252. })
  1253. test('error event did not occur', () => {
  1254. assert.strictEqual(log.counts.error, 0)
  1255. })
  1256. test('dataError event did not occur', () => {
  1257. assert.strictEqual(log.counts.dataError, 0)
  1258. })
  1259. test('endLine event did not occur', () => {
  1260. assert.strictEqual(log.counts.endLine, 0)
  1261. })
  1262. })
  1263. suite('two strings inside array:', () => {
  1264. let stream, emitter
  1265. setup(done => {
  1266. stream = new Readable()
  1267. stream._read = () => {}
  1268. emitter = walk(stream)
  1269. stream.push('["foo","bar"]')
  1270. stream.push(null)
  1271. Object.keys(events).forEach(key => {
  1272. emitter.on(events[key], spooks.fn({
  1273. name: key,
  1274. log: log
  1275. }))
  1276. })
  1277. emitter.on(events.end, done)
  1278. })
  1279. test('array event occurred once', () => {
  1280. assert.strictEqual(log.counts.array, 1)
  1281. })
  1282. test('string event occurred twice', () => {
  1283. assert.strictEqual(log.counts.string, 2)
  1284. })
  1285. test('string event was dispatched correctly first time', () => {
  1286. assert.strictEqual(log.args.string[0][0], 'foo')
  1287. })
  1288. test('string event was dispatched correctly second time', () => {
  1289. assert.strictEqual(log.args.string[1][0], 'bar')
  1290. })
  1291. test('endArray event occurred once', () => {
  1292. assert.strictEqual(log.counts.endArray, 1)
  1293. })
  1294. test('end event occurred once', () => {
  1295. assert.strictEqual(log.counts.end, 1)
  1296. })
  1297. test('error event did not occur', () => {
  1298. assert.strictEqual(log.counts.error, 0)
  1299. })
  1300. test('dataError event did not occur', () => {
  1301. assert.strictEqual(log.counts.dataError, 0)
  1302. })
  1303. })
  1304. suite('two strings inside array with whitespace:', () => {
  1305. let stream, emitter
  1306. setup(done => {
  1307. stream = new Readable()
  1308. stream._read = () => {}
  1309. emitter = walk(stream)
  1310. stream.push(' [ "baz" , "qux" ] ')
  1311. stream.push(null)
  1312. Object.keys(events).forEach(key => {
  1313. emitter.on(events[key], spooks.fn({
  1314. name: key,
  1315. log: log
  1316. }))
  1317. })
  1318. emitter.on(events.end, done)
  1319. })
  1320. test('array event occurred once', () => {
  1321. assert.strictEqual(log.counts.array, 1)
  1322. })
  1323. test('string event occurred twice', () => {
  1324. assert.strictEqual(log.counts.string, 2)
  1325. })
  1326. test('string event was dispatched correctly first time', () => {
  1327. assert.strictEqual(log.args.string[0][0], 'baz')
  1328. })
  1329. test('string event was dispatched correctly second time', () => {
  1330. assert.strictEqual(log.args.string[1][0], 'qux')
  1331. })
  1332. test('endArray event occurred once', () => {
  1333. assert.strictEqual(log.counts.endArray, 1)
  1334. })
  1335. test('end event occurred once', () => {
  1336. assert.strictEqual(log.counts.end, 1)
  1337. })
  1338. test('error event did not occur', () => {
  1339. assert.strictEqual(log.counts.error, 0)
  1340. })
  1341. test('dataError event did not occur', () => {
  1342. assert.strictEqual(log.counts.dataError, 0)
  1343. })
  1344. })
  1345. suite('literal inside array:', () => {
  1346. let stream, emitter
  1347. setup(done => {
  1348. stream = new Readable()
  1349. stream._read = () => {}
  1350. emitter = walk(stream)
  1351. stream.push('[false]')
  1352. stream.push(null)
  1353. Object.keys(events).forEach(key => {
  1354. emitter.on(events[key], spooks.fn({
  1355. name: key,
  1356. log: log
  1357. }))
  1358. })
  1359. emitter.on(events.end, done)
  1360. })
  1361. test('array event occurred once', () => {
  1362. assert.strictEqual(log.counts.array, 1)
  1363. })
  1364. test('literal event occurred once', () => {
  1365. assert.strictEqual(log.counts.literal, 1)
  1366. })
  1367. test('literal event was dispatched correctly', () => {
  1368. assert.strictEqual(log.args.literal[0][0], false)
  1369. })
  1370. test('endArray event occurred once', () => {
  1371. assert.strictEqual(log.counts.endArray, 1)
  1372. })
  1373. test('end event occurred once', () => {
  1374. assert.strictEqual(log.counts.end, 1)
  1375. })
  1376. test('error event did not occur', () => {
  1377. assert.strictEqual(log.counts.error, 0)
  1378. })
  1379. test('dataError event did not occur', () => {
  1380. assert.strictEqual(log.counts.dataError, 0)
  1381. })
  1382. })
  1383. suite('two literals inside array:', () => {
  1384. let stream, emitter
  1385. setup(done => {
  1386. stream = new Readable()
  1387. stream._read = () => {}
  1388. emitter = walk(stream)
  1389. stream.push('[true,null]')
  1390. stream.push(null)
  1391. Object.keys(events).forEach(key => {
  1392. emitter.on(events[key], spooks.fn({
  1393. name: key,
  1394. log: log
  1395. }))
  1396. })
  1397. emitter.on(events.end, done)
  1398. })
  1399. test('array event occurred once', () => {
  1400. assert.strictEqual(log.counts.array, 1)
  1401. })
  1402. test('literal event occurred twice', () => {
  1403. assert.strictEqual(log.counts.literal, 2)
  1404. })
  1405. test('literal event was dispatched correctly first time', () => {
  1406. assert.strictEqual(log.args.literal[0][0], true)
  1407. })
  1408. test('literal event was dispatched correctly second time', () => {
  1409. assert.strictEqual(log.args.literal[1][0], null)
  1410. })
  1411. test('endArray event occurred once', () => {
  1412. assert.strictEqual(log.counts.endArray, 1)
  1413. })
  1414. test('end event occurred once', () => {
  1415. assert.strictEqual(log.counts.end, 1)
  1416. })
  1417. test('error event did not occur', () => {
  1418. assert.strictEqual(log.counts.error, 0)
  1419. })
  1420. test('dataError event did not occur', () => {
  1421. assert.strictEqual(log.counts.dataError, 0)
  1422. })
  1423. })
  1424. suite('two literals inside array with whitespace:', () => {
  1425. let stream, emitter
  1426. setup(done => {
  1427. stream = new Readable()
  1428. stream._read = () => {}
  1429. emitter = walk(stream)
  1430. stream.push('[ null , false ]')
  1431. stream.push(null)
  1432. Object.keys(events).forEach(key => {
  1433. emitter.on(events[key], spooks.fn({
  1434. name: key,
  1435. log: log
  1436. }))
  1437. })
  1438. emitter.on(events.end, done)
  1439. })
  1440. test('array event occurred once', () => {
  1441. assert.strictEqual(log.counts.array, 1)
  1442. })
  1443. test('literal event occurred twice', () => {
  1444. assert.strictEqual(log.counts.literal, 2)
  1445. })
  1446. test('literal event was dispatched correctly first time', () => {
  1447. assert.strictEqual(log.args.literal[0][0], null)
  1448. })
  1449. test('literal event was dispatched correctly second time', () => {
  1450. assert.strictEqual(log.args.literal[1][0], false)
  1451. })
  1452. test('endArray event occurred once', () => {
  1453. assert.strictEqual(log.counts.endArray, 1)
  1454. })
  1455. test('end event occurred once', () => {
  1456. assert.strictEqual(log.counts.end, 1)
  1457. })
  1458. test('error event did not occur', () => {
  1459. assert.strictEqual(log.counts.error, 0)
  1460. })
  1461. test('dataError event did not occur', () => {
  1462. assert.strictEqual(log.counts.dataError, 0)
  1463. })
  1464. })
  1465. suite('number inside array:', () => {
  1466. let stream, emitter
  1467. setup(done => {
  1468. stream = new Readable()
  1469. stream._read = () => {}
  1470. emitter = walk(stream)
  1471. stream.push('[0]')
  1472. stream.push(null)
  1473. Object.keys(events).forEach(key => {
  1474. emitter.on(events[key], spooks.fn({
  1475. name: key,
  1476. log: log
  1477. }))
  1478. })
  1479. emitter.on(events.end, done)
  1480. })
  1481. test('array event occurred once', () => {
  1482. assert.strictEqual(log.counts.array, 1)
  1483. })
  1484. test('number event occurred once', () => {
  1485. assert.strictEqual(log.counts.number, 1)
  1486. })
  1487. test('number event was dispatched correctly', () => {
  1488. assert.strictEqual(log.args.number[0][0], 0)
  1489. })
  1490. test('endArray event occurred once', () => {
  1491. assert.strictEqual(log.counts.endArray, 1)
  1492. })
  1493. test('end event occurred once', () => {
  1494. assert.strictEqual(log.counts.end, 1)
  1495. })
  1496. test('error event did not occur', () => {
  1497. assert.strictEqual(log.counts.error, 0)
  1498. })
  1499. test('dataError event did not occur', () => {
  1500. assert.strictEqual(log.counts.dataError, 0)
  1501. })
  1502. })
  1503. suite('two numbers inside array:', () => {
  1504. let stream, emitter
  1505. setup(done => {
  1506. stream = new Readable()
  1507. stream._read = () => {}
  1508. emitter = walk(stream)
  1509. stream.push('[1,2]')
  1510. stream.push(null)
  1511. Object.keys(events).forEach(key => {
  1512. emitter.on(events[key], spooks.fn({
  1513. name: key,
  1514. log: log
  1515. }))
  1516. })
  1517. emitter.on(events.end, done)
  1518. })
  1519. test('array event occurred once', () => {
  1520. assert.strictEqual(log.counts.array, 1)
  1521. })
  1522. test('number event occurred twice', () => {
  1523. assert.strictEqual(log.counts.number, 2)
  1524. })
  1525. test('number event was dispatched correctly first time', () => {
  1526. assert.strictEqual(log.args.number[0][0], 1)
  1527. })
  1528. test('number event was dispatched correctly second time', () => {
  1529. assert.strictEqual(log.args.number[1][0], 2)
  1530. })
  1531. test('endArray event occurred once', () => {
  1532. assert.strictEqual(log.counts.endArray, 1)
  1533. })
  1534. test('end event occurred once', () => {
  1535. assert.strictEqual(log.counts.end, 1)
  1536. })
  1537. test('error event did not occur', () => {
  1538. assert.strictEqual(log.counts.error, 0)
  1539. })
  1540. test('dataError event did not occur', () => {
  1541. assert.strictEqual(log.counts.dataError, 0)
  1542. })
  1543. })
  1544. suite('two numbers inside array with whitespace:', () => {
  1545. let stream, emitter
  1546. setup(done => {
  1547. stream = new Readable()
  1548. stream._read = () => {}
  1549. emitter = walk(stream)
  1550. stream.push('[ 1977 , -1977 ]')
  1551. stream.push(null)
  1552. Object.keys(events).forEach(key => {
  1553. emitter.on(events[key], spooks.fn({
  1554. name: key,
  1555. log: log
  1556. }))
  1557. })
  1558. emitter.on(events.end, done)
  1559. })
  1560. test('array event occurred once', () => {
  1561. assert.strictEqual(log.counts.array, 1)
  1562. })
  1563. test('number event occurred twice', () => {
  1564. assert.strictEqual(log.counts.number, 2)
  1565. })
  1566. test('number event was dispatched correctly first time', () => {
  1567. assert.strictEqual(log.args.number[0][0], 1977)
  1568. })
  1569. test('number event was dispatched correctly second time', () => {
  1570. assert.strictEqual(log.args.number[1][0], -1977)
  1571. })
  1572. test('endArray event occurred once', () => {
  1573. assert.strictEqual(log.counts.endArray, 1)
  1574. })
  1575. test('end event occurred once', () => {
  1576. assert.strictEqual(log.counts.end, 1)
  1577. })
  1578. test('error event did not occur', () => {
  1579. assert.strictEqual(log.counts.error, 0)
  1580. })
  1581. test('dataError event did not occur', () => {
  1582. assert.strictEqual(log.counts.dataError, 0)
  1583. })
  1584. })
  1585. suite('object inside object:', () => {
  1586. let stream, emitter
  1587. setup(done => {
  1588. stream = new Readable()
  1589. stream._read = () => {}
  1590. emitter = walk(stream)
  1591. stream.push('{"foo":{}}')
  1592. stream.push(null)
  1593. Object.keys(events).forEach(key => {
  1594. emitter.on(events[key], spooks.fn({
  1595. name: key,
  1596. log: log
  1597. }))
  1598. })
  1599. emitter.on(events.end, done)
  1600. })
  1601. test('object event occurred twice', () => {
  1602. assert.strictEqual(log.counts.object, 2)
  1603. })
  1604. test('property event occurred once', () => {
  1605. assert.strictEqual(log.counts.property, 1)
  1606. })
  1607. test('property event was dispatched correctly', () => {
  1608. assert.lengthOf(log.args.property[0], 1)
  1609. assert.strictEqual(log.args.property[0][0], 'foo')
  1610. })
  1611. test('endObject event occurred twice', () => {
  1612. assert.strictEqual(log.counts.endObject, 2)
  1613. })
  1614. test('end event occurred once', () => {
  1615. assert.strictEqual(log.counts.end, 1)
  1616. })
  1617. test('error event did not occur', () => {
  1618. assert.strictEqual(log.counts.error, 0)
  1619. })
  1620. test('dataError event did not occur', () => {
  1621. assert.strictEqual(log.counts.dataError, 0)
  1622. })
  1623. })
  1624. suite('array and object inside object:', () => {
  1625. let stream, emitter
  1626. setup(done => {
  1627. stream = new Readable()
  1628. stream._read = () => {}
  1629. emitter = walk(stream)
  1630. stream.push('{"wibble wobble":[],"jelly on the plate":{}}')
  1631. stream.push(null)
  1632. Object.keys(events).forEach(key => {
  1633. emitter.on(events[key], spooks.fn({
  1634. name: key,
  1635. log: log
  1636. }))
  1637. })
  1638. emitter.on(events.end, done)
  1639. })
  1640. test('object event occurred twice', () => {
  1641. assert.strictEqual(log.counts.object, 2)
  1642. })
  1643. test('property event occurred twice', () => {
  1644. assert.strictEqual(log.counts.property, 2)
  1645. })
  1646. test('property event was dispatched correctly first time', () => {
  1647. assert.strictEqual(log.args.property[0][0], 'wibble wobble')
  1648. })
  1649. test('property event was dispatched correctly second time', () => {
  1650. assert.strictEqual(log.args.property[1][0], 'jelly on the plate')
  1651. })
  1652. test('array event occurred once', () => {
  1653. assert.strictEqual(log.counts.array, 1)
  1654. })
  1655. test('endArray event occurred once', () => {
  1656. assert.strictEqual(log.counts.endArray, 1)
  1657. })
  1658. test('endObject event occurred twice', () => {
  1659. assert.strictEqual(log.counts.endObject, 2)
  1660. })
  1661. test('end event occurred once', () => {
  1662. assert.strictEqual(log.counts.end, 1)
  1663. })
  1664. test('error event did not occur', () => {
  1665. assert.strictEqual(log.counts.error, 0)
  1666. })
  1667. test('dataError event did not occur', () => {
  1668. assert.strictEqual(log.counts.dataError, 0)
  1669. })
  1670. })
  1671. suite('string, literal and number inside object with whitespace:', () => {
  1672. let stream, emitter
  1673. setup(done => {
  1674. stream = new Readable()
  1675. stream._read = () => {}
  1676. emitter = walk(stream)
  1677. stream.push(' { "foo" : "bar" ,\t"baz"\t:\tnull\t,\r\n"qux"\r\n:\r\n3.14159265359\r\n} ')
  1678. stream.push(null)
  1679. Object.keys(events).forEach(key => {
  1680. emitter.on(events[key], spooks.fn({
  1681. name: key,
  1682. log: log
  1683. }))
  1684. })
  1685. emitter.on(events.end, done)
  1686. })
  1687. test('object event occurred once', () => {
  1688. assert.strictEqual(log.counts.object, 1)
  1689. })
  1690. test('property event occurred three times', () => {
  1691. assert.strictEqual(log.counts.property, 3)
  1692. })
  1693. test('property event was dispatched correctly first time', () => {
  1694. assert.strictEqual(log.args.property[0][0], 'foo')
  1695. })
  1696. test('property event was dispatched correctly second time', () => {
  1697. assert.strictEqual(log.args.property[1][0], 'baz')
  1698. })
  1699. test('property event was dispatched correctly third time', () => {
  1700. assert.strictEqual(log.args.property[2][0], 'qux')
  1701. })
  1702. test('string event occurred once', () => {
  1703. assert.strictEqual(log.counts.string, 1)
  1704. })
  1705. test('string event was dispatched correctly', () => {
  1706. assert.strictEqual(log.args.string[0][0], 'bar')
  1707. })
  1708. test('literal event occurred once', () => {
  1709. assert.strictEqual(log.counts.literal, 1)
  1710. })
  1711. test('literal event was dispatched correctly', () => {
  1712. assert.isNull(log.args.literal[0][0])
  1713. })
  1714. test('number event occurred once', () => {
  1715. assert.strictEqual(log.counts.number, 1)
  1716. })
  1717. test('number event was dispatched correctly', () => {
  1718. assert.strictEqual(log.args.number[0][0], 3.14159265359)
  1719. })
  1720. test('endObject event occurred once', () => {
  1721. assert.strictEqual(log.counts.endObject, 1)
  1722. })
  1723. test('end event occurred once', () => {
  1724. assert.strictEqual(log.counts.end, 1)
  1725. })
  1726. test('error event did not occur', () => {
  1727. assert.strictEqual(log.counts.error, 0)
  1728. })
  1729. test('dataError event did not occur', () => {
  1730. assert.strictEqual(log.counts.dataError, 0)
  1731. })
  1732. })
  1733. suite('two objects inside object without comma:', () => {
  1734. let stream, emitter
  1735. setup(done => {
  1736. stream = new Readable()
  1737. stream._read = () => {}
  1738. emitter = walk(stream)
  1739. stream.push('{"foo":{}"bar":{}}')
  1740. stream.push(null)
  1741. Object.keys(events).forEach(key => {
  1742. emitter.on(events[key], spooks.fn({
  1743. name: key,
  1744. log: log
  1745. }))
  1746. })
  1747. emitter.on(events.end, done)
  1748. })
  1749. test('object event occurred three times', () => {
  1750. assert.strictEqual(log.counts.object, 3)
  1751. })
  1752. test('property event occurred twice', () => {
  1753. assert.strictEqual(log.counts.property, 2)
  1754. })
  1755. test('property event was dispatched correctly first time', () => {
  1756. assert.strictEqual(log.args.property[0][0], 'foo')
  1757. })
  1758. test('property event was dispatched correctly second time', () => {
  1759. assert.strictEqual(log.args.property[1][0], 'bar')
  1760. })
  1761. test('dataError event occurred once', () => {
  1762. assert.strictEqual(log.counts.dataError, 1)
  1763. })
  1764. test('dataError event was dispatched correctly', () => {
  1765. assert.strictEqual(log.args.dataError[0][0].actual, '"')
  1766. assert.strictEqual(log.args.dataError[0][0].expected, ',')
  1767. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  1768. assert.strictEqual(log.args.dataError[0][0].columnNumber, 10)
  1769. })
  1770. test('endObject event occurred three times', () => {
  1771. assert.strictEqual(log.counts.endObject, 3)
  1772. })
  1773. test('end event occurred once', () => {
  1774. assert.strictEqual(log.counts.end, 1)
  1775. })
  1776. })
  1777. suite('unquoted property:', () => {
  1778. let stream, emitter
  1779. setup(done => {
  1780. stream = new Readable()
  1781. stream._read = () => {}
  1782. emitter = walk(stream)
  1783. stream.push('{foo:{}}')
  1784. stream.push(null)
  1785. Object.keys(events).forEach(key => {
  1786. emitter.on(events[key], spooks.fn({
  1787. name: key,
  1788. log: log
  1789. }))
  1790. })
  1791. emitter.on(events.end, done)
  1792. })
  1793. test('object event occurred once', () => {
  1794. assert.strictEqual(log.counts.object, 1)
  1795. })
  1796. test('dataError event occurred once', () => {
  1797. assert.strictEqual(log.counts.dataError, 3)
  1798. })
  1799. test('dataError event was dispatched correctly first time', () => {
  1800. assert.strictEqual(log.args.dataError[0][0].actual, 'f')
  1801. assert.strictEqual(log.args.dataError[0][0].expected, '"')
  1802. assert.strictEqual(log.args.dataError[0][0].lineNumber, 1)
  1803. assert.strictEqual(log.args.dataError[0][0].columnNumber, 2)
  1804. })
  1805. test('dataError event was dispatched correctly second time', () => {
  1806. assert.strictEqual(log.args.dataError[1][0].actual, 'EOF')
  1807. assert.strictEqual(log.args.dataError[1][0].expected, '"')
  1808. assert.strictEqual(log.args.dataError[1][0].lineNumber, 1)
  1809. assert.strictEqual(log.args.dataError[1][0].columnNumber, 9)
  1810. })
  1811. test('dataError event was dispatched correctly third time', () => {
  1812. assert.strictEqual(log.args.dataError[2][0].actual, 'EOF')
  1813. assert.strictEqual(log.args.dataError[2][0].expected, '}')
  1814. assert.strictEqual(log.args.dataError[2][0].lineNumber, 1)
  1815. assert.strictEqual(log.args.dataError[2][0].columnNumber, 9)
  1816. })
  1817. test('end event occurred once', () => {
  1818. assert.strictEqual(log.counts.end, 1)
  1819. })
  1820. })
  1821. suite('duplicate property:', () => {
  1822. let stream, emitter
  1823. setup(done => {
  1824. stream = new Readable()
  1825. stream._read = () => {}
  1826. emitter = walk(stream)
  1827. // NOTE: RFC 7159 is wishy washy on the subject of duplicates:
  1828. //
  1829. // "The names within an object SHOULD be unique
  1830. //
  1831. // ...
  1832. //
  1833. // An object whose names are all unique is interoperable
  1834. // in the sense that all software implementations receiving
  1835. // that object will agree on the name/value mappings. When
  1836. // the names within an object are not unique, the behavior
  1837. // of software that receives such an object is unpredictable.
  1838. // Many implementations report the last name/value pair only.
  1839. // Other implementations report an error or fail to parse the
  1840. // object, and some implementations report all of the name/value
  1841. // pairs, including duplicates."
  1842. //
  1843. // https://tools.ietf.org/html/rfc7159#section-4
  1844. stream.push('{"foo":{},"foo":{}}')
  1845. stream.push(null)
  1846. Object.keys(events).forEach(key => {
  1847. emitter.on(events[key], spooks.fn({
  1848. name: key,
  1849. log: log
  1850. }))
  1851. })
  1852. emitter.on(events.end, done)
  1853. })
  1854. test('object event occurred three times', () => {
  1855. assert.strictEqual(log.counts.object, 3)
  1856. })
  1857. test('property event occurred twice', () => {
  1858. assert.strictEqual(log.counts.property, 2)
  1859. })
  1860. test('property event was dispatched correctly first time', () => {
  1861. assert.strictEqual(log.args.property[0][0], 'foo')
  1862. })
  1863. test('property event was dispatched correctly second time', () => {
  1864. assert.strictEqual(log.args.property[1][0], 'foo')
  1865. })
  1866. test('endObject event occurred three times', () => {
  1867. assert.strictEqual(log.counts.endObject, 3)
  1868. })
  1869. test('end event occurred once', () => {
  1870. assert.strictEqual(log.counts.end, 1)
  1871. })
  1872. test('error event did not occur', () => {
  1873. assert.strictEqual(log.counts.error, 0)
  1874. })
  1875. test('dataError event did not occur', () => {
  1876. assert.strictEqual(log.counts.dataError, 0)
  1877. })
  1878. })
  1879. suite('empty array containing whitespace:', () => {
  1880. let stream, emitter
  1881. setup(done => {
  1882. stream = new Readable()
  1883. stream._read = () => {}
  1884. emitter = walk(stream)
  1885. stream.push('[ ]')
  1886. stream.push(null)
  1887. Object.keys(events).forEach(key => {
  1888. emitter.on(events[key], spooks.fn({
  1889. name: key,
  1890. log: log
  1891. }))
  1892. })
  1893. emitter.on(events.end, done)
  1894. })
  1895. test('array event occurred once', () => {
  1896. assert.strictEqual(log.counts.array, 1)
  1897. })
  1898. test('endArray event occurred once', () => {
  1899. assert.strictEqual(log.counts.endArray, 1)
  1900. })
  1901. test('end event occurred once', () => {
  1902. assert.strictEqual(log.counts.end, 1)
  1903. })
  1904. test('error event did not occur', () => {
  1905. assert.strictEqual(log.counts.error, 0)
  1906. })
  1907. test('dataError event did not occur', () => {
  1908. assert.strictEqual(log.counts.dataError, 0)
  1909. })
  1910. })
  1911. suite('chunked empty array:', () => {
  1912. let stream, emitter
  1913. setup(done => {
  1914. stream = new Readable()
  1915. stream._read = () => {}
  1916. emitter = walk(stream)
  1917. stream.push('[')
  1918. Object.keys(events).forEach(key => {
  1919. emitter.on(events[key], spooks.fn({
  1920. name: key,
  1921. log: log
  1922. }))
  1923. })
  1924. emitter.on(events.end, done)
  1925. emitter.on(events.array, stream.push.bind(stream, ']'))
  1926. emitter.on(events.endArray, stream.push.bind(stream, null))
  1927. })
  1928. test('array event occurred once', () => {
  1929. assert.strictEqual(log.counts.array, 1)
  1930. })
  1931. test('endArray event occurred once', () => {
  1932. assert.strictEqual(log.counts.endArray, 1)
  1933. })
  1934. test('end event occurred once', () => {
  1935. assert.strictEqual(log.counts.end, 1)
  1936. })
  1937. test('error event did not occur', () => {
  1938. assert.strictEqual(log.counts.error, 0)
  1939. })
  1940. test('dataError event did not occur', () => {
  1941. assert.strictEqual(log.counts.dataError, 0)
  1942. })
  1943. })
  1944. suite('chunked empty object with whitespace:', () => {
  1945. let stream, emitter
  1946. setup(done => {
  1947. stream = new Readable()
  1948. stream._read = () => {}
  1949. emitter = walk(stream)
  1950. stream.push(' {')
  1951. Object.keys(events).forEach(key => {
  1952. emitter.on(events[key], spooks.fn({
  1953. name: key,
  1954. log: log
  1955. }))
  1956. })
  1957. emitter.on(events.end, done)
  1958. emitter.on(events.object, () => {
  1959. setTimeout(stream.push.bind(stream, ' }'), 20)
  1960. })
  1961. emitter.on(events.endObject, () => {
  1962. setTimeout(stream.push.bind(stream, null), 20)
  1963. })
  1964. })
  1965. test('object event occurred once', () => {
  1966. assert.strictEqual(log.counts.object, 1)
  1967. })
  1968. test('endObject event occurred once', () => {
  1969. assert.strictEqual(log.counts.endObject, 1)
  1970. })
  1971. test('end event occurred once', () => {
  1972. assert.strictEqual(log.counts.end, 1)
  1973. })
  1974. test('error event did not occur', () => {
  1975. assert.strictEqual(log.counts.error, 0)
  1976. })
  1977. test('dataError event did not occur', () => {
  1978. assert.strictEqual(log.counts.dataError, 0)
  1979. })
  1980. })
  1981. suite('chunked string:', () => {
  1982. let stream, emitter
  1983. setup(done => {
  1984. stream = new Readable()
  1985. stream._read = () => {}
  1986. emitter = walk(stream)
  1987. stream.push('"')
  1988. Object.keys(events).forEach(key => {
  1989. emitter.on(events[key], spooks.fn({
  1990. name: key,
  1991. log: log
  1992. }))
  1993. })
  1994. emitter.on(events.end, done)
  1995. emitter.on(events.string, () => {
  1996. setTimeout(stream.push.bind(stream, null), 20)
  1997. })
  1998. setTimeout(stream.push.bind(stream, '\\'), 20)
  1999. setTimeout(stream.push.bind(stream, 't\\u'), 40)
  2000. setTimeout(stream.push.bind(stream, '00'), 60)
  2001. setTimeout(stream.push.bind(stream, 'a0'), 80)
  2002. setTimeout(stream.push.bind(stream, '"'), 100)
  2003. })
  2004. test('string event occurred once', () => {
  2005. assert.strictEqual(log.counts.string, 1)
  2006. })
  2007. test('string event was dispatched correctly', () => {
  2008. assert.strictEqual(log.args.string[0][0], '\t\u00a0')
  2009. })
  2010. test('end event occurred once', () => {
  2011. assert.strictEqual(log.counts.end, 1)
  2012. })
  2013. test('error event did not occur', () => {
  2014. assert.strictEqual(log.counts.error, 0)
  2015. })
  2016. test('dataError event did not occur', () => {
  2017. assert.strictEqual(log.counts.dataError, 0)
  2018. })
  2019. })
  2020. suite('chunked number:', () => {
  2021. let stream, emitter
  2022. setup(done => {
  2023. stream = new Readable()
  2024. stream._read = () => {}
  2025. emitter = walk(stream)
  2026. stream.push('-')
  2027. Object.keys(events).forEach(key => {
  2028. emitter.on(events[key], spooks.fn({
  2029. name: key,
  2030. log: log
  2031. }))
  2032. })
  2033. emitter.on(events.end, done)
  2034. setTimeout(stream.push.bind(stream, '3'), 20)
  2035. setTimeout(stream.push.bind(stream, '.'), 40)
  2036. setTimeout(stream.push.bind(stream, '14159'), 60)
  2037. setTimeout(stream.push.bind(stream, '265359'), 80)
  2038. setTimeout(stream.push.bind(stream, 'e'), 100)
  2039. setTimeout(stream.push.bind(stream, '-'), 120)
  2040. setTimeout(stream.push.bind(stream, '7'), 140)
  2041. setTimeout(stream.push.bind(stream, null), 160)
  2042. })
  2043. test('number event occurred once', () => {
  2044. assert.strictEqual(log.counts.number, 1)
  2045. })
  2046. test('number event was dispatched correctly', () => {
  2047. assert.strictEqual(log.args.number[0][0], -3.14159265359e-7)
  2048. })
  2049. test('end event occurred once', () => {
  2050. assert.strictEqual(log.counts.end, 1)
  2051. })
  2052. test('error event did not occur', () => {
  2053. assert.strictEqual(log.counts.error, 0)
  2054. })
  2055. test('dataError event did not occur', () => {
  2056. assert.strictEqual(log.counts.dataError, 0)
  2057. })
  2058. })
  2059. suite('chunked literal:', () => {
  2060. let stream, emitter
  2061. setup(done => {
  2062. stream = new Readable()
  2063. stream._read = () => {}
  2064. emitter = walk(stream)
  2065. stream.push('n')
  2066. Object.keys(events).forEach(key => {
  2067. emitter.on(events[key], spooks.fn({
  2068. name: key,
  2069. log: log
  2070. }))
  2071. })
  2072. emitter.on(events.end, done)
  2073. setTimeout(stream.push.bind(stream, 'u'), 20)
  2074. setTimeout(stream.push.bind(stream, 'l'), 40)
  2075. setTimeout(stream.push.bind(stream, 'l'), 60)
  2076. setTimeout(stream.push.bind(stream, null), 80)
  2077. })
  2078. test('literal event occurred once', () => {
  2079. assert.strictEqual(log.counts.literal, 1)
  2080. })
  2081. test('literal event was dispatched correctly', () => {
  2082. assert.strictEqual(log.args.literal[0][0], null)
  2083. })
  2084. test('end event occurred once', () => {
  2085. assert.strictEqual(log.counts.end, 1)
  2086. })
  2087. test('error event did not occur', () => {
  2088. assert.strictEqual(log.counts.error, 0)
  2089. })
  2090. test('dataError event did not occur', () => {
  2091. assert.strictEqual(log.counts.dataError, 0)
  2092. })
  2093. })
  2094. suite('populated array with discard=1:', () => {
  2095. let stream, emitter
  2096. setup(done => {
  2097. stream = new Readable()
  2098. stream._read = () => {}
  2099. emitter = walk(stream, { discard: 1 })
  2100. stream.push(' ')
  2101. Object.keys(events).forEach(key => {
  2102. emitter.on(events[key], spooks.fn({
  2103. name: key,
  2104. log: log
  2105. }))
  2106. })
  2107. emitter.on(events.end, done)
  2108. emitter.on(events.array, () => {
  2109. stream.push(' ""')
  2110. })
  2111. emitter.on(events.string, () => {
  2112. stream.push(' ]')
  2113. })
  2114. emitter.on(events.endArray, () => {
  2115. stream.push(null)
  2116. })
  2117. setImmediate(stream.push.bind(stream, '['))
  2118. })
  2119. test('array event occurred once', () => {
  2120. assert.strictEqual(log.counts.array, 1)
  2121. })
  2122. test('string event was dispatched correctly', () => {
  2123. assert.strictEqual(log.args.string[0][0], "")
  2124. })
  2125. test('endArray event occurred once', () => {
  2126. assert.strictEqual(log.counts.endArray, 1)
  2127. })
  2128. test('end event occurred once', () => {
  2129. assert.strictEqual(log.counts.end, 1)
  2130. })
  2131. test('string event occurred once', () => {
  2132. assert.strictEqual(log.counts.string, 1)
  2133. })
  2134. test('error event did not occur', () => {
  2135. assert.strictEqual(log.counts.error, 0)
  2136. })
  2137. test('dataError event did not occur', () => {
  2138. assert.strictEqual(log.counts.dataError, 0)
  2139. })
  2140. })
  2141. suite('throw errors from event handlers:', () => {
  2142. let stream, emitter
  2143. setup(done => {
  2144. stream = new Readable()
  2145. stream._read = () => {}
  2146. emitter = walk(stream)
  2147. stream.push('[null,false,true,0,"",{"foo":"bar"}]')
  2148. stream.push(null)
  2149. Object.keys(events).forEach(key => {
  2150. const event = events[key]
  2151. emitter.on(event, spooks.fn({
  2152. name: key,
  2153. log: log
  2154. }))
  2155. if (event !== events.end) {
  2156. emitter.on(event, () => { throw 0 })
  2157. }
  2158. })
  2159. emitter.on(events.end, done)
  2160. })
  2161. test('array event occurred once', () => {
  2162. assert.strictEqual(log.counts.array, 1)
  2163. })
  2164. test('endArray event occurred once', () => {
  2165. assert.strictEqual(log.counts.endArray, 1)
  2166. })
  2167. test('literal event occurred three times', () => {
  2168. assert.strictEqual(log.counts.literal, 3)
  2169. })
  2170. test('number event occurred once', () => {
  2171. assert.strictEqual(log.counts.number, 1)
  2172. })
  2173. test('string event occurred twice', () => {
  2174. assert.strictEqual(log.counts.string, 2)
  2175. })
  2176. test('property event occurred once', () => {
  2177. assert.strictEqual(log.counts.property, 1)
  2178. })
  2179. test('object event occurred once', () => {
  2180. assert.strictEqual(log.counts.object, 1)
  2181. })
  2182. test('endObject event occurred once', () => {
  2183. assert.strictEqual(log.counts.endObject, 1)
  2184. })
  2185. test('error event occurred eleven times', () => {
  2186. assert.strictEqual(log.counts.error, 11)
  2187. })
  2188. test('end event occurred once', () => {
  2189. assert.strictEqual(log.counts.end, 1)
  2190. })
  2191. test('dataError event did not occur', () => {
  2192. assert.strictEqual(log.counts.dataError, 0)
  2193. })
  2194. })
  2195. suite('error occurs on stream:', () => {
  2196. let stream, emitter
  2197. setup(done => {
  2198. stream = new Readable()
  2199. stream._read = () => {}
  2200. emitter = walk(stream)
  2201. Object.keys(events).forEach(key => {
  2202. emitter.on(events[key], spooks.fn({
  2203. name: key,
  2204. log: log
  2205. }))
  2206. })
  2207. stream.emit('error', new Error('wibble'))
  2208. stream.push(null)
  2209. emitter.on(events.end, done)
  2210. })
  2211. test('error event occurred once', () => {
  2212. assert.strictEqual(log.counts.error, 1)
  2213. })
  2214. test('error event was dispatched correctly', () => {
  2215. assert.strictEqual(log.args.error[0][0].message, 'wibble')
  2216. assert.isUndefined(log.args.error[0][0].actual)
  2217. assert.isUndefined(log.args.error[0][0].expected)
  2218. assert.isUndefined(log.args.error[0][0].lineNumber)
  2219. assert.isUndefined(log.args.error[0][0].columnNumber)
  2220. })
  2221. test('end event occurred once', () => {
  2222. assert.strictEqual(log.counts.end, 1)
  2223. })
  2224. test('dataError event did not occur', () => {
  2225. assert.strictEqual(log.counts.dataError, 0)
  2226. })
  2227. })
  2228. suite('two values separated by newline:', () => {
  2229. let stream, emitter
  2230. setup(done => {
  2231. stream = new Readable()
  2232. stream._read = () => {}
  2233. emitter = walk(stream)
  2234. stream.push('[]\n"foo"')
  2235. stream.push(null)
  2236. Object.keys(events).forEach(key => {
  2237. emitter.on(events[key], spooks.fn({
  2238. name: key,
  2239. log: log
  2240. }))
  2241. })
  2242. emitter.on(events.end, done)
  2243. })
  2244. test('array event occurred once', () => {
  2245. assert.strictEqual(log.counts.array, 1)
  2246. })
  2247. test('endArray event occurred once', () => {
  2248. assert.strictEqual(log.counts.endArray, 1)
  2249. })
  2250. test('string event occurred once', () => {
  2251. assert.strictEqual(log.counts.string, 1)
  2252. })
  2253. test('dataError event occurred once', () => {
  2254. assert.strictEqual(log.counts.dataError, 1)
  2255. })
  2256. test('end event occurred once', () => {
  2257. assert.strictEqual(log.counts.end, 1)
  2258. })
  2259. test('endLine event did not occur', () => {
  2260. assert.strictEqual(log.counts.endLine, 0)
  2261. })
  2262. })
  2263. suite('two values separated by newline, ndjson=true:', () => {
  2264. let stream, emitter
  2265. setup(done => {
  2266. stream = new Readable()
  2267. stream._read = () => {}
  2268. emitter = walk(stream, { ndjson: true })
  2269. stream.push('[]\n"foo"')
  2270. stream.push(null)
  2271. Object.keys(events).forEach(key => {
  2272. emitter.on(events[key], spooks.fn({
  2273. name: key,
  2274. log: log
  2275. }))
  2276. })
  2277. emitter.on(events.end, done)
  2278. })
  2279. test('array event occurred once', () => {
  2280. assert.strictEqual(log.counts.array, 1)
  2281. })
  2282. test('endArray event occurred once', () => {
  2283. assert.strictEqual(log.counts.endArray, 1)
  2284. })
  2285. test('string event occurred once', () => {
  2286. assert.strictEqual(log.counts.string, 1)
  2287. })
  2288. test('endLine event occurred once', () => {
  2289. assert.strictEqual(log.counts.endLine, 1)
  2290. })
  2291. test('end event occurred once', () => {
  2292. assert.strictEqual(log.counts.end, 1)
  2293. })
  2294. test('error event did not occur', () => {
  2295. assert.strictEqual(log.counts.error, 0)
  2296. })
  2297. test('dataError event did not occur', () => {
  2298. assert.strictEqual(log.counts.dataError, 0)
  2299. })
  2300. })
  2301. suite('two values separated by newline, ndjson=true, with embedded newlines in a value:', () => {
  2302. let stream, emitter
  2303. setup(done => {
  2304. stream = new Readable()
  2305. stream._read = () => {}
  2306. emitter = walk(stream, { ndjson: true })
  2307. stream.push('[\n\n\n"foo"\n\n,\n"bar"]\n"baz"')
  2308. stream.push(null)
  2309. Object.keys(events).forEach(key => {
  2310. emitter.on(events[key], spooks.fn({
  2311. name: key,
  2312. log: log
  2313. }))
  2314. })
  2315. emitter.on(events.end, done)
  2316. })
  2317. test('array event occurred once', () => {
  2318. assert.strictEqual(log.counts.array, 1)
  2319. })
  2320. test('endArray event occurred once', () => {
  2321. assert.strictEqual(log.counts.endArray, 1)
  2322. })
  2323. test('string event occurred three times', () => {
  2324. assert.strictEqual(log.counts.string, 3)
  2325. })
  2326. test('endLine event occurred once', () => {
  2327. assert.strictEqual(log.counts.endLine, 1)
  2328. })
  2329. test('end event occurred once', () => {
  2330. assert.strictEqual(log.counts.end, 1)
  2331. })
  2332. test('error event did not occur', () => {
  2333. assert.strictEqual(log.counts.error, 0)
  2334. })
  2335. test('dataError event did not occur', () => {
  2336. assert.strictEqual(log.counts.dataError, 0)
  2337. })
  2338. })
  2339. suite('two values not separated by newline, ndjson=true:', () => {
  2340. let stream, emitter
  2341. setup(done => {
  2342. stream = new Readable()
  2343. stream._read = () => {}
  2344. emitter = walk(stream, { ndjson: true })
  2345. stream.push('[]"foo"')
  2346. stream.push(null)
  2347. Object.keys(events).forEach(key => {
  2348. emitter.on(events[key], spooks.fn({
  2349. name: key,
  2350. log: log
  2351. }))
  2352. })
  2353. emitter.on(events.end, done)
  2354. })
  2355. test('array event occurred once', () => {
  2356. assert.strictEqual(log.counts.array, 1)
  2357. })
  2358. test('endArray event occurred once', () => {
  2359. assert.strictEqual(log.counts.endArray, 1)
  2360. })
  2361. test('end event occurred once', () => {
  2362. assert.strictEqual(log.counts.end, 1)
  2363. })
  2364. test('dataError event occurred five times', () => {
  2365. assert.strictEqual(log.counts.dataError, 5)
  2366. })
  2367. test('string event did not occurr', () => {
  2368. assert.strictEqual(log.counts.string, 0)
  2369. })
  2370. test('endLine event did not occur', () => {
  2371. assert.strictEqual(log.counts.endLine, 0)
  2372. })
  2373. })
  2374. suite('two values separated by two newlines, ndjson=true:', () => {
  2375. let stream, emitter
  2376. setup(done => {
  2377. stream = new Readable()
  2378. stream._read = () => {}
  2379. emitter = walk(stream, { ndjson: true })
  2380. stream.push('[]\r\n\r\n"foo"')
  2381. stream.push(null)
  2382. Object.keys(events).forEach(key => {
  2383. emitter.on(events[key], spooks.fn({
  2384. name: key,
  2385. log: log
  2386. }))
  2387. })
  2388. emitter.on(events.end, done)
  2389. })
  2390. test('array event occurred once', () => {
  2391. assert.strictEqual(log.counts.array, 1)
  2392. })
  2393. test('endArray event occurred once', () => {
  2394. assert.strictEqual(log.counts.endArray, 1)
  2395. })
  2396. test('string event occurred once', () => {
  2397. assert.strictEqual(log.counts.string, 1)
  2398. })
  2399. test('endLine event occurred twice', () => {
  2400. assert.strictEqual(log.counts.endLine, 2)
  2401. })
  2402. test('end event occurred once', () => {
  2403. assert.strictEqual(log.counts.end, 1)
  2404. })
  2405. test('error event did not occur', () => {
  2406. assert.strictEqual(log.counts.error, 0)
  2407. })
  2408. test('dataError event did not occur', () => {
  2409. assert.strictEqual(log.counts.dataError, 0)
  2410. })
  2411. })
  2412. suite('chunked ndjson:', () => {
  2413. let stream, emitter
  2414. setup(done => {
  2415. stream = new Readable()
  2416. stream._read = () => {}
  2417. emitter = walk(stream, { ndjson: true })
  2418. stream.push('[]')
  2419. Object.keys(events).forEach(key => {
  2420. emitter.on(events[key], spooks.fn({
  2421. name: key,
  2422. log: log
  2423. }))
  2424. })
  2425. emitter.on(events.end, done)
  2426. setTimeout(stream.push.bind(stream, ' '), 20)
  2427. setTimeout(stream.push.bind(stream, '\n'), 40)
  2428. setTimeout(stream.push.bind(stream, ' '), 60)
  2429. setTimeout(stream.push.bind(stream, '"'), 80)
  2430. setTimeout(stream.push.bind(stream, 'foo"'), 100)
  2431. setTimeout(stream.push.bind(stream, null), 120)
  2432. })
  2433. test('array event occurred once', () => {
  2434. assert.strictEqual(log.counts.array, 1)
  2435. })
  2436. test('endArray event occurred once', () => {
  2437. assert.strictEqual(log.counts.endArray, 1)
  2438. })
  2439. test('endLine event occurred once', () => {
  2440. assert.strictEqual(log.counts.endLine, 1)
  2441. })
  2442. test('string event occurred once', () => {
  2443. assert.strictEqual(log.counts.string, 1)
  2444. })
  2445. test('end event occurred once', () => {
  2446. assert.strictEqual(log.counts.end, 1)
  2447. })
  2448. test('error event did not occur', () => {
  2449. assert.strictEqual(log.counts.error, 0)
  2450. })
  2451. test('dataError event did not occur', () => {
  2452. assert.strictEqual(log.counts.dataError, 0)
  2453. })
  2454. })
  2455. })
  2456. })