initial, start porting Python MeterbusLib to node

This commit is contained in:
Wolfgang Hottgenroth
2017-08-09 14:45:17 +02:00
commit d1c969a793
12 changed files with 221 additions and 0 deletions

44
src/meterbus.test.ts Normal file
View 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)
})
})