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("%s: expected %s but got nil", test
.in
, test
.err
)
44 // NumError assertion must succeed; it's the only thing we return.
45 if test
.err
!= e
.(*NumError
).Err
{
46 t
.Errorf("%s: expected %s but got %s", test
.in
, test
.err
, e
)
51 t
.Errorf("%s: expected no error but got %s", test
.in
, e
)
54 t
.Errorf("%s: expected %t but got %t", test
.in
, test
.out
, b
)
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): expected %q but got %q`, b
, s
, f
)
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): expected %q but got %q", test
.in
, test
.b
, test
.out
, b
)