cabana/src/__tests__/panda/panda.test.js

23 lines
664 B
JavaScript
Raw Normal View History

2017-12-12 19:27:20 -07:00
import Panda from "../../api/panda";
2017-08-03 15:41:52 -06:00
function arrayBufferFromHex(hex) {
2017-12-12 19:27:20 -07:00
const buffer = Buffer.from(hex, "hex");
const arrayBuffer = new ArrayBuffer(buffer.length);
const view = new Uint8Array(arrayBuffer);
for (let i = 0; i < buffer.length; i++) {
view[i] = buffer[i];
}
return arrayBuffer;
2017-08-03 15:41:52 -06:00
}
2017-12-12 19:27:20 -07:00
test("parseCanBuffer correctly parses a message", () => {
const panda = new Panda();
// 16 byte buffer
2017-08-03 15:41:52 -06:00
2017-12-12 19:27:20 -07:00
const arrayBuffer = arrayBufferFromHex("abababababababababababababababab");
2017-08-03 15:41:52 -06:00
2017-12-12 19:27:20 -07:00
const messages = panda.parseCanBuffer(arrayBuffer);
expect(messages.length).toEqual(1);
expect(messages[0]).toEqual([1373, 43947, "abababababababab", 10]);
2017-08-03 15:41:52 -06:00
});