diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f1f4207..281d3cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/gabs.go b/gabs.go index b846954..04b3e06 100644 --- a/gabs.go +++ b/gabs.go @@ -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 @@ -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)) } @@ -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) { @@ -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) { @@ -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 diff --git a/gabs_test.go b/gabs_test.go index f8429e5..ef72350 100644 --- a/gabs_test.go +++ b/gabs_test.go @@ -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 { @@ -550,7 +550,7 @@ func TestDeletes(t *testing.T) { } } }`)) - + _ = jsonParsed.Delete() if err := jsonParsed.Delete("outter", "inner", "value2"); err != nil { t.Error(err) } @@ -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) {