add IsZero()

Go 1.4 will have JSON ,omitempty respect this, maybe.
This commit is contained in:
Greg 2014-08-29 00:37:35 +09:00
parent cf649e8f2a
commit 95bde34e57
2 changed files with 17 additions and 0 deletions

View file

@ -45,3 +45,8 @@ func (s String) Pointer() *string {
}
return &s.String
}
// IsZero returns true for invalid strings, for future omitempty support (Go 1.4?)
func (s String) IsZero() bool {
return !s.Valid
}

View file

@ -63,6 +63,18 @@ func TestPointer(t *testing.T) {
}
}
func TestIsZero(t *testing.T) {
str := StringFrom("test")
if str.IsZero() {
t.Errorf("IsZero() should be false")
}
null := StringFrom("")
if !null.IsZero() {
t.Errorf("IsZero() should be true")
}
}
func TestScan(t *testing.T) {
var str String
err := str.Scan("test")