-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7259b5a
commit fca8f21
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
/* eslint-disable no-new */ | ||
|
||
import SafeBuffer from 'safe-buffer' | ||
import sinon from 'sinon'; | ||
import CCTalkParser from '../lib/parsers/cctalk'; | ||
import assert from 'assert'; | ||
import ccTalkParser from '../dist/cctalk'; | ||
|
||
const Buffer = SafeBuffer.Buffer; | ||
|
||
describe('ccTalkParser', () => { | ||
it('create an instance from class with `new` keyword', () => assert(new ccTalkParser() instanceof ccTalkParser)); | ||
it('create an instance from class without `new` keyword', () => assert(ccTalkParser() instanceof ccTalkParser)); | ||
}); | ||
|
||
describe('CCTalkParser', () => { | ||
it('emits data for a default length message', () => { | ||
const data = Buffer.from([2, 0, 1, 254, 217]); | ||
const spy = sinon.spy(); | ||
const parser = new CCTalkParser(); | ||
parser.on('data', spy); | ||
parser.write(data); | ||
assert.equal(spy.callCount, 1); | ||
assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 0, 1, 254, 217])); | ||
}); | ||
|
||
it('emits data for a 7 byte length message', () => { | ||
const parser = new CCTalkParser(); | ||
const spy = sinon.spy(); | ||
parser.on('data', spy); | ||
parser.write(Buffer.from([2, 2, 1, 254, 1, 1, 217])); | ||
assert.equal(spy.callCount, 1); | ||
assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 2, 1, 254, 1, 1, 217])); | ||
}); | ||
|
||
it('emits 2 times data first length 7 secund length 5', () => { | ||
const parser = new CCTalkParser(); | ||
const spy = sinon.spy(); | ||
parser.on('data', spy); | ||
parser.write(Buffer.from([2, 2, 1])); | ||
parser.write(Buffer.from([254, 1, 1])); | ||
parser.write(Buffer.from([217, 2])); | ||
parser.write(Buffer.from([0, 1, 254, 217])); | ||
assert.equal(spy.callCount, 2); | ||
assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 2, 1, 254, 1, 1, 217])); | ||
assert.deepEqual(spy.getCall(1).args[0], Buffer.from([2, 0, 1, 254, 217])); | ||
}); | ||
}); | ||
// 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])); |