Source file src/unique/clone_test.go

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package unique
     6  
     7  import (
     8  	"internal/abi"
     9  	"internal/goarch"
    10  	"reflect"
    11  	"testing"
    12  )
    13  
    14  func TestMakeCloneSeq(t *testing.T) {
    15  	testCloneSeq[testString](t, cSeq(0))
    16  	testCloneSeq[testIntArray](t, cSeq())
    17  	testCloneSeq[testEface](t, cSeq())
    18  	testCloneSeq[testStringArray](t, cSeq(0, 2*goarch.PtrSize, 4*goarch.PtrSize))
    19  	testCloneSeq[testStringStruct](t, cSeq(0))
    20  	testCloneSeq[testStringStructArrayStruct](t, cSeq(0, 2*goarch.PtrSize))
    21  	testCloneSeq[testStruct](t, cSeq(8))
    22  }
    23  
    24  func cSeq(stringOffsets ...uintptr) cloneSeq {
    25  	return cloneSeq{stringOffsets: stringOffsets}
    26  }
    27  
    28  func testCloneSeq[T any](t *testing.T, want cloneSeq) {
    29  	typName := reflect.TypeFor[T]().Name()
    30  	typ := abi.TypeFor[T]()
    31  	t.Run(typName, func(t *testing.T) {
    32  		got := makeCloneSeq(typ)
    33  		if !reflect.DeepEqual(got, want) {
    34  			t.Errorf("unexpected cloneSeq for type %s: got %#v, want %#v", typName, got, want)
    35  		}
    36  	})
    37  }
    38  

View as plain text