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`.
This commit is contained in:
arve0 2016-07-28 13:32:14 +02:00
parent d0c64555c0
commit 5249f5c02b

View file

@ -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');