mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
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:
parent
d0c64555c0
commit
5249f5c02b
1 changed files with 8 additions and 0 deletions
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue