Hi,
I'm writing some functions that need to do deep clones of slices, and I'd like to test my code to ensure that it creates a new underlying array for each cloned slice.
See:
Is this achievable in Go? I've found that I can use the test:
unsafe.Pointer(*slice1) != unsafe.Pointer(*slice2)
to test whether to slices are the same (slices can otherwise only be compared to nil), but this still isn't quite right: BadClone in the code passes this test, but the slice it returns still references the same array.
Notes:
- this is for tests only, not for live code, so I don't mind using hacks like the use of unsafe.Pointer above
- the actual slices that I'm testing are deeply nested, up to four levels deep ([][][][]float64 is how
GeoJSON represents the coordinates of a MultiPolygon), so I'd like a more generic test than mutating elements of the supposed clone and testing to see if the original array is mutated, if possible.
Thanks!
Tom