initial, start porting Python MeterbusLib to node
This commit is contained in:
44
src/meterbus.test.ts
Normal file
44
src/meterbus.test.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import {MeterbusLib} from './meterbus'
|
||||
|
||||
import * as mocha from 'mocha'
|
||||
import * as chai from 'chai'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('The Meterbus Library', () => {
|
||||
it('should store hexString', () => {
|
||||
const telegram = new MeterbusLib.Telegram()
|
||||
telegram.fromHexString("01 02 03")
|
||||
expect(telegram.hexString).to.equal("01 02 03")
|
||||
})
|
||||
it('should parse the hexString into the telegram array', () => {
|
||||
const telegram = new MeterbusLib.Telegram()
|
||||
telegram.fromHexString("01 02 03")
|
||||
expect(telegram.telegram).to.deep.equal([1, 2, 3])
|
||||
})
|
||||
it('should detect a control frame', () => {
|
||||
const telegram = new MeterbusLib.Telegram()
|
||||
telegram.fromHexString("68 03")
|
||||
telegram.parse()
|
||||
expect(telegram.frame).instanceof(MeterbusLib.ControlFrame)
|
||||
})
|
||||
it('should detect a short frame', () => {
|
||||
const telegram = new MeterbusLib.Telegram()
|
||||
telegram.fromHexString("10")
|
||||
telegram.parse()
|
||||
expect(telegram.frame).instanceof(MeterbusLib.ShortFrame)
|
||||
})
|
||||
it('should detect a long frame', () => {
|
||||
const telegram = new MeterbusLib.Telegram()
|
||||
telegram.fromHexString("68 10")
|
||||
telegram.parse()
|
||||
expect(telegram.frame).instanceof(MeterbusLib.LongFrame)
|
||||
})
|
||||
it('should detect a single char frame', () => {
|
||||
const telegram = new MeterbusLib.Telegram()
|
||||
telegram.fromHexString("e5")
|
||||
telegram.parse()
|
||||
expect(telegram.frame).instanceof(MeterbusLib.SingleCharFrame)
|
||||
})
|
||||
|
||||
})
|
Reference in New Issue
Block a user