3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test string literal syntax.
15 func assert(a, b, c string) {
18 print("FAIL: ", c, ": ", a, "!=", b, "\n")
23 for i := 0; i < max; i++ {
33 print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n")
43 gx2fix = "aä\uFFFD\uFFFD本☺"
62 "\a\b\f\n\r\t\v\\\"" +
63 "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe" +
71 `\a\b\f\n\r\t\v\\\'` +
72 `\000\123\x00\xca\xFE\u0123\ubabe\U0000babe` +
75 assert("", ``, "empty")
76 assert(" ", " ", "blank")
77 assert("\x61", "a", "lowercase a")
78 assert("\x61", `a`, "lowercase a (backquote)")
79 assert("\u00e4", "ä", "a umlaut")
80 assert("\u00e4", `ä`, "a umlaut (backquote)")
81 assert("\u672c", "本", "nihon")
82 assert("\u672c", `本`, "nihon (backquote)")
83 assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
86 assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
88 "backslashes (backquote)")
89 assert("\x00\x53\000\xca\376S몾몾",
90 "\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
92 assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
93 `\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
94 "backslashes 2 (backquote)")
95 assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)")
97 // test large and surrogate-half runes. perhaps not the most logical place for these tests.
99 r = 0x10ffff // largest rune value
101 assert(s, "\xf4\x8f\xbf\xbf", "largest rune")
104 assert(s, "\xef\xbf\xbd", "too-large rune")
107 assert(s, "\xef\xbf\xbd", "surrogate rune min")
110 assert(s, "\xef\xbf\xbd", "surrogate rune max")
113 assert(s, "\xef\xbf\xbd", "negative rune")
115 // the large rune tests again, this time using constants instead of a variable.
116 // these conversions will be done at compile time.
117 s = string(0x10ffff) // largest rune value
118 assert(s, "\xf4\x8f\xbf\xbf", "largest rune constant")
119 s = string(0x10ffff + 1)
120 assert(s, "\xef\xbf\xbd", "too-large rune constant")
122 assert(s, "\xef\xbf\xbd", "surrogate rune min constant")
124 assert(s, "\xef\xbf\xbd", "surrogate rune max constant")
126 assert(s, "\xef\xbf\xbd", "negative rune")
128 // the large rune tests yet again, with a slice.
129 rs := []rune{0x10ffff, 0x10ffff + 1, 0xD800, 0xDFFF, -1}
131 assert(s, "\xf4\x8f\xbf\xbf\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd", "large rune slice")
133 assert(string(gr1), gx1, "global ->[]rune")
134 assert(string(gr2), gx2fix, "global invalid ->[]rune")
135 assert(string(gb1), gx1, "->[]byte")
136 assert(string(gb2), gx2, "global invalid ->[]byte")
144 assert(string(r1), gx1, "->[]rune")
145 assert(string(r2), gx2fix, "invalid ->[]rune")
146 assert(string(b1), gx1, "->[]byte")
147 assert(string(b2), gx2, "invalid ->[]byte")