MCPcopy
hub / github.com/TomWright/dasel / TestValue_Copy

Function TestValue_Copy

model/value_test.go:147–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestValue_Copy(t *testing.T) {
148 t.Run("map copy is independent", func(t *testing.T) {
149 orig := model.NewValue(orderedmap.NewMap().Set("a", "one"))
150 cp, err := orig.Copy()
151 if err != nil {
152 t.Fatal(err)
153 }
154 // Modify original
155 if err := orig.SetMapKey("a", model.NewStringValue("modified")); err != nil {
156 t.Fatal(err)
157 }
158 // Copy should be unchanged
159 val, err := cp.GetMapKey("a")
160 if err != nil {
161 t.Fatal(err)
162 }
163 got, err := val.StringValue()
164 if err != nil {
165 t.Fatal(err)
166 }
167 if got != "one" {
168 t.Errorf("expected copy to be 'one', got %s", got)
169 }
170 })
171 t.Run("non-map returns error", func(t *testing.T) {
172 _, err := model.NewIntValue(1).Copy()
173 if err == nil {
174 t.Fatal("expected error for Copy on non-map")
175 }
176 })
177}
178
179func TestValues_ToSliceValue(t *testing.T) {
180 vals := model.Values{model.NewIntValue(1), model.NewStringValue("hello")}

Callers

nothing calls this directly

Calls 10

CopyMethod · 0.95
SetMapKeyMethod · 0.95
NewValueFunction · 0.92
NewMapFunction · 0.92
NewStringValueFunction · 0.92
NewIntValueFunction · 0.92
GetMapKeyMethod · 0.80
StringValueMethod · 0.80
RunMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected