summaryrefslogtreecommitdiff
path: root/libgo/go/bytes/example_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-01-09 01:23:08 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-09 01:23:08 +0000
commit1a2f01efa63036a5104f203a4789e682c0e0915d (patch)
tree373e15778dc8295354584e1f86915ae493b604ff /libgo/go/bytes/example_test.go
parent8799df67f2dab88f9fda11739c501780a85575e2 (diff)
libgo: update to Go1.10beta1
Update the Go library to the 1.10beta1 release. Requires a few changes to the compiler for modifications to the map runtime code, and to handle some nowritebarrier cases in the runtime. Reviewed-on: https://go-review.googlesource.com/86455 gotools/: * Makefile.am (go_cmd_vet_files): New variable. (go_cmd_buildid_files, go_cmd_test2json_files): New variables. (s-zdefaultcc): Change from constants to functions. (noinst_PROGRAMS): Add vet, buildid, and test2json. (cgo$(EXEEXT)): Link against $(LIBGOTOOL). (vet$(EXEEXT)): New target. (buildid$(EXEEXT)): New target. (test2json$(EXEEXT)): New target. (install-exec-local): Install all $(noinst_PROGRAMS). (uninstall-local): Uninstasll all $(noinst_PROGRAMS). (check-go-tool): Depend on $(noinst_PROGRAMS). Copy down objabi.go. (check-runtime): Depend on $(noinst_PROGRAMS). (check-cgo-test, check-carchive-test): Likewise. (check-vet): New target. (check): Depend on check-vet. Look at cmd_vet-testlog. (.PHONY): Add check-vet. * Makefile.in: Rebuild. From-SVN: r256365
Diffstat (limited to 'libgo/go/bytes/example_test.go')
-rw-r--r--libgo/go/bytes/example_test.go141
1 files changed, 141 insertions, 0 deletions
diff --git a/libgo/go/bytes/example_test.go b/libgo/go/bytes/example_test.go
index 93972770ab2..5b7a46058f5 100644
--- a/libgo/go/bytes/example_test.go
+++ b/libgo/go/bytes/example_test.go
@@ -119,6 +119,32 @@ func ExampleContains() {
// true
}
+func ExampleContainsAny() {
+ fmt.Println(bytes.ContainsAny([]byte("I like seafood."), "fÄo!"))
+ fmt.Println(bytes.ContainsAny([]byte("I like seafood."), "去是伟大的."))
+ fmt.Println(bytes.ContainsAny([]byte("I like seafood."), ""))
+ fmt.Println(bytes.ContainsAny([]byte(""), ""))
+ // Output:
+ // true
+ // true
+ // false
+ // false
+}
+
+func ExampleContainsRune() {
+ fmt.Println(bytes.ContainsRune([]byte("I like seafood."), 'f'))
+ fmt.Println(bytes.ContainsRune([]byte("I like seafood."), 'ö'))
+ fmt.Println(bytes.ContainsRune([]byte("去是伟大的!"), '大'))
+ fmt.Println(bytes.ContainsRune([]byte("去是伟大的!"), '!'))
+ fmt.Println(bytes.ContainsRune([]byte(""), '@'))
+ // Output:
+ // true
+ // false
+ // true
+ // true
+ // false
+}
+
func ExampleCount() {
fmt.Println(bytes.Count([]byte("cheese"), []byte("e")))
fmt.Println(bytes.Count([]byte("five"), []byte(""))) // before & after each rune
@@ -127,6 +153,14 @@ func ExampleCount() {
// 5
}
+func ExampleEqual() {
+ fmt.Println(bytes.Equal([]byte("Go"), []byte("Go")))
+ fmt.Println(bytes.Equal([]byte("Go"), []byte("C++")))
+ // Output:
+ // true
+ // false
+}
+
func ExampleEqualFold() {
fmt.Println(bytes.EqualFold([]byte("Go"), []byte("go")))
// Output: true
@@ -162,6 +196,14 @@ func ExampleIndex() {
// -1
}
+func ExampleIndexByte() {
+ fmt.Println(bytes.IndexByte([]byte("chicken"), byte('k')))
+ fmt.Println(bytes.IndexByte([]byte("chicken"), byte('g')))
+ // Output:
+ // 4
+ // -1
+}
+
func ExampleIndexFunc() {
f := func(c rune) bool {
return unicode.Is(unicode.Han, c)
@@ -199,6 +241,36 @@ func ExampleLastIndex() {
// -1
}
+func ExampleLastIndexAny() {
+ fmt.Println(bytes.LastIndexAny([]byte("go gopher"), "MüQp"))
+ fmt.Println(bytes.LastIndexAny([]byte("go 地鼠"), "地大"))
+ fmt.Println(bytes.LastIndexAny([]byte("go gopher"), "z,!."))
+ // Output:
+ // 5
+ // 3
+ // -1
+}
+
+func ExampleLastIndexByte() {
+ fmt.Println(bytes.LastIndexByte([]byte("go gopher"), byte('g')))
+ fmt.Println(bytes.LastIndexByte([]byte("go gopher"), byte('r')))
+ fmt.Println(bytes.LastIndexByte([]byte("go gopher"), byte('z')))
+ // Output:
+ // 3
+ // 8
+ // -1
+}
+
+func ExampleLastIndexFunc() {
+ fmt.Println(bytes.LastIndexFunc([]byte("go gopher!"), unicode.IsLetter))
+ fmt.Println(bytes.LastIndexFunc([]byte("go gopher!"), unicode.IsPunct))
+ fmt.Println(bytes.LastIndexFunc([]byte("go gopher!"), unicode.IsNumber))
+ // Output:
+ // 8
+ // 9
+ // -1
+}
+
func ExampleJoin() {
s := [][]byte{[]byte("foo"), []byte("bar"), []byte("baz")}
fmt.Printf("%s", bytes.Join(s, []byte(", ")))
@@ -218,6 +290,23 @@ func ExampleReplace() {
// moo moo moo
}
+func ExampleRunes() {
+ rs := bytes.Runes([]byte("go gopher"))
+ for _, r := range rs {
+ fmt.Printf("%#U\n", r)
+ }
+ // Output:
+ // U+0067 'g'
+ // U+006F 'o'
+ // U+0020 ' '
+ // U+0067 'g'
+ // U+006F 'o'
+ // U+0070 'p'
+ // U+0068 'h'
+ // U+0065 'e'
+ // U+0072 'r'
+}
+
func ExampleSplit() {
fmt.Printf("%q\n", bytes.Split([]byte("a,b,c"), []byte(",")))
fmt.Printf("%q\n", bytes.Split([]byte("a man a plan a canal panama"), []byte("a ")))
@@ -267,6 +356,18 @@ func ExampleTrim() {
// Output: ["Achtung! Achtung"]
}
+func ExampleTrimFunc() {
+ fmt.Println(string(bytes.TrimFunc([]byte("go-gopher!"), unicode.IsLetter)))
+ fmt.Println(string(bytes.TrimFunc([]byte("\"go-gopher!\""), unicode.IsLetter)))
+ fmt.Println(string(bytes.TrimFunc([]byte("go-gopher!"), unicode.IsPunct)))
+ fmt.Println(string(bytes.TrimFunc([]byte("1234go-gopher!567"), unicode.IsNumber)))
+ // Output:
+ // -gopher!
+ // "go-gopher!"
+ // go-gopher
+ // go-gopher!
+}
+
func ExampleMap() {
rot13 := func(r rune) rune {
switch {
@@ -281,11 +382,43 @@ func ExampleMap() {
// Output: 'Gjnf oevyyvt naq gur fyvgul tbcure...
}
+func ExampleTrimLeft() {
+ fmt.Print(string(bytes.TrimLeft([]byte("453gopher8257"), "0123456789")))
+ // Output:
+ // gopher8257
+}
+
+func ExampleTrimLeftFunc() {
+ fmt.Println(string(bytes.TrimLeftFunc([]byte("go-gopher"), unicode.IsLetter)))
+ fmt.Println(string(bytes.TrimLeftFunc([]byte("go-gopher!"), unicode.IsPunct)))
+ fmt.Println(string(bytes.TrimLeftFunc([]byte("1234go-gopher!567"), unicode.IsNumber)))
+ // Output:
+ // -gopher
+ // go-gopher!
+ // go-gopher!567
+}
+
func ExampleTrimSpace() {
fmt.Printf("%s", bytes.TrimSpace([]byte(" \t\n a lone gopher \n\t\r\n")))
// Output: a lone gopher
}
+func ExampleTrimRight() {
+ fmt.Print(string(bytes.TrimRight([]byte("453gopher8257"), "0123456789")))
+ // Output:
+ // 453gopher
+}
+
+func ExampleTrimRightFunc() {
+ fmt.Println(string(bytes.TrimRightFunc([]byte("go-gopher"), unicode.IsLetter)))
+ fmt.Println(string(bytes.TrimRightFunc([]byte("go-gopher!"), unicode.IsPunct)))
+ fmt.Println(string(bytes.TrimRightFunc([]byte("1234go-gopher!567"), unicode.IsNumber)))
+ // Output:
+ // go-
+ // go-gopher
+ // 1234go-gopher!
+}
+
func ExampleToUpper() {
fmt.Printf("%s", bytes.ToUpper([]byte("Gopher")))
// Output: GOPHER
@@ -295,3 +428,11 @@ func ExampleToLower() {
fmt.Printf("%s", bytes.ToLower([]byte("Gopher")))
// Output: gopher
}
+
+func ExampleReader_Len() {
+ fmt.Println(bytes.NewReader([]byte("Hi!")).Len())
+ fmt.Println(bytes.NewReader([]byte("こんにちは!")).Len())
+ // Output:
+ // 3
+ // 16
+}