2010-03-25 12:50:07 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package strconv_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "strconv"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type atobTest struct {
|
|
|
|
in string
|
|
|
|
out bool
|
2011-11-01 20:05:34 -06:00
|
|
|
err error
|
2010-03-25 12:50:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var atobtests = []atobTest{
|
2011-10-27 20:46:31 -06:00
|
|
|
{"", false, ErrSyntax},
|
|
|
|
{"asdf", false, ErrSyntax},
|
2010-10-22 11:06:33 -06:00
|
|
|
{"0", false, nil},
|
|
|
|
{"f", false, nil},
|
|
|
|
{"F", false, nil},
|
|
|
|
{"FALSE", false, nil},
|
|
|
|
{"false", false, nil},
|
2011-05-12 23:00:50 -06:00
|
|
|
{"False", false, nil},
|
2010-10-22 11:06:33 -06:00
|
|
|
{"1", true, nil},
|
|
|
|
{"t", true, nil},
|
|
|
|
{"T", true, nil},
|
|
|
|
{"TRUE", true, nil},
|
|
|
|
{"true", true, nil},
|
2011-05-12 23:00:50 -06:00
|
|
|
{"True", true, nil},
|
2010-03-25 12:50:07 -06:00
|
|
|
}
|
|
|
|
|
2011-12-05 13:48:21 -07:00
|
|
|
func TestParseBool(t *testing.T) {
|
2010-03-25 12:50:07 -06:00
|
|
|
for _, test := range atobtests {
|
2011-12-05 13:48:21 -07:00
|
|
|
b, e := ParseBool(test.in)
|
2010-03-25 12:50:07 -06:00
|
|
|
if test.err != nil {
|
|
|
|
// expect an error
|
|
|
|
if e == nil {
|
|
|
|
t.Errorf("%s: expected %s but got nil", test.in, test.err)
|
|
|
|
} else {
|
|
|
|
// NumError assertion must succeed; it's the only thing we return.
|
2011-11-01 20:05:34 -06:00
|
|
|
if test.err != e.(*NumError).Err {
|
2010-03-25 12:50:07 -06:00
|
|
|
t.Errorf("%s: expected %s but got %s", test.in, test.err, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if e != nil {
|
2010-12-07 14:42:54 -07:00
|
|
|
t.Errorf("%s: expected no error but got %s", test.in, e)
|
2010-03-25 12:50:07 -06:00
|
|
|
}
|
|
|
|
if b != test.out {
|
|
|
|
t.Errorf("%s: expected %t but got %t", test.in, test.out, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|