]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: add tests for FormatBool and AppendBool
authorShawn Smith <shawn.p.smith@gmail.com>
Fri, 27 Dec 2013 16:40:14 +0000 (08:40 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 27 Dec 2013 16:40:14 +0000 (08:40 -0800)
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/42480043

src/pkg/strconv/atob_test.go

index a7c1454eb1ef9390d63b7f5048181b1ebb05dcf9..28f469f5854d8a504674e88cab58a9f2d5b98d13 100644 (file)
@@ -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)
+               }
+       }
+}