Skip to content

Commit

Permalink
Fix FilterSelector stringification
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Nov 12, 2024
1 parent 669b6ad commit 1d0311c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ All notable changes to this project will be documented in this file. It uses the
from the current child node or also recursively selects from all of its
descendants.

### 🪲 Bug Fixes

* Added missing "?" to the stringification of `spec.FilterSelector`.

### 📔 Notes

* Made `spec.SliceSelector.Bounds` public.
Expand Down
1 change: 1 addition & 0 deletions spec/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func (f *FilterSelector) String() string {

// writeTo writes a string representation of f to buf.
func (f *FilterSelector) writeTo(buf *strings.Builder) {
buf.WriteRune('?')
f.LogicalOr.writeTo(buf)
}

Expand Down
18 changes: 9 additions & 9 deletions spec/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func TestFilterSelector(t *testing.T) {
name: "no_filter",
filter: Filter(LogicalOr{}),
exp: []any{},
str: "",
str: "?",
},
{
name: "array_root",
Expand All @@ -553,7 +553,7 @@ func TestFilterSelector(t *testing.T) {
root: []any{42, true, "hi"},
current: map[string]any{"x": 2},
exp: []any{2},
str: `$[0]`,
str: `?$[0]`,
},
{
name: "array_root_false",
Expand All @@ -563,7 +563,7 @@ func TestFilterSelector(t *testing.T) {
root: []any{42, true, "hi"},
current: map[string]any{"x": 2},
exp: []any{},
str: `$[4]`,
str: `?$[4]`,
},
{
name: "object_root",
Expand All @@ -573,7 +573,7 @@ func TestFilterSelector(t *testing.T) {
root: map[string]any{"x": 42, "y": "hi"},
current: map[string]any{"a": 2, "b": 3},
exp: []any{2, 3},
str: `$["y"]`,
str: `?$["y"]`,
rand: true,
},
{
Expand All @@ -584,7 +584,7 @@ func TestFilterSelector(t *testing.T) {
root: map[string]any{"x": 42, "y": "hi"},
current: map[string]any{"a": 2, "b": 3},
exp: []any{},
str: `$["z"]`,
str: `?$["z"]`,
rand: true,
},
{
Expand All @@ -594,7 +594,7 @@ func TestFilterSelector(t *testing.T) {
}}}),
current: []any{[]any{42}},
exp: []any{[]any{42}},
str: `@[0]`,
str: `?@[0]`,
},
{
name: "array_current_false",
Expand All @@ -603,7 +603,7 @@ func TestFilterSelector(t *testing.T) {
}}}),
current: []any{[]any{42}},
exp: []any{},
str: `@[1]`,
str: `?@[1]`,
},
{
name: "object_current",
Expand All @@ -612,7 +612,7 @@ func TestFilterSelector(t *testing.T) {
}}}),
current: []any{map[string]any{"x": 42}},
exp: []any{map[string]any{"x": 42}},
str: `@["x"]`,
str: `?@["x"]`,
},
{
name: "object_current_false",
Expand All @@ -621,7 +621,7 @@ func TestFilterSelector(t *testing.T) {
}}}),
current: []any{map[string]any{"x": 42}},
exp: []any{},
str: `@["y"]`,
str: `?@["y"]`,
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 1d0311c

Please sign in to comment.