v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/util/slice/copy_test.go (about) 1 package slice 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestCopy(t *testing.T) { 9 type args struct { 10 s []int 11 } 12 tests := []struct { 13 name string 14 args args 15 want []int 16 }{ 17 { 18 name: "Copy len=1 cap=5", 19 args: args{ 20 s: []int{1, 2, 3, 4, 5}[:1], 21 }, 22 want: []int{1, 2, 3, 4, 5}[:1], 23 }, 24 { 25 name: "Copy len=5 cap=5", 26 args: args{ 27 s: []int{1, 2, 3, 4, 5}[:5], 28 }, 29 want: []int{1, 2, 3, 4, 5}[:5], 30 }, 31 } 32 for _, tt := range tests { 33 t.Run(tt.name, func(t *testing.T) { 34 if got := Copy(tt.args.s); !reflect.DeepEqual(got[:cap(got)], tt.want[:cap(tt.want)]) { 35 t.Errorf("Copy() = %v, want %v", got, tt.want) 36 } 37 }) 38 } 39 }