Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ jobs:
run: go mod tidy && git diff-index --quiet HEAD || { >&2 echo "Stale go.{mod,sum} detected. This can be fixed with 'go mod tidy'."; exit 1; }

- name: Test
run: go test -count 100 ./...
run: go test -count 100 ./... -coverprofile="codecov.report"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

golangci-lint:
runs-on: ubuntu-latest
Expand Down
11 changes: 4 additions & 7 deletions gabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
// the intended operation.
ErrNotObj = errors.New("not an object")

// ErrInvalidQuery is returned when a seach query was not valid.
// ErrInvalidQuery is returned when a search query was not valid.
ErrInvalidQuery = errors.New("invalid search query")

// ErrNotArray is returned when a target is not an array but needs to be for
Expand Down Expand Up @@ -177,9 +177,6 @@ func (g *Container) searchStrict(allowWildcard bool, hierarchy ...string) (*Cont
if err != nil {
return nil, fmt.Errorf("failed to resolve path segment '%v': found array but segment value '%v' could not be parsed into array index: %v", target, pathSeg, err)
}
if index < 0 {
return nil, fmt.Errorf("failed to resolve path segment '%v': found array but index '%v' is invalid", target, pathSeg)
}
if len(typedObj) <= index {
return nil, fmt.Errorf("failed to resolve path segment '%v': found array but index '%v' exceeded target array size of '%v'", target, pathSeg, len(typedObj))
}
Expand Down Expand Up @@ -720,7 +717,7 @@ func walkObject(path string, obj, flat map[string]interface{}, includeEmpty bool
flat[path] = struct{}{}
}
for elePath, v := range obj {
if len(path) > 0 {
if path != "" {
elePath = path + "." + elePath
}
switch t := v.(type) {
Expand All @@ -740,7 +737,7 @@ func walkArray(path string, arr []interface{}, flat map[string]interface{}, incl
}
for i, ele := range arr {
elePath := strconv.Itoa(i)
if len(path) > 0 {
if path != "" {
elePath = path + "." + elePath
}
switch t := ele.(type) {
Expand Down Expand Up @@ -897,7 +894,7 @@ func ParseJSONDecoder(decoder *json.Decoder) (*Container, error) {

// ParseJSONFile reads a file and unmarshals the contents into a *Container.
func ParseJSONFile(path string) (*Container, error) {
if len(path) > 0 {
if path != "" {
cBytes, err := os.ReadFile(path)
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions gabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestJSONPointer(t *testing.T) {

var result *Container
result, err = root.JSONPointer(test.path)
if len(test.err) > 0 {
if test.err != "" {
if err == nil {
tt.Errorf("Expected error: %v", test.err)
} else if exp, act := test.err, err.Error(); exp != act {
Expand Down Expand Up @@ -550,7 +550,7 @@ func TestDeletes(t *testing.T) {
}
}
}`))

_ = jsonParsed.Delete()
if err := jsonParsed.Delete("outter", "inner", "value2"); err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -890,6 +890,8 @@ func TestArrayConcat(t *testing.T) {
if result != expected {
t.Errorf("Non matched output: %v != %v", result, expected)
}
//
jsonObj.ArrayConcat(10)
}

func TestArrayConcatP(t *testing.T) {
Expand Down