Add assertions for the `dyn.Path` argument to the visit callback (#1265)

## Changes

The `dyn.Path` argument wasn't tested and could regress. Spotted this
while working on related code. Follow up to #1260.

## Tests

Unit tests.
This commit is contained in:
Pieter Noordhuis 2024-03-08 11:48:40 +01:00 committed by GitHub
parent 16a4c711e2
commit c950826ac1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

View File

@ -45,7 +45,8 @@ func TestMapFuncOnMap(t *testing.T) {
// Note: in the test cases below we implicitly test that the original
// value is not modified as we repeatedly set values on it.
vfoo, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Key("foo")), func(_ dyn.Path, v dyn.Value) (dyn.Value, error) {
vfoo, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Key("foo")), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
assert.Equal(t, dyn.NewPath(dyn.Key("foo")), p)
assert.Equal(t, dyn.V(42), v)
return dyn.V(44), nil
})
@ -55,7 +56,8 @@ func TestMapFuncOnMap(t *testing.T) {
"bar": 43,
}, vfoo.AsAny())
vbar, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Key("bar")), func(_ dyn.Path, v dyn.Value) (dyn.Value, error) {
vbar, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Key("bar")), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
assert.Equal(t, dyn.NewPath(dyn.Key("bar")), p)
assert.Equal(t, dyn.V(43), v)
return dyn.V(45), nil
})
@ -115,14 +117,16 @@ func TestMapFuncOnSequence(t *testing.T) {
// Note: in the test cases below we implicitly test that the original
// value is not modified as we repeatedly set values on it.
v0, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Index(0)), func(_ dyn.Path, v dyn.Value) (dyn.Value, error) {
v0, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Index(0)), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
assert.Equal(t, dyn.NewPath(dyn.Index(0)), p)
assert.Equal(t, dyn.V(42), v)
return dyn.V(44), nil
})
assert.NoError(t, err)
assert.Equal(t, []any{44, 43}, v0.AsAny())
v1, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Index(1)), func(_ dyn.Path, v dyn.Value) (dyn.Value, error) {
v1, err := dyn.MapByPath(vin, dyn.NewPath(dyn.Index(1)), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
assert.Equal(t, dyn.NewPath(dyn.Index(1)), p)
assert.Equal(t, dyn.V(43), v)
return dyn.V(45), nil
})