Skip to content

Commit

Permalink
Merge pull request #7 from axiomzen/chris/move-method-to-here
Browse files Browse the repository at this point in the history
Move method to this package
  • Loading branch information
Chris S authored Mar 12, 2018
2 parents 76255e2 + fd1f26b commit caf7c03
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func NewString(s string, valid bool) String {
}
}

// IsEmptyString useful for when the value
// needs to be check for zero
func IsEmptyString(n String) bool {
return !n.Valid || n.String == ""
}

// UnmarshalJSON implements json.Unmarshaler.
// It supports string and null input. Blank string input does not produce a null String.
// It also supports unmarshalling a sql.NullString.
Expand Down
22 changes: 22 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,25 @@ func assertJSONEquals(t *testing.T, data []byte, cmp string, from string) {
t.Errorf("bad %s data: %s ≠ %s\n", from, data, cmp)
}
}

func TestIsEmpty(t *testing.T) {
s := NewString("", true)
if IsEmptyString(s) != true {
t.Errorf("Expected %t to be true", IsEmptyString(s))
}

s2 := NewString("dfd", false)
if IsEmptyString(s2) != true {
t.Errorf("Expected %t to be true", IsEmptyString(s))
}

s3 := NewString("", false)
if IsEmptyString(s3) != true {
t.Errorf("Expected %t to be true", IsEmptyString(s))
}

s4 := NewString("dsfds", true)
if IsEmptyString(s4) == true {
t.Errorf("Expected %t to be false", IsEmptyString(s))
}
}

0 comments on commit caf7c03

Please sign in to comment.