it('should parse negative floats', () => { let literal = Parser.parse('-1.1', { type }); expect(literal.output.getType()).to.equal(Scalar.Type.V_FLOAT); expect(literal.output.getVFloat()).to.equal(-1.1); literal = Parser.parse('-1.1111111', { type }); expect(literal.output.getType()).to.equal(Scalar.Type.V_FLOAT); expect(literal.output.getVFloat()).to.equal(-1.1111111); });
it('should parse booleans', () => { let literal = Parser.parse('true', { type }); expect(literal.output.getType()).to.equal(Scalar.Type.V_BOOL); expect(literal.output.getVBool()).to.equal(true); literal = Parser.parse('false', { type }); expect(literal.output.getType()).to.equal(Scalar.Type.V_BOOL); expect(literal.output.getVBool()).to.equal(false); });
it('should not loose precision for big numbers', () => { let overflow = Number.MAX_SAFE_INTEGER + 1; let literal = Parser.parse(`${overflow}`, { type }); expect(literal.output.getType()).to.equal(Scalar.Type.V_STRING); /* eslint-disable node/no-deprecated-api */ expect(new Buffer(literal.output.getVString().getValue()).toString()).to.equal(`${overflow}`); /* eslint-enable node/no-deprecated-api */ overflow = Number.MIN_SAFE_INTEGER - 1; literal = Parser.parse(`${overflow}`, { type }); expect(literal.output.getType()).to.equal(Scalar.Type.V_STRING); /* eslint-disable node/no-deprecated-api */ expect(new Buffer(literal.output.getVString().getValue()).toString()).to.equal(`${overflow}`); /* eslint-enable node/no-deprecated-api */ });
it('should parse single-quoted strings', () => { const literal = Parser.parse("'bar'", { type }); expect(literal.output.getType()).to.equal(Scalar.Type.V_STRING); /* eslint-disable node/no-deprecated-api */ expect(new Buffer(literal.output.getVString().getValue()).toString()).to.equal('bar'); /* eslint-enable node/no-deprecated-api */ });
expect(() => Parser.parse("doc->'$.foo'")).to.throw();
expect(() => Parser.parse('[<"foo", 1>]')).to.throw();
expect(() => Parser.parse('$**.bar()')).to.throw();
expect(() => Parser.parse('foo[*]."bar"')).to.throw();
expect(() => Parser.parse('$.**')).to.throw();
expect(() => Parser.parse('_**[*]_.**._')).to.throw();
expect(() => Parser.parse('$.a[*].z', options)).to.throw();
expect(() => Parser.parse('$.a[0].b[0]', options)).to.throw();
expect(() => Parser.parse('$ = {"a":1}', options)).to.throw();
expect(() => Parser.parse('$.foo.bar[*]', options)).to.throw();
expect(() => Parser.parse('_**[*]._**._', options)).to.throw();
expect(() => Parser.parse('.doc')).to.throw();
expect(() => Parser.parse('**foo')).to.throw();
expect(() => Parser.parse('$."foo bar"."baz**" = $', options)).to.throw();
expect(() => Parser.parse('$.foo[**]')).to.throw();
expect(() => Parser.parse('$.foo**.bar', options)).to.throw();
expect(() => Parser.parse('$.foo..bar')).to.throw();
expect(() => Parser.parse('$."foo bar"**.baz', options)).to.throw();
expect(() => Parser.parse('"foo".bar')).to.throw();
expect(() => Parser.parse('$."foo."**.".bar"', options)).to.throw();
expect(() => Parser.parse('[<foo, bar>]')).to.throw();
expect(() => Parser.parse('$.""', options)).to.throw();
expect(() => Parser.parse('{<foobar>}')).to.throw();
expect(() => Parser.parse('$**[0]', options)).to.throw();
expect(() => Parser.parse("foo.bar->'$.foo'")).to.throw();
expect(() => Parser.parse('$.a**.foo', options)).to.throw();