@@ -175,32 +175,114 @@ func Test_ApplyFilter_PanicSafety(t *testing.T) {
175175func Test_deepCopyAny (t * testing.T ) {
176176 g := NewWithT (t )
177177
178- // Test copying a map
178+ // Test copying a map preserves types
179179 inputMap := map [string ]any {"foo" : "bar" , "num" : 42 }
180180 copyMap , err := deepCopyAny (inputMap )
181181 g .Expect (err ).Should (BeNil ())
182- g .Expect (copyMap ).Should (Equal (map [string ]any {"foo" : "bar" , "num" : float64 ( 42 ) }))
182+ g .Expect (copyMap ).Should (Equal (map [string ]any {"foo" : "bar" , "num" : 42 }))
183183 g .Expect (copyMap ).ShouldNot (BeIdenticalTo (inputMap ))
184184
185- // Test copying a slice
185+ // Test copying a slice preserves types
186186 inputSlice := []any {"a" , 1 , true }
187187 copySlice , err := deepCopyAny (inputSlice )
188188 g .Expect (err ).Should (BeNil ())
189- g .Expect (copySlice ).Should (Equal ([]any {"a" , float64 ( 1 ) , true }))
189+ g .Expect (copySlice ).Should (Equal ([]any {"a" , 1 , true }))
190190 g .Expect (copySlice ).ShouldNot (BeIdenticalTo (inputSlice ))
191191
192192 // Test copying nil
193193 copyNil , err := deepCopyAny (nil )
194194 g .Expect (err ).Should (BeNil ())
195195 g .Expect (copyNil ).Should (BeNil ())
196196
197- // Test copying a value that cannot be marshaled to JSON
197+ // Test copying a value with unsupported type
198198 inputInvalid := map [string ]any {"ch" : make (chan int )}
199199 copyInvalid , err := deepCopyAny (inputInvalid )
200200 g .Expect (err ).ShouldNot (BeNil ())
201201 g .Expect (copyInvalid ).Should (BeNil ())
202202}
203203
204+ func Test_deepCopyAny_NestedMap (t * testing.T ) {
205+ g := NewWithT (t )
206+
207+ input := map [string ]any {
208+ "metadata" : map [string ]any {
209+ "name" : "my-pod" ,
210+ "namespace" : "default" ,
211+ "labels" : map [string ]any {"app" : "test" },
212+ },
213+ "spec" : map [string ]any {
214+ "replicas" : float64 (3 ),
215+ },
216+ }
217+
218+ result , err := deepCopyAny (input )
219+ g .Expect (err ).Should (BeNil ())
220+
221+ resultMap := result .(map [string ]any )
222+ g .Expect (resultMap ["metadata" ]).Should (Equal (input ["metadata" ]))
223+
224+ // Verify it's a true deep copy: mutating the copy must not affect the original.
225+ resultMeta := resultMap ["metadata" ].(map [string ]any )
226+ resultMeta ["name" ] = "mutated"
227+ g .Expect (input ["metadata" ].(map [string ]any )["name" ]).Should (Equal ("my-pod" ))
228+ }
229+
230+ func Test_deepCopyAny_NestedSlice (t * testing.T ) {
231+ g := NewWithT (t )
232+
233+ input := []any {
234+ map [string ]any {"name" : "a" },
235+ map [string ]any {"name" : "b" },
236+ }
237+
238+ result , err := deepCopyAny (input )
239+ g .Expect (err ).Should (BeNil ())
240+
241+ resultSlice := result .([]any )
242+ g .Expect (resultSlice ).Should (HaveLen (2 ))
243+
244+ // Mutate copy, verify original is untouched.
245+ resultSlice [0 ].(map [string ]any )["name" ] = "mutated"
246+ g .Expect (input [0 ].(map [string ]any )["name" ]).Should (Equal ("a" ))
247+ }
248+
249+ func Test_deepCopyAny_NumericTypes (t * testing.T ) {
250+ g := NewWithT (t )
251+
252+ input := map [string ]any {
253+ "int" : 42 ,
254+ "int64" : int64 (100 ),
255+ "float64" : 3.14 ,
256+ "bool" : true ,
257+ "string" : "hello" ,
258+ }
259+
260+ result , err := deepCopyAny (input )
261+ g .Expect (err ).Should (BeNil ())
262+ g .Expect (result ).Should (Equal (input ))
263+ }
264+
265+ func BenchmarkDeepCopyAny (b * testing.B ) {
266+ input := map [string ]any {
267+ "metadata" : map [string ]any {
268+ "name" : "my-pod" ,
269+ "namespace" : "default" ,
270+ "labels" : map [string ]any {"app" : "test" , "env" : "prod" },
271+ },
272+ "spec" : map [string ]any {
273+ "containers" : []any {
274+ map [string ]any {"name" : "main" , "image" : "nginx:latest" },
275+ map [string ]any {"name" : "sidecar" , "image" : "envoy:latest" },
276+ },
277+ "replicas" : float64 (3 ),
278+ },
279+ }
280+ b .ResetTimer ()
281+ for range b .N {
282+ _ , _ = deepCopyAny (input )
283+ }
284+ }
285+
204286// ---- Compile / CompiledJqFilter tests ----
205287
206288func Test_Compile_ValidExpression (t * testing.T ) {
0 commit comments