mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-05 15:33:59 +00:00
cd913fc144
* small `strict` improvements * fix type * use isObject
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { stringToOSCArgs } from '../oscArgParser.js';
|
|
|
|
describe('test stringToOSCArgs()', () => {
|
|
it('all types', () => {
|
|
const test = 'test 1111 0.1111 TRUE FALSE';
|
|
const expected = [
|
|
{ type: 'string', value: 'test' },
|
|
{ type: 'integer', value: 1111 },
|
|
{ type: 'float', value: 0.1111 },
|
|
{ type: 'T', value: true },
|
|
{ type: 'F', value: false },
|
|
];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
|
|
it('empty is nothing', () => {
|
|
const test = undefined;
|
|
const expected: any[] = [];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
|
|
it('empty is nothing', () => {
|
|
const test = '';
|
|
const expected: any[] = [];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
|
|
it('1 space is nothing', () => {
|
|
const test = ' ';
|
|
const expected: any[] = [];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
|
|
it('keep other types in strings', () => {
|
|
const test = 'test "1111" "0.1111" "TRUE" "FALSE"';
|
|
const expected = [
|
|
{ type: 'string', value: 'test' },
|
|
{ type: 'string', value: '1111' },
|
|
{ type: 'string', value: '0.1111' },
|
|
{ type: 'string', value: 'TRUE' },
|
|
{ type: 'string', value: 'FALSE' },
|
|
];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
|
|
it('keep spaces in quoted strings', () => {
|
|
const test = '"test space" 1111 0.1111 TRUE FALSE';
|
|
const expected = [
|
|
{ type: 'string', value: 'test space' },
|
|
{ type: 'integer', value: 1111 },
|
|
{ type: 'float', value: 0.1111 },
|
|
{ type: 'T', value: true },
|
|
{ type: 'F', value: false },
|
|
];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
|
|
it('keep spaces escaped quotes', () => {
|
|
const test = '"test \\" space" 1111 0.1111 TRUE FALSE';
|
|
const expected = [
|
|
{ type: 'string', value: 'test " space' },
|
|
{ type: 'integer', value: 1111 },
|
|
{ type: 'float', value: 0.1111 },
|
|
{ type: 'T', value: true },
|
|
{ type: 'F', value: false },
|
|
];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
|
|
it('2 spaces', () => {
|
|
const test = '1111 0.1111 TRUE FALSE';
|
|
const expected = [
|
|
{ type: 'integer', value: 1111 },
|
|
{ type: 'float', value: 0.1111 },
|
|
{ type: 'T', value: true },
|
|
{ type: 'F', value: false },
|
|
];
|
|
expect(stringToOSCArgs(test)).toStrictEqual(expected);
|
|
});
|
|
});
|