Skip to content

Commit 83c7b28

Browse files
author
Kevin Wiesmüller
committed
fix remove and test
1 parent 28e231e commit 83c7b28

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

typed/remove_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,29 @@ func TestRemoveShallowRemovesParents(t *testing.T) {
117117
},
118118
}
119119

120-
test = removeItemsWithSchema(test, remove, schema, typeRef, false)
120+
tv := TypedValue{
121+
value: test,
122+
typeRef: typeRef,
123+
schema: schema,
124+
}
125+
126+
result := tv.RemoveItems(remove)
121127

122128
expect, err := value.FromJSON([]byte(`{"keep": "value", "keepMap": {"child": "value"}, "keepList": [{"child": "value"}], "removeMap": {"child":"value"}, "removeList": [{"child": "value"}]}`))
123129
if err != nil {
124130
t.Fatal(err)
125131
}
126-
if !value.Equals(test, expect) {
132+
if !value.Equals(result.AsValue(), expect) {
127133
t.Fatalf("unexpected result after remove:\ngot: %v\nexp: %v", test.String(), expect.String())
128134
}
129135

130-
test = removeItemsWithSchema(test, remove, schema, typeRef, true)
136+
result = tv.Remove(remove)
131137

132138
expect, err = value.FromJSON([]byte(`{"keep": "value", "keepMap": {"child": "value"}, "keepList": [{"child": "value"}]}`))
133139
if err != nil {
134140
t.Fatal(err)
135141
}
136-
if !value.Equals(test, expect) {
142+
if !value.Equals(result.AsValue(), expect) {
137143
t.Fatalf("unexpected result after remove:\ngot: %v\nexp: %v", value.ToString(test), value.ToString(expect))
138144
}
139145
}

typed/typed.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (tv TypedValue) RemoveItems(items *fieldpath.Set) *TypedValue {
146146

147147
// Remove removes each provided path from the value.
148148
func (tv TypedValue) Remove(paths *fieldpath.Set) *TypedValue {
149-
tv.value = removeItemsWithSchema(tv.value, paths, tv.schema, tv.typeRef, false)
149+
tv.value = removeItemsWithSchema(tv.value, paths, tv.schema, tv.typeRef, true)
150150
return &tv
151151
}
152152

0 commit comments

Comments
 (0)