summaryrefslogtreecommitdiff
path: root/test/string_lit.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2012-08-30 11:16:55 -0700
committerRob Pike <r@golang.org>2012-08-30 11:16:55 -0700
commit1980ce66a9754aa3621ddf9d80572b98f0a955e9 (patch)
treec4060a8e94224c5098326a376b5fa0e47cb68d1b /test/string_lit.go
parent37f474fe10c6eb42dcd26956a5813b0183b91a8c (diff)
downloadgo-1980ce66a9754aa3621ddf9d80572b98f0a955e9.tar.gz
cmd/gc: string conversion for surrogates
This is required by the spec to produce the replacement char. The fix lies in lib9's rune code. R=golang-dev, nigeltao, rsc CC=golang-dev http://codereview.appspot.com/6443109
Diffstat (limited to 'test/string_lit.go')
-rw-r--r--test/string_lit.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/test/string_lit.go b/test/string_lit.go
index 956330038..457faaa88 100644
--- a/test/string_lit.go
+++ b/test/string_lit.go
@@ -93,7 +93,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)
@@ -101,6 +101,28 @@ 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")
assert(string(gr1), gx1, "global ->[]rune")
assert(string(gr2), gx2fix, "global invalid ->[]rune")