diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml deleted file mode 100644 index 0ffd8f2..0000000 --- a/.github/workflows/coverage.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: Coverage -on: - push: - branches: - - main - paths: - - '**.go' - - 'go.mod' -jobs: - coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: '1.17' - - name: Install dependencies - run: | - go install golang.org/x/lint/golint@latest - go mod download - - name: Run Test - run: | - go test -v -coverprofile=coverage.txt -covermode=atomic -count=10 ./... - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage.txt - fail_ci_if_error: true - verbose: true diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index a1ab746..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name: Lint -on: - push: - branches: - - main - - develop - paths: - - '**.go' - - 'go.mod' - pull_request: - branches: - - main - - develop - paths: - - '**.go' - - 'go.mod' -jobs: - lint: - strategy: - matrix: - go-version: [1.17.x] - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - - name: Install dependencies - run: | - go install golang.org/x/lint/golint@latest - go mod download - - name: Run Lint - run: | - golint -set_exit_status=1 ./... \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/pull_request.yaml similarity index 52% rename from .github/workflows/test.yaml rename to .github/workflows/pull_request.yaml index 58d08d0..4294765 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/pull_request.yaml @@ -1,12 +1,5 @@ -name: Test +name: Pull Requests on: - push: - branches: - - main - - develop - paths: - - '**.go' - - 'go.mod' pull_request: branches: - main @@ -35,3 +28,23 @@ jobs: - name: Run Test run: | go test -v -count=10 ./... + lint: + strategy: + matrix: + go-version: [1.17.x] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Install dependencies + run: | + go install golang.org/x/lint/golint@latest + go mod download + - name: Run Lint + run: | + golint -set_exit_status=1 ./... diff --git a/.github/workflows/push_main.yaml b/.github/workflows/push_main.yaml new file mode 100644 index 0000000..4b8de67 --- /dev/null +++ b/.github/workflows/push_main.yaml @@ -0,0 +1,81 @@ +name: Push Main +on: + push: + branches: + - main + paths: + - '**.go' + - 'go.mod' +jobs: + test: + strategy: + matrix: + go-version: ['1.17'] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Install dependencies + run: | + go version + go mod download + - name: Run Test + run: | + go test -v -count=10 ./... + lint: + strategy: + matrix: + go-version: ['1.17'] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Install dependencies + run: | + go install golang.org/x/lint/golint@latest + go mod download + - name: Run Lint + run: | + golint -set_exit_status=1 ./... + coverage: + runs-on: ubuntu-latest + needs: [test, lint] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '1.17' + - name: Install dependencies + run: | + go install golang.org/x/lint/golint@latest + go mod download + - name: Run Test + run: | + go test -v -coverprofile=coverage.txt -covermode=atomic -count=10 ./... + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.txt + fail_ci_if_error: true + verbose: true + release: + runs-on: ubuntu-latest + needs: [test, lint] + steps: + - uses: actions/checkout@master + - uses: go-semantic-release/action@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + allow-initial-development-versions: true + force-bump-patch-version: true diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 8da391f..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: Release -on: - push: - branches: - - main - paths: - - '**.go' - - 'go.mod' -jobs: - release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: go-semantic-release/action@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - allow-initial-development-versions: true - force-bump-patch-version: true diff --git a/README.md b/README.md index 27ec404..b1d12a2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ [![codecov](https://codecov.io/gh/evilmonkeyinc/jsonpath/branch/main/graph/badge.svg?token=4PU85I7J2R)](https://codecov.io/gh/evilmonkeyinc/jsonpath) [![main](https://github.com/evilmonkeyinc/jsonpath/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/evilmonkeyinc/jsonpath/actions/workflows/test.yaml) -[![develop](https://github.com/evilmonkeyinc/jsonpath/actions/workflows/test.yaml/badge.svg?branch=develop)](https://github.com/evilmonkeyinc/jsonpath/actions/workflows/test.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/evilmonkeyinc/jsonpath.svg)](https://pkg.go.dev/github.com/evilmonkeyinc/jsonpath) > This library is on the unstable version v0.X.X, which means there is a chance that any minor update may introduce a breaking change. Where I will endeavor to avoid this, care should be taken updating your dependency on this library until the first stable release v1.0.0 at which point any future breaking changes will result in a new major release. diff --git a/test/README.md b/test/README.md index 8934774..2e5e979 100644 --- a/test/README.md +++ b/test/README.md @@ -171,17 +171,17 @@ This implementation would be closer to the 'Scalar consensus' as it does not alw |`$[?(@.key>42 && @.key<44)]`|`[ {"key": 42}, {"key": 43}, {"key": 44} ]`|`[{"key":43}]`|`[{"key":43}]`|:white_check_mark:| |`$[?(@.key>0 && false)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[]`|:question:| |`$[?(@.key>0 && true)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3}]`|:question:| -|`$[?(@.key>43 || @.key<43)]`|`[ {"key": 42}, {"key": 43}, {"key": 44} ]`|`[{"key":42},{"key":44}]`|`[{"key":42},{"key":44}]`|:white_check_mark:| -|`$[?(@.key>0 || false)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3}]`|:question:| -|`$[?(@.key>0 || true)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3},{"key":-1},{"key":0}]`|:question:| +|`$[?(@.key>43 \|\| @.key<43)]`|`[ {"key": 42}, {"key": 43}, {"key": 44} ]`|`[{"key":42},{"key":44}]`|`[{"key":42},{"key":44}]`|:white_check_mark:| +|`$[?(@.key>0 \|\| false)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3}]`|:question:| +|`$[?(@.key>0 \|\| true)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3},{"key":-1},{"key":0}]`|:question:| |`$[?(@['key']==42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"some": "value"} ]`|`[{"key":42}]`|`[{"key":42}]`|:white_check_mark:| |`$[?(@['@key']==42)]`|`[ {"@key": 0}, {"@key": 42}, {"key": 42}, {"@key": 43}, {"some": "value"} ]`|`[{"@key":42}]`|`[{"@key":42}]`|:white_check_mark:| |`$[?(@[-1]==2)]`|`[[2, 3], ["a"], [0, 2], [2]]`|none|`[[0,2],[2]]`|:question:| |`$[?(@[1]=='b')]`|`[["a", "b"], ["x", "y"]]`|`[["a","b"]]`|`[["a","b"]]`|:white_check_mark:| |`$[?(@[1]=='b')]`|`{"1": ["a", "b"], "2": ["x", "y"]}`|none|`[["a","b"]]`|:question:| |`$[?(@)]`|`[ "some value", null, "value", 0, 1, -1, "", [], {}, false, true ]`|none|`["some value","value",0,1,-1,true]`|:question:| -|`$[?(@.a && (@.b || @.c))]`|`[ { "a": true }, { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "c": true }, { "b": true } ]`|none|`[]`|:question:| -|`[?(@.a && @.b || @.c)]`|`[ { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "a": true }, { "b": true }, { "c": true }, { "d": true }, {} ]`|none|`null`|:question:| +|`$[?(@.a && (@.b \|\| @.c))]`|`[ { "a": true }, { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "c": true }, { "b": true } ]`|none|`[]`|:question:| +|`[?(@.a && @.b \|\| @.c)]`|`[ { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "a": true }, { "b": true }, { "c": true }, { "d": true }, {} ]`|none|`null`|:question:| |`$[?(@.key/10==5)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key/10": 5}]`|none|`[{"key":50}]`|:question:| |`$[?(@.key-dash == 'value')]`|`[ { "key-dash": "value" } ]`|none|`[]`|:question:| |`$[?(@.2 == 'second')]`|`[{"a": "first", "2": "second", "b": "third"}]`|none|`[{"2":"second","a":"first","b":"third"}]`|:question:| diff --git a/test/helper_test.go b/test/helper_test.go index a0acbbf..744982c 100644 --- a/test/helper_test.go +++ b/test/helper_test.go @@ -9,6 +9,7 @@ import ( "io" "os" "reflect" + "strings" "testing" "github.com/evilmonkeyinc/jsonpath" @@ -110,6 +111,11 @@ func printConsensusMatrix(writer io.Writer, tests []testData) { fmt.Fprintf(writer, "|query|data|consensus|actual|match|\n") fmt.Fprintf(writer, "|---|---|---|---|---|\n") for _, test := range tests { + + query := test.query + // escape | so format doesnt break + query = strings.ReplaceAll(query, "|", "\\|") + expected := test.expected if expected == nil { expected = "null" @@ -119,7 +125,7 @@ func printConsensusMatrix(writer io.Writer, tests []testData) { } if test.consensus == consensusNone { - fmt.Fprintf(writer, "|`%s`|`%v`|%s|`%v`|%s|\n", test.query, test.data, "none", expected, ":question:") + fmt.Fprintf(writer, "|`%s`|`%v`|%s|`%v`|%s|\n", query, test.data, "none", expected, ":question:") continue } @@ -136,6 +142,6 @@ func printConsensusMatrix(writer io.Writer, tests []testData) { symbol = ":white_check_mark:" } - fmt.Fprintf(writer, "|`%s`|`%v`|`%v`|`%v`|%s|\n", test.query, test.data, consensus, expected, symbol) + fmt.Fprintf(writer, "|`%s`|`%v`|`%v`|`%v`|%s|\n", query, test.data, consensus, expected, symbol) } }