]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix stringw test.
authorKeith Randall <khr@golang.org>
Tue, 17 Jun 2014 16:17:33 +0000 (09:17 -0700)
committerKeith Randall <khr@golang.org>
Tue, 17 Jun 2014 16:17:33 +0000 (09:17 -0700)
Null terminate string.  Make it endian-agnostic.

TBR=bradfitz
R=golang-codereviews
CC=golang-codereviews
https://golang.org/cl/106060044

src/pkg/runtime/export_test.go
src/pkg/runtime/string_test.go

index 72d4e110865b21ddff469794f85d80bd9432d145..4f29106c55eb073737fafc38a88d5d840e246ff5 100644 (file)
@@ -91,6 +91,6 @@ func gogoBytes() int32
 
 var GogoBytes = gogoBytes
 
-func gostringW([]byte) string
+func gostringW([]uint16) string
 
 var GostringW = gostringW
index cd253b2349e7818c661aea16e9d7625149e4428b..9ed579235d2b36eb04e5aaaadaa3f6e0a93903a7 100644 (file)
@@ -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)