remove Buffer from message decode tests

This commit is contained in:
2024-10-10 16:59:44 -05:00
parent 7a07f5d815
commit 287685a095
+21 -15
View File
@@ -5,47 +5,53 @@ const osc = require('../dist/index');
const tests = [
{
description: 'simple address no args',
bytes: Buffer.from('2f68656c6c6f00002c000000', 'hex'),
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 0, 0, 0]),
expected: { address: '/hello', args: [] },
},
{
description: 'simple address string arg',
bytes: Buffer.from('2f68656c6c6f00002c7300006172673100000000', 'hex'),
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 115, 0, 0, 97, 114, 103, 49, 0, 0, 0, 0]),
expected: { address: '/hello', args: [{ type: 's', value: 'arg1' }] },
},
{
description: 'simple address integer arg',
bytes: Buffer.from('2f68656c6c6f00002c69000000000023', 'hex'),
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 105, 0, 0, 0, 0, 0, 35]),
expected: { address: '/hello', args: [{ type: 'i', value: 35 }] },
},
{
description: 'simple address float arg',
bytes: Buffer.from('2f68656c6c6f00002c660000420a0000', 'hex'),
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 102, 0, 0, 66, 10, 0, 0]),
expected: { address: '/hello', args: [{ type: 'f', value: 34.5 }] },
},
{
description: 'simple address blob arg',
bytes: Buffer.from('2f68656c6c6f00002c62000000000004626c6f62', 'hex'),
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 98, 0, 0, 0, 0, 0, 4, 98, 108, 111, 98]),
expected: { address: '/hello', args: [{ type: 'b', value: new TextEncoder().encode('blob') }] },
},
{
description: 'simple address True arg',
bytes: Buffer.from('2f68656c6c6f00002c540000', 'hex'),
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 84, 0, 0]),
expected: { address: '/hello', args: [{ type: 'T', value: true }] },
},
{
description: 'simple address False arg',
bytes: Buffer.from('2f68656c6c6f00002c460000', 'hex'),
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 70, 0, 0]),
expected: { address: '/hello', args: [{ type: 'F', value: false }] },
},
{
description: 'osc 1.0 spec example 1',
bytes: Buffer.from('2f6f7363696c6c61746f722f342f6672657175656e6379002c66000043dc0000', 'hex'),
bytes: new Uint8Array([
47, 111, 115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52, 47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0, 44,
102, 0, 0, 67, 220, 0, 0,
]),
expected: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },
},
{
description: 'osc 1.0 spec example 2',
bytes: Buffer.from('2f666f6f000000002c69697366660000000003e8ffffffff68656c6c6f0000003f9df3b640b5b22d', 'hex'),
bytes: new Uint8Array([
47, 102, 111, 111, 0, 0, 0, 0, 44, 105, 105, 115, 102, 102, 0, 0, 0, 0, 3, 232, 255, 255, 255, 255, 104, 101, 108,
108, 111, 0, 0, 0, 63, 157, 243, 182, 64, 181, 178, 45,
]),
expected: {
address: '/foo',
args: [
@@ -71,7 +77,7 @@ describe('OSC Message Decoding', () => {
it('bad address', () => {
throws(
() => {
osc.messageFromBuffer(Buffer.from('68656c6c6f00002c660000420a0000', 'hex'));
osc.messageFromBuffer(new Uint8Array([0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x66,0x00,0x00,0x42,0x0a,0x00,0x00]));
},
{ name: /^Error$/, message: /must start with/ }
);
@@ -80,7 +86,7 @@ describe('OSC Message Decoding', () => {
it('bad type string', () => {
throws(
() => {
osc.messageFromBuffer(Buffer.from('2f68656c6c6f000066000000420a00', 'hex'));
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x66,0x00,0x00,0x00,0x42,0x0a,0x00]));
},
{ name: /^Error$/, message: /type string must start with/ }
);
@@ -89,7 +95,7 @@ describe('OSC Message Decoding', () => {
it('unknown type', () => {
throws(
() => {
osc.messageFromBuffer(Buffer.from('2f68656c6c6f00002c7a0000420a0000', 'hex'));
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x7a,0x00,0x00,0x42,0x0a,0x00,0x00]));
},
{ name: /^Error$/, message: /unknown/ }
);
@@ -98,7 +104,7 @@ describe('OSC Message Decoding', () => {
it('float arg missing bytes', () => {
throws(
() => {
osc.messageFromBuffer(Buffer.from('2f68656c6c6f00002c660000420a00', 'hex'));
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x66,0x00,0x00,0x42,0x0a,0x00]));
},
{ name: /^Error$/, message: /not enough bytes/ }
);
@@ -107,7 +113,7 @@ describe('OSC Message Decoding', () => {
it('int arg missing bytes', () => {
throws(
() => {
osc.messageFromBuffer(Buffer.from('2f68656c6c6f00002c690000000000', 'hex'));
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x69,0x00,0x00,0x00,0x00,0x00]));
},
{ name: /^Error$/, message: /not enough bytes/ }
);
@@ -116,7 +122,7 @@ describe('OSC Message Decoding', () => {
it('blob bytes too small', () => {
throws(
() => {
osc.messageFromBuffer(Buffer.from('2f68656c6c6f00002c62000000000004626c6f', 'hex'));
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x62,0x00,0x00,0x00,0x00,0x00,0x04,0x62,0x6c,0x6f]));
},
{ name: /^Error$/, message: /not enough bytes/ }
);