forked from mirror/stringy
Merge pull request #15 from ursetto/boolean-fix
Treat "true" as a valid boolean
This commit is contained in:
commit
ac138e2d61
|
@ -18,4 +18,4 @@ const (
|
||||||
var False = []string{"off", "no", "0", "false"}
|
var False = []string{"off", "no", "0", "false"}
|
||||||
|
|
||||||
// True is slice of array for true logical representation in string
|
// True is slice of array for true logical representation in string
|
||||||
var True = []string{"on", "yes", "1", "True"}
|
var True = []string{"on", "yes", "1", "true"}
|
||||||
|
|
|
@ -29,33 +29,42 @@ func TestInput_EmptyNoMatchBetween(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInput_Boolean(t *testing.T) {
|
func TestInput_BooleanTrue(t *testing.T) {
|
||||||
str := New("on")
|
strs := []string{"on", "On", "yes", "YES", "1", "true"}
|
||||||
val := str.Boolean()
|
for _, s := range strs {
|
||||||
if !val {
|
t.Run(s, func(t *testing.T) {
|
||||||
t.Errorf("Expected: to be true but got: %v", val)
|
if val := New(s).Boolean(); !val {
|
||||||
|
t.Errorf("Expected: to be true but got: %v", val)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInput_BooleanOff(t *testing.T) {
|
func TestInput_BooleanFalse(t *testing.T) {
|
||||||
str := New("off")
|
strs := []string{"off", "Off", "no", "NO", "0", "false"}
|
||||||
val := str.Boolean()
|
for _, s := range strs {
|
||||||
if val {
|
t.Run(s, func(t *testing.T) {
|
||||||
t.Errorf("Expected: to be false but got: %v", val)
|
if val := New(s).Boolean(); val {
|
||||||
|
t.Errorf("Expected: to be false but got: %v", val)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInput_BooleanError(t *testing.T) {
|
func TestInput_BooleanError(t *testing.T) {
|
||||||
defer func() {
|
strs := []string{"invalid", "-1", ""}
|
||||||
if err := recover(); err == nil {
|
for _, s := range strs {
|
||||||
t.Errorf("Error expected")
|
t.Run(s, func(t *testing.T) {
|
||||||
}
|
defer func() {
|
||||||
}()
|
if err := recover(); err == nil {
|
||||||
str := New("invalid")
|
t.Errorf("Error expected")
|
||||||
val := str.Boolean()
|
}
|
||||||
if val {
|
}()
|
||||||
t.Errorf("Expected: to be false but got: %v", val)
|
val := New(s).Boolean()
|
||||||
|
t.Errorf("Expected: to panic but got: %v", val)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInput_CamelCase(t *testing.T) {
|
func TestInput_CamelCase(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue