1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 type atobTest struct {
19 var atobtests = []atobTest{
20 {"", false, ErrSyntax},
21 {"asdf", false, ErrSyntax},
25 {"FALSE", false, nil},
26 {"false", false, nil},
27 {"False", false, nil},
36 func TestParseBool(t *testing.T) {
37 for _, test := range atobtests {
38 b, e := ParseBool(test.in)
42 t.Errorf("ParseBool(%s) = nil; want %s", test.in, test.err)
44 // NumError assertion must succeed; it's the only thing we return.
45 if e.(*NumError).Err != test.err {
46 t.Errorf("ParseBool(%s) = %s; want %s", test.in, e, test.err)
51 t.Errorf("ParseBool(%s) = %s; want nil", test.in, e)
54 t.Errorf("ParseBool(%s) = %t; want %t", test.in, b, test.out)
60 var boolString = map[bool]string{
65 func TestFormatBool(t *testing.T) {
66 for b, s := range boolString {
67 if f := FormatBool(b); f != s {
68 t.Errorf("FormatBool(%v) = %q; want %q", b, f, s)
73 type appendBoolTest struct {
79 var appendBoolTests = []appendBoolTest{
80 {true, []byte("foo "), []byte("foo true")},
81 {false, []byte("foo "), []byte("foo false")},
84 func TestAppendBool(t *testing.T) {
85 for _, test := range appendBoolTests {
86 b := AppendBool(test.in, test.b)
87 if !bytes.Equal(b, test.out) {
88 t.Errorf("AppendBool(%q, %v) = %q; want %q", test.in, test.b, b, test.out)