github.com/prebid/prebid-server/v2@v2.18.0/util/sliceutil/clone_test.go (about)

     1  package sliceutil
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestCloneSlice(t *testing.T) {
    10  	testCases := []struct {
    11  		name  string
    12  		given []int
    13  	}{
    14  		{
    15  			name:  "nil",
    16  			given: nil,
    17  		},
    18  		{
    19  			name:  "empty",
    20  			given: []int{},
    21  		},
    22  		{
    23  			name:  "one",
    24  			given: []int{1},
    25  		},
    26  		{
    27  			name:  "many",
    28  			given: []int{1, 2},
    29  		},
    30  	}
    31  
    32  	for _, test := range testCases {
    33  		t.Run(test.name, func(t *testing.T) {
    34  			result := Clone(test.given)
    35  			assert.Equal(t, test.given, result, "equality")
    36  			assert.NotSame(t, test.given, result, "pointer")
    37  		})
    38  	}
    39  }