summaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.test/test/string_lit.go
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/go.test/test/string_lit.go
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/go.test/test/string_lit.go')
-rw-r--r--gcc/testsuite/go.test/test/string_lit.go120
1 files changed, 120 insertions, 0 deletions
diff --git a/gcc/testsuite/go.test/test/string_lit.go b/gcc/testsuite/go.test/test/string_lit.go
new file mode 100644
index 000000000..4358dd8e8
--- /dev/null
+++ b/gcc/testsuite/go.test/test/string_lit.go
@@ -0,0 +1,120 @@
+// $G $F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+package main
+
+import "os"
+
+var ecode int
+
+func assert(a, b, c string) {
+ if a != b {
+ ecode = 1
+ print("FAIL: ", c, ": ", a, "!=", b, "\n")
+ var max int = len(a)
+ if len(b) > max {
+ max = len(b)
+ }
+ for i := 0; i < max; i++ {
+ ac := 0
+ bc := 0
+ if i < len(a) {
+ ac = int(a[i])
+ }
+ if i < len(b) {
+ bc = int(b[i])
+ }
+ if ac != bc {
+ print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n")
+ }
+ }
+ }
+}
+
+const (
+ gx1 = "aä本☺"
+ gx2 = "aä\xFF\xFF本☺"
+ gx2fix = "aä\uFFFD\uFFFD本☺"
+)
+
+var (
+ gr1 = []int(gx1)
+ gr2 = []int(gx2)
+ gb1 = []byte(gx1)
+ gb2 = []byte(gx2)
+)
+
+func main() {
+ ecode = 0
+ s :=
+ "" +
+ " " +
+ "'`" +
+ "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` +
+ `\x\u\U\`
+
+ 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)")
+ assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
+ "\a\b\f\n\r\t\v\\\"",
+ "backslashes")
+ assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
+ `\a\b\f\n\r\t\v\\\"`,
+ "backslashes (backquote)")
+ assert("\x00\x53\000\xca\376S몾몾",
+ "\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
+ "backslashes 2")
+ assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
+ `\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
+ "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.
+ var r int32
+ r = 0x10ffff; // largest rune value
+ 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")
+
+ assert(string(gr1), gx1, "global ->[]int")
+ assert(string(gr2), gx2fix, "global invalid ->[]int")
+ assert(string(gb1), gx1, "->[]byte")
+ assert(string(gb2), gx2, "global invalid ->[]byte")
+
+ var (
+ r1 = []int(gx1)
+ r2 = []int(gx2)
+ b1 = []byte(gx1)
+ b2 = []byte(gx2)
+ )
+ assert(string(r1), gx1, "->[]int")
+ assert(string(r2), gx2fix, "invalid ->[]int")
+ assert(string(b1), gx1, "->[]byte")
+ assert(string(b2), gx2, "invalid ->[]byte")
+
+ os.Exit(ecode)
+}