Commit 77d01504 authored by earncef's avatar earncef Committed by Hanzei
Browse files

Nil value returns empty string. (#76)

parent d1e4838f
......@@ -20,6 +20,8 @@ func (v *Value) Data() interface{} {
// String returns the value always as a string
func (v *Value) String() string {
switch {
case v.IsNil():
return ""
case v.IsStr():
return v.Str()
case v.IsBool():
......
......@@ -67,10 +67,12 @@ func TestStringTypeFloat(t *testing.T) {
func TestStringTypeOther(t *testing.T) {
m := objx.Map{
"other": []string{"foo", "bar"},
"other": []string{"foo", "bar"},
"nilValue": nil,
}
assert.Equal(t, "[]string{\"foo\", \"bar\"}", m.Get("other").String())
assert.Equal(t, "", m.Get("nilValue").String())
}
func TestStringSliceTypeString(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment