Skip to content

Commit

Permalink
Nil value returns empty string. (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
geseq authored and hanzei committed May 31, 2018
1 parent d1e4838 commit 77d0150
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 3 additions & 1 deletion value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 77d0150

Please sign in to comment.