github.com/grailbio/base@v0.0.11/unsafe/unsafe_test.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache-2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package unsafe_test
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"github.com/grailbio/base/unsafe"
    12  )
    13  
    14  func TestBytesToString(t *testing.T) {
    15  	for _, src := range []string{"", "abc"} {
    16  		d := unsafe.BytesToString([]byte(src))
    17  		if d != src {
    18  			t.Error(d)
    19  		}
    20  	}
    21  }
    22  
    23  func ExampleBytesToString() {
    24  	fmt.Println(unsafe.BytesToString([]byte{'A', 'b', 'C'}))
    25  	// Output: AbC
    26  }
    27  
    28  func TestStringToBytes(t *testing.T) {
    29  	for _, src := range []string{"", "abc"} {
    30  		d := unsafe.StringToBytes(src)
    31  		if string(d) != src {
    32  			t.Error(d)
    33  		}
    34  	}
    35  }
    36  
    37  func ExampleStringToBytes() {
    38  	fmt.Println(unsafe.StringToBytes("AbC"))
    39  	// Output: [65 98 67]
    40  }