2012-02-16 21:51:04 -07:00
|
|
|
// run
|
2008-03-19 16:45:07 -06:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2012-02-23 17:48:19 -07:00
|
|
|
// Test string literal syntax.
|
|
|
|
|
2008-03-19 16:45:07 -06:00
|
|
|
package main
|
|
|
|
|
2009-05-08 16:21:41 -06:00
|
|
|
import "os"
|
|
|
|
|
2009-12-09 17:55:03 -07:00
|
|
|
var ecode int
|
2008-06-08 20:08:00 -06:00
|
|
|
|
|
|
|
func assert(a, b, c string) {
|
|
|
|
if a != b {
|
2010-09-03 18:36:13 -06:00
|
|
|
ecode = 1
|
|
|
|
print("FAIL: ", c, ": ", a, "!=", b, "\n")
|
|
|
|
var max int = len(a)
|
2008-06-08 20:08:00 -06:00
|
|
|
if len(b) > max {
|
2009-12-09 17:55:03 -07:00
|
|
|
max = len(b)
|
2008-06-08 20:08:00 -06:00
|
|
|
}
|
|
|
|
for i := 0; i < max; i++ {
|
2010-09-03 18:36:13 -06:00
|
|
|
ac := 0
|
|
|
|
bc := 0
|
2008-06-08 20:08:00 -06:00
|
|
|
if i < len(a) {
|
2009-12-09 17:55:03 -07:00
|
|
|
ac = int(a[i])
|
2008-06-08 20:08:00 -06:00
|
|
|
}
|
|
|
|
if i < len(b) {
|
2009-12-09 17:55:03 -07:00
|
|
|
bc = int(b[i])
|
2008-06-08 20:08:00 -06:00
|
|
|
}
|
|
|
|
if ac != bc {
|
2009-12-09 17:55:03 -07:00
|
|
|
print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n")
|
2008-06-08 20:08:00 -06:00
|
|
|
}
|
|
|
|
}
|
2013-02-12 11:17:49 -07:00
|
|
|
panic("string_lit")
|
2008-06-08 20:08:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-25 16:11:07 -07:00
|
|
|
const (
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-25 23:20:02 -06:00
|
|
|
gx1 = "aä本☺"
|
|
|
|
gx2 = "aä\xFF\xFF本☺"
|
2010-02-25 16:11:07 -07:00
|
|
|
gx2fix = "aä\uFFFD\uFFFD本☺"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-25 23:20:02 -06:00
|
|
|
gr1 = []rune(gx1)
|
|
|
|
gr2 = []rune(gx2)
|
2010-02-25 16:11:07 -07:00
|
|
|
gb1 = []byte(gx1)
|
|
|
|
gb2 = []byte(gx2)
|
|
|
|
)
|
|
|
|
|
2008-06-27 15:15:06 -06:00
|
|
|
func main() {
|
2010-09-03 18:36:13 -06:00
|
|
|
ecode = 0
|
2008-06-08 20:08:00 -06:00
|
|
|
s :=
|
2009-12-09 17:55:03 -07:00
|
|
|
"" +
|
|
|
|
" " +
|
|
|
|
"'`" +
|
|
|
|
"a" +
|
|
|
|
"ä" +
|
|
|
|
"本" +
|
|
|
|
"\a\b\f\n\r\t\v\\\"" +
|
|
|
|
"\000\123\x00\xca\xFE\u0123\ubabe\U0000babe" +
|
|
|
|
|
|
|
|
`` +
|
|
|
|
` ` +
|
|
|
|
`'"` +
|
|
|
|
`a` +
|
|
|
|
`ä` +
|
|
|
|
`本` +
|
|
|
|
`\a\b\f\n\r\t\v\\\'` +
|
|
|
|
`\000\123\x00\xca\xFE\u0123\ubabe\U0000babe` +
|
2010-09-03 18:36:13 -06:00
|
|
|
`\x\u\U\`
|
2009-01-16 15:58:14 -07:00
|
|
|
|
2010-09-03 18:36:13 -06:00
|
|
|
assert("", ``, "empty")
|
|
|
|
assert(" ", " ", "blank")
|
|
|
|
assert("\x61", "a", "lowercase a")
|
|
|
|
assert("\x61", `a`, "lowercase a (backquote)")
|
|
|
|
assert("\u00e4", "ä", "a umlaut")
|
|
|
|
assert("\u00e4", `ä`, "a umlaut (backquote)")
|
|
|
|
assert("\u672c", "本", "nihon")
|
|
|
|
assert("\u672c", `本`, "nihon (backquote)")
|
2008-06-08 20:08:00 -06:00
|
|
|
assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
|
2009-12-09 17:55:03 -07:00
|
|
|
"\a\b\f\n\r\t\v\\\"",
|
2010-09-03 18:36:13 -06:00
|
|
|
"backslashes")
|
2008-06-08 20:08:00 -06:00
|
|
|
assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
|
2009-08-17 14:30:22 -06:00
|
|
|
`\a\b\f\n\r\t\v\\\"`,
|
2010-09-03 18:36:13 -06:00
|
|
|
"backslashes (backquote)")
|
2008-06-08 20:08:00 -06:00
|
|
|
assert("\x00\x53\000\xca\376S몾몾",
|
2009-08-17 14:30:22 -06:00
|
|
|
"\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
|
2010-09-03 18:36:13 -06:00
|
|
|
"backslashes 2")
|
2008-06-08 20:08:00 -06:00
|
|
|
assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
|
2009-08-17 14:30:22 -06:00
|
|
|
`\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
|
2010-09-03 18:36:13 -06:00
|
|
|
"backslashes 2 (backquote)")
|
|
|
|
assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)")
|
2008-07-07 15:07:46 -06:00
|
|
|
|
2012-08-30 12:16:55 -06:00
|
|
|
// test large and surrogate-half runes. perhaps not the most logical place for these tests.
|
2010-09-03 18:36:13 -06:00
|
|
|
var r int32
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-25 23:20:02 -06:00
|
|
|
r = 0x10ffff // largest rune value
|
2010-09-03 18:36:13 -06:00
|
|
|
s = string(r)
|
|
|
|
assert(s, "\xf4\x8f\xbf\xbf", "largest rune")
|
|
|
|
r = 0x10ffff + 1
|
|
|
|
s = string(r)
|
|
|
|
assert(s, "\xef\xbf\xbd", "too-large rune")
|
2012-08-30 12:16:55 -06:00
|
|
|
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")
|
2013-02-12 11:17:49 -07:00
|
|
|
|
2012-08-30 12:16:55 -06:00
|
|
|
// 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")
|
2010-02-25 16:11:07 -07:00
|
|
|
|
2013-12-12 18:17:02 -07:00
|
|
|
// 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")
|
|
|
|
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-25 23:20:02 -06:00
|
|
|
assert(string(gr1), gx1, "global ->[]rune")
|
|
|
|
assert(string(gr2), gx2fix, "global invalid ->[]rune")
|
2010-02-25 16:11:07 -07:00
|
|
|
assert(string(gb1), gx1, "->[]byte")
|
|
|
|
assert(string(gb2), gx2, "global invalid ->[]byte")
|
|
|
|
|
|
|
|
var (
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-25 23:20:02 -06:00
|
|
|
r1 = []rune(gx1)
|
|
|
|
r2 = []rune(gx2)
|
2010-02-25 16:11:07 -07:00
|
|
|
b1 = []byte(gx1)
|
|
|
|
b2 = []byte(gx2)
|
|
|
|
)
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-25 23:20:02 -06:00
|
|
|
assert(string(r1), gx1, "->[]rune")
|
|
|
|
assert(string(r2), gx2fix, "invalid ->[]rune")
|
2010-02-25 16:11:07 -07:00
|
|
|
assert(string(b1), gx1, "->[]byte")
|
|
|
|
assert(string(b2), gx2, "invalid ->[]byte")
|
|
|
|
|
2010-09-03 18:36:13 -06:00
|
|
|
os.Exit(ecode)
|
2008-03-19 16:45:07 -06:00
|
|
|
}
|