stardb/rows_internal_test.go

30 lines
698 B
Go
Raw Permalink Normal View History

package stardb
import "testing"
func TestCloneScannedValue_BytesAreCopied(t *testing.T) {
original := []byte("hello")
clonedAny := cloneScannedValue(original)
cloned, ok := clonedAny.([]byte)
if !ok {
t.Fatalf("expected []byte, got %T", clonedAny)
}
original[0] = 'H'
if string(cloned) != "hello" {
t.Fatalf("expected cloned value to remain 'hello', got '%s'", string(cloned))
}
if len(cloned) > 0 && &cloned[0] == &original[0] {
t.Fatal("expected cloned bytes to have a different backing array")
}
}
func TestCloneScannedValue_NonBytesKeepReference(t *testing.T) {
in := int64(42)
out := cloneScannedValue(in)
if out != in {
t.Fatalf("expected %v, got %v", in, out)
}
}