Skip to content

Commit

Permalink
add bool empty option
Browse files Browse the repository at this point in the history
do it like the standard library does

add test for boolean value inputs for the isEmpty function
  • Loading branch information
jackspirou committed Mar 3, 2016
1 parent a4eecd4 commit e27e134
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ func isEmpty(rv reflect.Value) bool {
if rv.Len() == 0 {
return true
}
case reflect.Bool:
return !rv.Bool()
}

return false
Expand Down
13 changes: 13 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net"
"reflect"
"testing"
"time"
)
Expand Down Expand Up @@ -564,3 +565,15 @@ func ExampleEncoder_Encode() {
// key1 = "val1"
// key2 = "val2"
}

func TestisEmptyBool(t *testing.T) {
tests := []struct {
input bool
result bool
}{{true, false}, {false, true}}
for _, test := range tests {
if isEmpty(reflect.ValueOf(test.input)) != test.result {
t.Error("expected %s got %s", test.result, test.input)
}
}
}

0 comments on commit e27e134

Please sign in to comment.