forked from mirror/stringy
Expand test cases for Boolean
This commit is contained in:
parent
aedd444bba
commit
7befa36001
|
@ -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) {
|
||||||
|
if val := New(s).Boolean(); !val {
|
||||||
t.Errorf("Expected: to be true but got: %v", 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) {
|
||||||
|
if val := New(s).Boolean(); val {
|
||||||
t.Errorf("Expected: to be false but got: %v", val)
|
t.Errorf("Expected: to be false but got: %v", val)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInput_BooleanError(t *testing.T) {
|
func TestInput_BooleanError(t *testing.T) {
|
||||||
|
strs := []string{"invalid", "-1", ""}
|
||||||
|
for _, s := range strs {
|
||||||
|
t.Run(s, func(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err == nil {
|
if err := recover(); err == nil {
|
||||||
t.Errorf("Error expected")
|
t.Errorf("Error expected")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
str := New("invalid")
|
val := New(s).Boolean()
|
||||||
val := str.Boolean()
|
t.Errorf("Expected: to panic but got: %v", val)
|
||||||
if val {
|
})
|
||||||
t.Errorf("Expected: to be false but got: %v", val)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInput_CamelCase(t *testing.T) {
|
func TestInput_CamelCase(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue