github.com/influx6/npkg@v0.8.8/nreflect/deepcopy_test.go (about) 1 package nreflect_test 2 3 import ( 4 "testing" 5 6 "github.com/influx6/npkg/nreflect" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestDeepCopy(t *testing.T) { 11 type moma struct { 12 Number int 13 } 14 15 var specs = []struct { 16 Value interface{} 17 Fail bool 18 }{ 19 { 20 Value: map[string]int{"one": 1, "two": 2, "three": 3}, 21 }, 22 { 23 Value: []string{"one", "two", "three"}, 24 }, 25 { 26 Value: [3]string{"one", "two", "three"}, 27 }, 28 { 29 Value: []int{1, 2, 3, 4, 5}, 30 }, 31 { 32 Value: moma{Number: 20}, 33 }, 34 { 35 Value: &moma{Number: 20}, 36 }, 37 { 38 Value: struct { 39 Name string 40 }{ 41 Name: "wonder", 42 }, 43 }, 44 { 45 Value: &(struct { 46 Name string 47 }{ 48 Name: "wonder", 49 }), 50 }, 51 { 52 Value: "one", 53 }, 54 { 55 Value: "1", 56 }, 57 { 58 Value: 1, 59 }, 60 { 61 Value: float64(1.6), 62 }, 63 { 64 Value: float32(11.1), 65 }, 66 { 67 Value: true, 68 }, 69 { 70 Value: false, 71 }, 72 } 73 74 for _, spec := range specs { 75 var dest, err = nreflect.DeepCopy(spec.Value) 76 require.NoError(t, err) 77 require.NotNil(t, dest) 78 require.Equal(t, spec.Value, dest) 79 } 80 }