summaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.test/test/stringrange.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/stringrange.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/stringrange.go')
-rw-r--r--gcc/testsuite/go.test/test/stringrange.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/gcc/testsuite/go.test/test/stringrange.go b/gcc/testsuite/go.test/test/stringrange.go
new file mode 100644
index 000000000..d5ada2628
--- /dev/null
+++ b/gcc/testsuite/go.test/test/stringrange.go
@@ -0,0 +1,61 @@
+// $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 (
+ "fmt"
+ "os"
+ "utf8"
+)
+
+func main() {
+ s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U0010FFFFx"
+ expect := []int{ 0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x' }
+ offset := 0
+ var i, c int
+ ok := true
+ cnum := 0
+ for i, c = range s {
+ rune, size := utf8.DecodeRuneInString(s[i:len(s)]) // check it another way
+ if i != offset {
+ fmt.Printf("unexpected offset %d not %d\n", i, offset)
+ ok = false
+ }
+ if rune != expect[cnum] {
+ fmt.Printf("unexpected rune %d from DecodeRuneInString: %x not %x\n", i, rune, expect[cnum])
+ ok = false
+ }
+ if c != expect[cnum] {
+ fmt.Printf("unexpected rune %d from range: %x not %x\n", i, rune, expect[cnum])
+ ok = false
+ }
+ offset += size
+ cnum++
+ }
+ if i != len(s)-1 {
+ fmt.Println("after loop i is", i, "not", len(s)-1)
+ ok = false
+ }
+
+ i = 12345
+ c = 23456
+ for i, c = range "" {
+ }
+ if i != 12345 {
+ fmt.Println("range empty string assigned to index:", i)
+ ok = false
+ }
+ if c != 23456 {
+ fmt.Println("range empty string assigned to value:", c)
+ ok = false
+ }
+
+ if !ok {
+ fmt.Println("BUG: stringrange")
+ os.Exit(1)
+ }
+}