npm run format:write

This commit is contained in:
2024-11-04 19:19:33 -06:00
parent 2453189b50
commit a995cf9cc9
3 changed files with 44 additions and 45 deletions
+5 -3
View File
@@ -7,10 +7,12 @@ export * from './message';
export * from './bundle'; export * from './bundle';
export function fromBuffer(bytes: Uint8Array): [OSCBundle | OSCMessage | undefined, Uint8Array | undefined] { export function fromBuffer(bytes: Uint8Array): [OSCBundle | OSCMessage | undefined, Uint8Array | undefined] {
if (bytes[0] === 47) { // starts with '/' if (bytes[0] === 47) {
// starts with '/'
return messageFromBuffer(bytes); return messageFromBuffer(bytes);
} else if (bytes[0] === 35) { // starts with '#' } else if (bytes[0] === 35) {
return bundleFromBuffer(bytes) // starts with '#'
return bundleFromBuffer(bytes);
} else { } else {
throw new Error('bytes do not look like an OSC message or bundle'); throw new Error('bytes do not look like an OSC message or bundle');
} }
+2 -2
View File
@@ -28,14 +28,14 @@ const tests = [
]), ]),
expected: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }, expected: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },
}, },
] ];
describe('OSC Bytes Decoding', () => { describe('OSC Bytes Decoding', () => {
tests.forEach((bytesTest) => { tests.forEach((bytesTest) => {
it(bytesTest.description, () => { it(bytesTest.description, () => {
const [decoded, remainingBytes] = osc.fromBuffer(bytesTest.bytes); const [decoded, remainingBytes] = osc.fromBuffer(bytesTest.bytes);
deepEqual(decoded, bytesTest.expected); deepEqual(decoded, bytesTest.expected);
equal(remainingBytes.length, 0) equal(remainingBytes.length, 0);
}); });
}); });
}); });
+1 -4
View File
@@ -155,9 +155,7 @@ const badTests = [
}, },
{ {
description: 'float64 missing bytes', description: 'float64 missing bytes',
bytes: new Uint8Array([ bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9]),
47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9,
]),
throwsMessage: { name: /^Error$/, message: /not enough bytes/ }, throwsMessage: { name: /^Error$/, message: /not enough bytes/ },
}, },
{ {
@@ -170,7 +168,6 @@ const badTests = [
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22]), bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22]),
throwsMessage: { name: /^Error$/, message: /must be at least/ }, throwsMessage: { name: /^Error$/, message: /must be at least/ },
}, },
]; ];
describe('OSC Message Decoding Pass', () => { describe('OSC Message Decoding Pass', () => {