Skip to content

Commit

Permalink
better matching README
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed May 3, 2024
1 parent 82b9be8 commit 3bea774
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"}
Expand Down

0 comments on commit 3bea774

Please sign in to comment.