diff --git a/src/index.js b/src/index.js index 6aaea20..a1eea4c 100644 --- a/src/index.js +++ b/src/index.js @@ -90,13 +90,13 @@ export class RawProto { this.choices = choices } - query(path, choices, prefix = '') { + query(path, prefix = '') { if (!this.tree) { this.offset = 0 this.tree = this.readMessage() this.offset = 0 } - return query(this.tree, path, choices || this.choices || {}, prefix) + return query(this.tree, path, this.choices, prefix) } // read a VARINT from buffer, at offset diff --git a/test/query.test.js b/test/query.test.js index dcd6740..0474842 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -12,14 +12,6 @@ test('A Simple Message', () => { expect(query(tree, '1:uint')).toEqual([150]) }) -test('A Simple Message: RawProto.query', () => { - /* - 1: 150 - */ - const tree = new RawProto([0x08, 0x96, 0x01]) - expect(tree.query('1:uint')).toEqual([150]) -}) - test('A Simple Message: choices', () => { /* 1: 150 @@ -36,6 +28,25 @@ test('A Simple Message: choices & prefix', () => { expect(query(tree, '1', { 3.1: 'uint' }, '3')).toEqual([150]) }) +// test same stuff using RawProto.query +test('A Simple Message: RawProto.query', () => { + /* + 3: {1: 150} + */ + const tree = new RawProto([0x1a, 0x03, 0x08, 0x96, 0x01], { 3.1: 'uint' }) + // tpye in query + expect(tree.query('3.1:uint')).toEqual([150]) + + // use choices + expect(tree.query('3.1')).toEqual([150]) + + // use prefix + // expect(tree.query('1:uint', '3')).toEqual([150]) + + // use choices & prefix + expect(tree.query('1', '3')).toEqual([150]) +}) + test('Length-Delimited Records', () => { /* 2: {"testing"}