UNPKG

@foxglove/omgidl-parser

Version:

Parse OMG IDL to flattened definitions for serialization

70 lines (64 loc) 1.78 kB
import { parseIDLToAST } from "./parseIDLToAST"; describe("Unsupported IDL grammar features", () => { /**************** Not yet supported */ it("cannot parse leading ::", () => { const msgDef = ` typedef float coord[2]; module msg { struct Point { ::coord loc; coord loc2; }; }; `; expect(() => parseIDLToAST(msgDef)).toThrow(/unexpected : token/i); }); it("fails forward struct declarations", () => { const msgDef = ` struct Foo; typedef Foo fooArray[5]; struct Foo { uint32 a; }; `; expect(() => parseIDLToAST(msgDef)).toThrow(); }); it("cannot parse wide string literals", () => { const msgDef = ` const wstring WSTRING_CONSTANT = L"wstring_value"; `; expect(() => parseIDLToAST(msgDef)).toThrow(); }); it("cannot properly parse octal literals", () => { const msgDef = ` const short SHORT_CONSTANT = 014; `; expect(parseIDLToAST(msgDef)).toEqual([ { name: "SHORT_CONSTANT", declarator: "const", isConstant: true, isComplex: false, type: "short", // This should be 12, but the parser doesn't support octal literals value: 14, valueText: "014", }, ]); }); it("cannot parse escape sequence character literals", () => { const msgDef = ` const short SHORT_CONSTANT = \n `; expect(() => parseIDLToAST(msgDef)).toThrow(); }); it.each(["+", "-", "*", "/", "%", "<<", ">>", "|", "&", "^"])( "cannot parse constant expression: %s", (operator) => { const msgDef = ` const short SHORT_CONSTANT = 1 ${operator} 2; `; expect(() => parseIDLToAST(msgDef)).toThrow(); }, ); });