From 3ee0744c06503eece696a615b1f8b37b4a0ed8a8 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Wed, 11 Sep 2013 21:20:15 +1000 Subject: 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 --- src/pkg/bytes/bytes_test.go | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/pkg/bytes/bytes_test.go') 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. -- cgit v1.3