Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <vmg@strn.cat>
  • Loading branch information
vmg committed Feb 11, 2025
1 parent 9070230 commit b6aeff3
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions go/tools/asthelpergen/integration/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ limitations under the License.

package integration

import "encoding/binary"

// This file is a copy of the file go/vt/sqlparser/paths.go
// We need it here to be able to test the path accumulation of the rewriter

type ASTPath string

func AddStep(path ASTPath, step ASTStep) ASTPath {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(step))
return path + ASTPath(b)
}

func AddStepWithSliceIndex(path ASTPath, step ASTStep, idx int) ASTPath {
if idx < 255 {
// 2 bytes for step code + 1 byte for index
b := make([]byte, 3)
binary.BigEndian.PutUint16(b[:2], uint16(step))
b[2] = byte(idx)
return path + ASTPath(b)
// nextPathOffset is an implementation of binary.Uvarint that works directly on
// the ASTPath without having to cast and allocate a byte slice
func (path ASTPath) nextPathOffset() (uint64, int) {
var x uint64
var s uint
for i := 0; i < len(path); i++ {
b := path[i]
if b < 0x80 {
return x | uint64(b)<<s, i + 1
}
x |= uint64(b&0x7f) << s
s += 7
}
return 0, 0
}

// 2 bytes for step code + 4 byte for index
b := make([]byte, 6)
longStep := step + 1
binary.BigEndian.PutUint16(b[:2], uint16(longStep))
binary.BigEndian.PutUint32(b[2:], uint32(idx))
return path + ASTPath(b)
func (path ASTPath) nextPathStep() ASTStep {
_ = path[1] // bounds check hint to compiler; see golang.org/issue/14808
return ASTStep(uint16(path[1]) | uint16(path[0])<<8)
}

0 comments on commit b6aeff3

Please sign in to comment.