diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
commit | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch) | |
tree | 4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/pkg/bytes/bytes_test.go | |
parent | c8bf49ef8a92e2337b69c14b9b88396efe498600 (diff) | |
download | golang-51f2ca399fb8da86b2e7b3a0582e083fab731a98.tar.gz |
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/pkg/bytes/bytes_test.go')
-rw-r--r-- | src/pkg/bytes/bytes_test.go | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index ab5da4fbf..394dd7a44 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -785,6 +785,16 @@ func TestMap(t *testing.T) { if string(m) != expect { t.Errorf("drop: expected %q got %q", expect, m) } + + // 6. Invalid rune + invalidRune := func(r rune) rune { + return utf8.MaxRune + 1 + } + m = Map(invalidRune, []byte("x")) + expect = "\uFFFD" + if string(m) != expect { + t.Errorf("invalidRune: expected %q got %q", expect, m) + } } func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) } @@ -1073,6 +1083,8 @@ var TitleTests = []TitleTest{ {"123a456", "123a456"}, {"double-blind", "Double-Blind"}, {"ÿøû", "Ÿøû"}, + {"with_underscore", "With_underscore"}, + {"unicode \xe2\x80\xa8 line separator", "Unicode \xe2\x80\xa8 Line Separator"}, } func TestTitle(t *testing.T) { @@ -1132,7 +1144,7 @@ func TestEqualFold(t *testing.T) { func TestBufferGrowNegative(t *testing.T) { defer func() { if err := recover(); err == nil { - t.Fatal("Grow(-1) should have paniced") + t.Fatal("Grow(-1) should have panicked") } }() var b Buffer @@ -1142,7 +1154,7 @@ func TestBufferGrowNegative(t *testing.T) { func TestBufferTruncateNegative(t *testing.T) { defer func() { if err := recover(); err == nil { - t.Fatal("Truncate(-1) should have paniced") + t.Fatal("Truncate(-1) should have panicked") } }() var b Buffer @@ -1152,7 +1164,7 @@ func TestBufferTruncateNegative(t *testing.T) { func TestBufferTruncateOutOfRange(t *testing.T) { defer func() { if err := recover(); err == nil { - t.Fatal("Truncate(20) should have paniced") + t.Fatal("Truncate(20) should have panicked") } }() var b Buffer @@ -1160,6 +1172,24 @@ func TestBufferTruncateOutOfRange(t *testing.T) { b.Truncate(20) } +var containsTests = []struct { + b, subslice []byte + want bool +}{ + {[]byte("hello"), []byte("hel"), true}, + {[]byte("日本語"), []byte("日本"), true}, + {[]byte("hello"), []byte("Hello, world"), false}, + {[]byte("東京"), []byte("京東"), false}, +} + +func TestContains(t *testing.T) { + for _, tt := range containsTests { + if got := Contains(tt.b, tt.subslice); got != tt.want { + t.Errorf("Contains(%q, %q) = %v, want %v", tt.b, tt.subslice, got, tt.want) + } + } +} + var makeFieldsInput = func() []byte { x := make([]byte, 1<<20) // Input is ~10% space, ~10% 2-byte UTF-8, rest ASCII non-space. |