aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShawn Smith <shawn.p.smith@gmail.com>2013-12-27 08:40:14 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2013-12-27 08:40:14 -0800
commitd1a9143669633cd2f47f00b074d6534fc77e1e4d (patch)
tree0438d8beb37cb73f9bc765b09e5a97e2a3d4a8a9 /src
parentf485e9859a4cbb1154541afb0c3659578e035f63 (diff)
downloadgo-d1a9143669633cd2f47f00b074d6534fc77e1e4d.tar.xz
strconv: add tests for FormatBool and AppendBool
R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/42480043
Diffstat (limited to 'src')
-rw-r--r--src/pkg/strconv/atob_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/pkg/strconv/atob_test.go b/src/pkg/strconv/atob_test.go
index a7c1454eb1..28f469f585 100644
--- a/src/pkg/strconv/atob_test.go
+++ b/src/pkg/strconv/atob_test.go
@@ -5,6 +5,7 @@
package strconv_test
import (
+ "bytes"
. "strconv"
"testing"
)
@@ -55,3 +56,36 @@ func TestParseBool(t *testing.T) {
}
}
}
+
+var boolString = map[bool]string{
+ true: "true",
+ false: "false",
+}
+
+func TestFormatBool(t *testing.T) {
+ for b, s := range boolString {
+ if f := FormatBool(b); f != s {
+ t.Errorf(`FormatBool(%v): expected %q but got %q`, b, s, f)
+ }
+ }
+}
+
+type appendBoolTest struct {
+ b bool
+ in []byte
+ out []byte
+}
+
+var appendBoolTests = []appendBoolTest{
+ {true, []byte("foo "), []byte("foo true")},
+ {false, []byte("foo "), []byte("foo false")},
+}
+
+func TestAppendBool(t *testing.T) {
+ for _, test := range appendBoolTests {
+ b := AppendBool(test.in, test.b)
+ if !bytes.Equal(b, test.out) {
+ t.Errorf("AppendBool(%q, %v): expected %q but got %q", test.in, test.b, test.out, b)
+ }
+ }
+}