aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/bytes/bytes_test.go
diff options
context:
space:
mode:
authorDave Cheney <dave@cheney.net>2013-09-11 21:20:15 +1000
committerDave Cheney <dave@cheney.net>2013-09-11 21:20:15 +1000
commit3ee0744c06503eece696a615b1f8b37b4a0ed8a8 (patch)
tree619936bd19bc70e1fab0f77f32613f2e10375070 /src/pkg/bytes/bytes_test.go
parentb34ec90e1945af8ed22bf96254deb4c637c0bfbc (diff)
downloadgo-3ee0744c06503eece696a615b1f8b37b4a0ed8a8.tar.xz
bytes: additional test coverage
Add coverage for some uncovered bytes methods. The increase in actual coverage is disapointing small. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/13651044
Diffstat (limited to 'src/pkg/bytes/bytes_test.go')
-rw-r--r--src/pkg/bytes/bytes_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go
index 29134ac0be..ab5da4fbf0 100644
--- a/src/pkg/bytes/bytes_test.go
+++ b/src/pkg/bytes/bytes_test.go
@@ -143,6 +143,7 @@ var indexTests = []BinOpTest{
{"", "a", -1},
{"", "foo", -1},
{"fo", "foo", -1},
+ {"foo", "baz", -1},
{"foo", "foo", 0},
{"oofofoofooo", "f", 2},
{"oofofoofooo", "foo", 4},
@@ -1082,6 +1083,24 @@ func TestTitle(t *testing.T) {
}
}
+var ToTitleTests = []TitleTest{
+ {"", ""},
+ {"a", "A"},
+ {" aaa aaa aaa ", " AAA AAA AAA "},
+ {" Aaa Aaa Aaa ", " AAA AAA AAA "},
+ {"123a456", "123A456"},
+ {"double-blind", "DOUBLE-BLIND"},
+ {"ÿøû", "ŸØÛ"},
+}
+
+func TestToTitle(t *testing.T) {
+ for _, tt := range ToTitleTests {
+ if s := string(ToTitle([]byte(tt.in))); s != tt.out {
+ t.Errorf("ToTitle(%q) = %q, want %q", tt.in, s, tt.out)
+ }
+ }
+}
+
var EqualFoldTests = []struct {
s, t string
out bool
@@ -1110,6 +1129,37 @@ func TestEqualFold(t *testing.T) {
}
}
+func TestBufferGrowNegative(t *testing.T) {
+ defer func() {
+ if err := recover(); err == nil {
+ t.Fatal("Grow(-1) should have paniced")
+ }
+ }()
+ var b Buffer
+ b.Grow(-1)
+}
+
+func TestBufferTruncateNegative(t *testing.T) {
+ defer func() {
+ if err := recover(); err == nil {
+ t.Fatal("Truncate(-1) should have paniced")
+ }
+ }()
+ var b Buffer
+ b.Truncate(-1)
+}
+
+func TestBufferTruncateOutOfRange(t *testing.T) {
+ defer func() {
+ if err := recover(); err == nil {
+ t.Fatal("Truncate(20) should have paniced")
+ }
+ }()
+ var b Buffer
+ b.Write(make([]byte, 10))
+ b.Truncate(20)
+}
+
var makeFieldsInput = func() []byte {
x := make([]byte, 1<<20)
// Input is ~10% space, ~10% 2-byte UTF-8, rest ASCII non-space.