gofmt pass
This commit is contained in:
@@ -97,4 +97,3 @@ func TestLexSpace(t *testing.T) {
|
||||
token{Position{1, 12}, tokenEOF, ""},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+7
-8
@@ -1,11 +1,10 @@
|
||||
package jpath
|
||||
|
||||
import (
|
||||
. "github.com/pelletier/go-toml"
|
||||
"fmt"
|
||||
. "github.com/pelletier/go-toml"
|
||||
)
|
||||
|
||||
|
||||
// base match
|
||||
type matchBase struct {
|
||||
next PathFn
|
||||
@@ -44,7 +43,7 @@ type matchKeyFn struct {
|
||||
}
|
||||
|
||||
func newMatchKeyFn(name string) *matchKeyFn {
|
||||
return &matchKeyFn{ Name: name }
|
||||
return &matchKeyFn{Name: name}
|
||||
}
|
||||
|
||||
func (f *matchKeyFn) Call(node interface{}, ctx *queryContext) {
|
||||
@@ -63,7 +62,7 @@ type matchIndexFn struct {
|
||||
}
|
||||
|
||||
func newMatchIndexFn(idx int) *matchIndexFn {
|
||||
return &matchIndexFn{ Idx: idx }
|
||||
return &matchIndexFn{Idx: idx}
|
||||
}
|
||||
|
||||
func (f *matchIndexFn) Call(node interface{}, ctx *queryContext) {
|
||||
@@ -81,7 +80,7 @@ type matchSliceFn struct {
|
||||
}
|
||||
|
||||
func newMatchSliceFn(start, end, step int) *matchSliceFn {
|
||||
return &matchSliceFn{ Start: start, End: end, Step: step }
|
||||
return &matchSliceFn{Start: start, End: end, Step: step}
|
||||
}
|
||||
|
||||
func (f *matchSliceFn) Call(node interface{}, ctx *queryContext) {
|
||||
@@ -144,7 +143,7 @@ type matchRecursiveFn struct {
|
||||
matchBase
|
||||
}
|
||||
|
||||
func newMatchRecursiveFn() *matchRecursiveFn{
|
||||
func newMatchRecursiveFn() *matchRecursiveFn {
|
||||
return &matchRecursiveFn{}
|
||||
}
|
||||
|
||||
@@ -177,7 +176,7 @@ type matchFilterFn struct {
|
||||
}
|
||||
|
||||
func newMatchFilterFn(name string, pos Position) *matchFilterFn {
|
||||
return &matchFilterFn{ Name: name, Pos: pos }
|
||||
return &matchFilterFn{Name: name, Pos: pos}
|
||||
}
|
||||
|
||||
func (f *matchFilterFn) Call(node interface{}, ctx *queryContext) {
|
||||
@@ -211,7 +210,7 @@ type matchScriptFn struct {
|
||||
}
|
||||
|
||||
func newMatchScriptFn(name string, pos Position) *matchScriptFn {
|
||||
return &matchScriptFn{ Name: name, Pos: pos }
|
||||
return &matchScriptFn{Name: name, Pos: pos}
|
||||
}
|
||||
|
||||
func (f *matchScriptFn) Call(node interface{}, ctx *queryContext) {
|
||||
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
package jpath
|
||||
|
||||
import (
|
||||
. "github.com/pelletier/go-toml"
|
||||
"fmt"
|
||||
. "github.com/pelletier/go-toml"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
@@ -63,7 +63,7 @@ func assertPath(t *testing.T, query string, ref *Query) {
|
||||
assertPathMatch(t, path, ref)
|
||||
}
|
||||
|
||||
func buildPath(parts... PathFn) *Query {
|
||||
func buildPath(parts ...PathFn) *Query {
|
||||
query := newQuery()
|
||||
for _, v := range parts {
|
||||
query.appendPath(v)
|
||||
@@ -179,7 +179,7 @@ func TestPathUnion(t *testing.T) {
|
||||
assertPath(t,
|
||||
"$[foo, bar, baz]",
|
||||
buildPath(
|
||||
&matchUnionFn{ []PathFn {
|
||||
&matchUnionFn{[]PathFn{
|
||||
newMatchKeyFn("foo"),
|
||||
newMatchKeyFn("bar"),
|
||||
newMatchKeyFn("baz"),
|
||||
@@ -199,7 +199,7 @@ func TestPathFilterExpr(t *testing.T) {
|
||||
assertPath(t,
|
||||
"$[?('foo'),?(bar)]",
|
||||
buildPath(
|
||||
&matchUnionFn{ []PathFn {
|
||||
&matchUnionFn{[]PathFn{
|
||||
newMatchFilterFn("foo", Position{}),
|
||||
newMatchFilterFn("bar", Position{}),
|
||||
}},
|
||||
@@ -210,7 +210,7 @@ func TestPathScriptExpr(t *testing.T) {
|
||||
assertPath(t,
|
||||
"$[('foo'),(bar)]",
|
||||
buildPath(
|
||||
&matchUnionFn{ []PathFn {
|
||||
&matchUnionFn{[]PathFn{
|
||||
newMatchScriptFn("foo", Position{}),
|
||||
newMatchScriptFn("bar", Position{}),
|
||||
}},
|
||||
|
||||
+2
-2
@@ -49,7 +49,7 @@ func (p *parser) peek() *token {
|
||||
return &tok
|
||||
}
|
||||
|
||||
func (p *parser) lookahead(types... tokenType) bool {
|
||||
func (p *parser) lookahead(types ...tokenType) bool {
|
||||
result := true
|
||||
buffer := []token{}
|
||||
|
||||
@@ -193,7 +193,7 @@ loop: // labeled loop for easy breaking
|
||||
// if there is only one sub-expression, use that instead
|
||||
if len(p.union) == 1 {
|
||||
p.path.appendPath(p.union[0])
|
||||
}else {
|
||||
} else {
|
||||
p.path.appendPath(&matchUnionFn{p.union})
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ func assertQuery(t *testing.T, toml, query string, ref []interface{}) {
|
||||
return
|
||||
}
|
||||
results := Compile(query).Execute(tree)
|
||||
assertValue(t, results, ref, "((" + query + ")) -> ")
|
||||
assertValue(t, results, ref, "(("+query+")) -> ")
|
||||
}
|
||||
|
||||
func assertValue(t *testing.T, result, ref interface{}, location string) {
|
||||
|
||||
+5
-6
@@ -33,7 +33,7 @@ type Query struct {
|
||||
}
|
||||
|
||||
func newQuery() *Query {
|
||||
return &Query {
|
||||
return &Query{
|
||||
root: nil,
|
||||
tail: nil,
|
||||
filters: &defaultFilterFunctions,
|
||||
@@ -60,7 +60,7 @@ func (q *Query) Execute(node interface{}) interface{} {
|
||||
if q.root == nil {
|
||||
return []interface{}{node} // identity query for no predicates
|
||||
}
|
||||
ctx := &queryContext {
|
||||
ctx := &queryContext{
|
||||
filters: q.filters,
|
||||
scripts: q.scripts,
|
||||
results: []interface{}{},
|
||||
@@ -91,7 +91,7 @@ func (q *Query) SetScript(name string, fn nodeFn) {
|
||||
(*q.scripts)[name] = fn
|
||||
}
|
||||
|
||||
var defaultFilterFunctions = map[string]nodeFilterFn {
|
||||
var defaultFilterFunctions = map[string]nodeFilterFn{
|
||||
"odd": func(node interface{}) bool {
|
||||
if ii, ok := node.(int64); ok {
|
||||
return (ii & 1) == 1
|
||||
@@ -106,12 +106,11 @@ var defaultFilterFunctions = map[string]nodeFilterFn {
|
||||
},
|
||||
}
|
||||
|
||||
var defaultScriptFunctions = map[string]nodeFn {
|
||||
var defaultScriptFunctions = map[string]nodeFn{
|
||||
"last": func(node interface{}) interface{} {
|
||||
if arr, ok := node.([]interface{}); ok {
|
||||
return len(arr)-1
|
||||
return len(arr) - 1
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user