test json invalid boolean primitives ; only valid when wrapped
This commit is contained in:
parent
c2e8efc82b
commit
e2bda2b2dd
|
@ -30,6 +30,7 @@ func TestSimpleString(t *testing.T) {
|
|||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSlice(t *testing.T) {
|
||||
p := Parameter{Parsed: false, File: false, Value: `["str1", "str2"]`}
|
||||
|
||||
|
@ -73,3 +74,42 @@ func TestStringSlice(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func TestJsonPrimitiveBool(t *testing.T) {
|
||||
tcases := []struct {
|
||||
Raw string
|
||||
BoolValue bool
|
||||
}{
|
||||
{"true", true},
|
||||
{"false", false},
|
||||
}
|
||||
|
||||
for i, tcase := range tcases {
|
||||
t.Run("case "+string(i), func(t *testing.T) {
|
||||
p := Parameter{Parsed: false, File: false, Value: tcase.Raw}
|
||||
|
||||
err := p.Parse()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: <%s>", err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if !p.Parsed {
|
||||
t.Errorf("expected parameter to be parsed")
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
cast, canCast := p.Value.(bool)
|
||||
if !canCast {
|
||||
t.Errorf("expected parameter to be a bool")
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if cast != tcase.BoolValue {
|
||||
t.Errorf("expected a value of %T, got %T", tcase.BoolValue, cast)
|
||||
t.FailNow()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue