Skip to content

Commit

Permalink
--ignore failed to match json-paths containing arrays
Browse files Browse the repository at this point in the history
Adding indices in json-paths prevented the glob library from matching
`.foo\[\]` to any index in the array.
  • Loading branch information
yazgazan committed Nov 8, 2018
1 parent 3846f53 commit bfd42e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ Report format:
```diff
$ jaydiff --report --show-types old.json new.json

- .b[]: float64 3
+ .b[]: float64 5
+ .b[]: float64 4
- .b[1]: float64 3
+ .b[1]: float64 5
+ .b[2]: float64 4
- .c.a: string toto
+ .c.a: string titi
- .c.b: float64 23
Expand Down Expand Up @@ -137,8 +137,8 @@ Ignore Excess values (useful when checking for backward compatibility):
```diff
$ jaydiff --report --show-types --ignore-excess old.json new.json

- .b[]: float64 3
+ .b[]: float64 5
- .b[1]: float64 3
+ .b[1]: float64 5
- .c.a: string toto
+ .c.a: string titi
- .c.b: float64 23
Expand Down
2 changes: 2 additions & 0 deletions patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"github.com/gobwas/glob"
"github.com/yazgazan/jaydiff/jpath"
)

type ignorePattern struct {
Expand All @@ -25,6 +26,7 @@ func (p *ignorePatterns) UnmarshalFlag(s string) error {
}

func (p ignorePatterns) Match(s string) bool {
s = jpath.StripIndices(s)
for _, pattern := range p {
if pattern.Match(s) {
return true
Expand Down
2 changes: 1 addition & 1 deletion test_files/rhs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"b": [
1,
5,
4
4
],
"c": {
"a": "titi",
Expand Down
13 changes: 13 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ else
fi
echo

echo "./jaydiff --show-types --ignore(all):"
./jaydiff --indent=' ' --show-types \
--ignore='.b\[\]' --ignore='.[c-h]' \
test_files/lhs.json test_files/rhs.json
CODE=$?
if [[ $CODE -ne 0 ]]; then
echo "FAIL with code $CODE"
FAILED=1
else
echo "OK"
fi
echo

echo "./jaydiff --report --show-types:"
./jaydiff --report --indent=' ' --show-types \
test_files/lhs.json test_files/rhs.json
Expand Down

0 comments on commit bfd42e8

Please # to comment.