11cb0ef41Sopenharmony_civar stream = require('stream'); 21cb0ef41Sopenharmony_civar JsonParse = require('../jsonparse'); 31cb0ef41Sopenharmony_civar test = require('tape'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_citest('can handle large tokens without running out of memory', function (t) { 61cb0ef41Sopenharmony_ci var parser = new JsonParse(); 71cb0ef41Sopenharmony_ci var chunkSize = 1024; 81cb0ef41Sopenharmony_ci var chunks = 1024 * 200; // 200mb 91cb0ef41Sopenharmony_ci var quote = Buffer.from ? Buffer.from('"') : new Buffer('"'); 101cb0ef41Sopenharmony_ci t.plan(1); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci parser.onToken = function (type, value) { 131cb0ef41Sopenharmony_ci t.equal(value.length, chunkSize * chunks, 'token should be size of input json'); 141cb0ef41Sopenharmony_ci t.end(); 151cb0ef41Sopenharmony_ci }; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci parser.write(quote); 181cb0ef41Sopenharmony_ci for (var i = 0; i < chunks; ++i) { 191cb0ef41Sopenharmony_ci var buf = Buffer.alloc ? Buffer.alloc(chunkSize) : new Buffer(chunkSize); 201cb0ef41Sopenharmony_ci buf.fill('a'); 211cb0ef41Sopenharmony_ci parser.write(buf); 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci parser.write(quote); 241cb0ef41Sopenharmony_ci}); 25