mirror of https://github.com/siddontang/go.git
38 lines
446 B
Go
38 lines
446 B
Go
package hack
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"testing"
|
|
)
|
|
|
|
func TestString(t *testing.T) {
|
|
b := []byte("hello world")
|
|
a := String(b)
|
|
|
|
if a != "hello world" {
|
|
t.Fatal(a)
|
|
}
|
|
|
|
b[0] = 'a'
|
|
|
|
if a != "aello world" {
|
|
t.Fatal(a)
|
|
}
|
|
|
|
b = append(b, "abc"...)
|
|
if a != "aello world" {
|
|
t.Fatal(a)
|
|
}
|
|
}
|
|
|
|
func TestByte(t *testing.T) {
|
|
a := "hello world"
|
|
|
|
b := Slice(a)
|
|
|
|
if !bytes.Equal(b, []byte("hello world")) {
|
|
t.Fatal(string(b))
|
|
}
|
|
}
|