From c950826ac1550d62c08da63a15ac8397111e44ac Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 8 Mar 2024 11:48:40 +0100 Subject: [PATCH] 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. --- libs/dyn/visit_map_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/dyn/visit_map_test.go b/libs/dyn/visit_map_test.go index 2659b71f..2be996fb 100644 --- a/libs/dyn/visit_map_test.go +++ b/libs/dyn/visit_map_test.go @@ -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 })