github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/utils/str_test.go (about)

     1  package utils_test
     2  
     3  import (
     4  	"testing"
     5  	"unsafe"
     6  
     7  	"github.com/clubpay/ronykit/kit/utils"
     8  )
     9  
    10  func TestClone(t *testing.T) {
    11  	x := utils.RandomID(128)
    12  	y := utils.CloneStr(x)
    13  	if unsafe.Pointer(&x) == unsafe.Pointer(&y) {
    14  		t.Fatal("CloneStr should return a new string", unsafe.Pointer(&x), unsafe.Pointer(&y))
    15  	}
    16  	tt := utils.CloneBytes(utils.S2B(y))
    17  	if unsafe.Pointer(&tt) == unsafe.Pointer(&y) {
    18  		t.Fatal("CloneBytes should return a new slice", unsafe.Pointer(&tt), unsafe.Pointer(&y))
    19  	}
    20  }
    21  
    22  func BenchmarkConvert(b *testing.B) {
    23  	x := utils.RandomID(128)
    24  	for i := 0; i < b.N; i++ {
    25  		y := utils.B2S(utils.S2B(x))
    26  		if len(x) != len(y) {
    27  			b.Fatal("B2S should return same length")
    28  		}
    29  	}
    30  }