]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/string_lit.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / string_lit.go
index c702a05e91fa6a07fd9e65cad9a0c0cbe17b643a..4751b82ccf49836ab17a2dfb345623f8afa6ec4f 100644 (file)
@@ -1,9 +1,11 @@
-// $G $F.go && $L $F.$A && ./$A.out
+// run
 
 // Copyright 2009 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// Test string literal syntax.
+
 package main
 
 import "os"
@@ -31,6 +33,7 @@ func assert(a, b, c string) {
                                print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n")
                        }
                }
+               panic("string_lit")
        }
 }
 
@@ -91,7 +94,7 @@ func main() {
                "backslashes 2 (backquote)")
        assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)")
 
-       // test large runes. perhaps not the most logical place for this test.
+       // test large and surrogate-half runes. perhaps not the most logical place for these tests.
        var r int32
        r = 0x10ffff // largest rune value
        s = string(r)
@@ -99,6 +102,33 @@ func main() {
        r = 0x10ffff + 1
        s = string(r)
        assert(s, "\xef\xbf\xbd", "too-large rune")
+       r = 0xD800
+       s = string(r)
+       assert(s, "\xef\xbf\xbd", "surrogate rune min")
+       r = 0xDFFF
+       s = string(r)
+       assert(s, "\xef\xbf\xbd", "surrogate rune max")
+       r = -1
+       s = string(r)
+       assert(s, "\xef\xbf\xbd", "negative rune")
+
+       // the large rune tests again, this time using constants instead of a variable.
+       // these conversions will be done at compile time.
+       s = string(0x10ffff) // largest rune value
+       assert(s, "\xf4\x8f\xbf\xbf", "largest rune constant")
+       s = string(0x10ffff + 1)
+       assert(s, "\xef\xbf\xbd", "too-large rune constant")
+       s = string(0xD800)
+       assert(s, "\xef\xbf\xbd", "surrogate rune min constant")
+       s = string(0xDFFF)
+       assert(s, "\xef\xbf\xbd", "surrogate rune max constant")
+       s = string(-1)
+       assert(s, "\xef\xbf\xbd", "negative rune")
+
+       // the large rune tests yet again, with a slice.
+       rs := []rune{0x10ffff, 0x10ffff + 1, 0xD800, 0xDFFF, -1}
+       s = string(rs)
+       assert(s, "\xf4\x8f\xbf\xbf\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd", "large rune slice")
 
        assert(string(gr1), gx1, "global ->[]rune")
        assert(string(gr2), gx2fix, "global invalid ->[]rune")