From 5249f5c02b79c8bb320bb380f31770820fc24a10 Mon Sep 17 00:00:00 2001 From: arve0 Date: Thu, 28 Jul 2016 13:32:14 +0200 Subject: [PATCH] parsers.byteDelimiter: add test, emit only on following delimiters Example: ``` var parser = byteDelimiter([0,0]); parser(emit, new Buffer('\0hello\0world\0\0'); ``` Expected: `emit` should be called once, upon `\0\0` with whole string. What happens: `emit` is called twice, with `\0hello\0` and `world\0\0`. --- test/parsers.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/parsers.js b/test/parsers.js index 96db441..3034316 100644 --- a/test/parsers.js +++ b/test/parsers.js @@ -70,6 +70,14 @@ describe('parsers', function() { assert.equal(spy.callCount, 3); }); + it('should only emit if delimiters are strictly in row', function() { + var data = new Buffer('\0Hello\0World\0\0'); + var parser = parsers.byteDelimiter([0, 0]); + var spy = sinon.spy(); + parser({ emit: spy }, data); + assert.equal(spy.callCount, 1); + }); + it('continues looking for delimiters in the next buffers', function() { var data1 = new Buffer('This could be\0\0binary '); var data2 = new Buffer('data\0\0sent from a Moteino\0\0');