|
| 1 | +'use strict'; |
| 2 | +/* eslint-disable no-new */ |
| 3 | + |
| 4 | +const Buffer = require('safe-buffer').Buffer; |
| 5 | +const sinon = require('sinon'); |
| 6 | +const CCTalkParser = require('../lib/parsers/cctalk'); |
| 7 | + |
| 8 | +describe('CCTalkParser', () => { |
| 9 | + it('emits data for a default length message', () => { |
| 10 | + const data = Buffer.from([2, 0, 1, 254, 217]); |
| 11 | + const spy = sinon.spy(); |
| 12 | + const parser = new CCTalkParser(); |
| 13 | + parser.on('data', spy); |
| 14 | + parser.write(data); |
| 15 | + assert.equal(spy.callCount, 1); |
| 16 | + assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 0, 1, 254, 217])); |
| 17 | + }); |
| 18 | + |
| 19 | + it('emits data for a 7 byte length message', () => { |
| 20 | + const parser = new CCTalkParser(); |
| 21 | + const spy = sinon.spy(); |
| 22 | + parser.on('data', spy); |
| 23 | + parser.write(Buffer.from([2, 2, 1, 254, 1, 1, 217])); |
| 24 | + assert.equal(spy.callCount, 1); |
| 25 | + assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 2, 1, 254, 1, 1, 217])); |
| 26 | + }); |
| 27 | + |
| 28 | + it('emits 2 times data first length 7 secund length 5', () => { |
| 29 | + const parser = new CCTalkParser(); |
| 30 | + const spy = sinon.spy(); |
| 31 | + parser.on('data', spy); |
| 32 | + parser.write(Buffer.from([2, 2, 1])); |
| 33 | + parser.write(Buffer.from([254, 1, 1])); |
| 34 | + parser.write(Buffer.from([217, 2])); |
| 35 | + parser.write(Buffer.from([0, 1, 254, 217])); |
| 36 | + assert.equal(spy.callCount, 2); |
| 37 | + assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 2, 1, 254, 1, 1, 217])); |
| 38 | + assert.deepEqual(spy.getCall(1).args[0], Buffer.from([2, 0, 1, 254, 217])); |
| 39 | + }); |
| 40 | +}); |
| 41 | +// TODO: parser.write(Buffer.from([2, 2, 1, 254, 1, 1, 217, 2, 0, 1, 254, 217, 2, 2, 1, 251, 1, 1, 217, 2, 2, 1, 252, 1, 1, 217, 2, 0, 1, 253, 217])); |
0 commit comments