Commit 2b309c6e authored by Keith Randall's avatar Keith Randall

runtime: fix stringw test.

Null terminate string.  Make it endian-agnostic.

TBR=bradfitz
R=golang-codereviews
CC=golang-codereviews
https://golang.org/cl/106060044
parent 63393fae
......@@ -91,6 +91,6 @@ func gogoBytes() int32
var GogoBytes = gogoBytes
func gostringW([]byte) string
func gostringW([]uint16) string
var GostringW = gostringW
......@@ -104,18 +104,18 @@ func BenchmarkRuneIterate2(b *testing.B) {
func TestStringW(t *testing.T) {
strings := []string{
"hello",
//"a\u5566\u7788b",
"a\u5566\u7788b",
}
for _, s := range strings {
var b []byte
var b []uint16
for _, c := range s {
b = append(b, byte(c&255))
b = append(b, byte(c>>8))
if c>>16 != 0 {
b = append(b, uint16(c))
if c != rune(uint16(c)) {
t.Errorf("bad test: stringW can't handle >16 bit runes")
}
}
b = append(b, 0)
r := runtime.GostringW(b)
if r != s {
t.Errorf("gostringW(%v) = %s, want %s", b, r, s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment