diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-03-02 20:01:37 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-03-02 20:01:37 +0000 |
commit | 501699af1603287b1b47ac450fd6eeb826aa76b1 (patch) | |
tree | 3eeb8918d39d675108073c8b76d6dd10586a608c /libgo/go/bytes | |
parent | 34c5f21a387dc461042bafc3052ce6e1af786a77 (diff) | |
download | gcc-501699af1603287b1b47ac450fd6eeb826aa76b1.zip gcc-501699af1603287b1b47ac450fd6eeb826aa76b1.tar.gz gcc-501699af1603287b1b47ac450fd6eeb826aa76b1.tar.bz2 |
libgo: Update to weekly.2012-02-22 release.
From-SVN: r184819
Diffstat (limited to 'libgo/go/bytes')
-rw-r--r-- | libgo/go/bytes/bytes.go | 2 | ||||
-rw-r--r-- | libgo/go/bytes/bytes_test.go | 41 | ||||
-rw-r--r-- | libgo/go/bytes/example_test.go | 4 |
3 files changed, 28 insertions, 19 deletions
diff --git a/libgo/go/bytes/bytes.go b/libgo/go/bytes/bytes.go index e94a0ec..7d1426f 100644 --- a/libgo/go/bytes/bytes.go +++ b/libgo/go/bytes/bytes.go @@ -13,6 +13,7 @@ import ( // Compare returns an integer comparing the two byte arrays lexicographically. // The result will be 0 if a==b, -1 if a < b, and +1 if a > b +// A nil argument is equivalent to an empty slice. func Compare(a, b []byte) int { m := len(a) if m > len(b) { @@ -37,6 +38,7 @@ func Compare(a, b []byte) int { } // Equal returns a boolean reporting whether a == b. +// A nil argument is equivalent to an empty slice. func Equal(a, b []byte) bool func equalPortable(a, b []byte) bool { diff --git a/libgo/go/bytes/bytes_test.go b/libgo/go/bytes/bytes_test.go index 2a1d41b..000f235 100644 --- a/libgo/go/bytes/bytes_test.go +++ b/libgo/go/bytes/bytes_test.go @@ -46,32 +46,39 @@ type BinOpTest struct { i int } -var comparetests = []BinOpTest{ - {"", "", 0}, - {"a", "", 1}, - {"", "a", -1}, - {"abc", "abc", 0}, - {"ab", "abc", -1}, - {"abc", "ab", 1}, - {"x", "ab", 1}, - {"ab", "x", -1}, - {"x", "a", 1}, - {"b", "x", -1}, +var compareTests = []struct { + a, b []byte + i int +}{ + {[]byte(""), []byte(""), 0}, + {[]byte("a"), []byte(""), 1}, + {[]byte(""), []byte("a"), -1}, + {[]byte("abc"), []byte("abc"), 0}, + {[]byte("ab"), []byte("abc"), -1}, + {[]byte("abc"), []byte("ab"), 1}, + {[]byte("x"), []byte("ab"), 1}, + {[]byte("ab"), []byte("x"), -1}, + {[]byte("x"), []byte("a"), 1}, + {[]byte("b"), []byte("x"), -1}, + // nil tests + {nil, nil, 0}, + {[]byte(""), nil, 0}, + {nil, []byte(""), 0}, + {[]byte("a"), nil, 1}, + {nil, []byte("a"), -1}, } func TestCompare(t *testing.T) { - for _, tt := range comparetests { - a := []byte(tt.a) - b := []byte(tt.b) - cmp := Compare(a, b) + for _, tt := range compareTests { + cmp := Compare(tt.a, tt.b) if cmp != tt.i { t.Errorf(`Compare(%q, %q) = %v`, tt.a, tt.b, cmp) } - eql := Equal(a, b) + eql := Equal(tt.a, tt.b) if eql != (tt.i == 0) { t.Errorf(`Equal(%q, %q) = %v`, tt.a, tt.b, eql) } - eql = EqualPortable(a, b) + eql = EqualPortable(tt.a, tt.b) if eql != (tt.i == 0) { t.Errorf(`EqualPortable(%q, %q) = %v`, tt.a, tt.b, eql) } diff --git a/libgo/go/bytes/example_test.go b/libgo/go/bytes/example_test.go index 0234a01..6fe8cd5 100644 --- a/libgo/go/bytes/example_test.go +++ b/libgo/go/bytes/example_test.go @@ -11,18 +11,18 @@ import ( "os" ) -// Hello world! func ExampleBuffer() { var b Buffer // A Buffer needs no initialization. b.Write([]byte("Hello ")) b.Write([]byte("world!")) b.WriteTo(os.Stdout) + // Output: Hello world! } -// Gophers rule! func ExampleBuffer_reader() { // A Buffer can turn a string or a []byte into an io.Reader. buf := NewBufferString("R29waGVycyBydWxlIQ==") dec := base64.NewDecoder(base64.StdEncoding, buf) io.Copy(os.Stdout, dec) + // Output: Gophers rule! } |