Skip to content

Commit

Permalink
Added a checker for empty strings w/ corresponding test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kat-co committed Aug 12, 2014
1 parent 064425d commit bfe9b50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ func GreaterThan(param int, comparativeVal int, paramName string) Checker {
}
}

func StringNotEmpty(obtained, paramName string) Checker {
return func() (isNotEmpty bool, errMsg string) {
isNotEmpty = obtained != ""
errMsg = fmt.Sprintf("Parameter is an empty string: %s", paramName)
return
}
}

func validationFactory(numErrors int) *Validation {
return &Validation{make([]string, numErrors)}
}
12 changes: 12 additions & 0 deletions validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,15 @@ func TestGreaterThan(t *testing.T) {
t.FailNow()
}
}

func TestStringNotEmpty(t *testing.T) {

err := BeginValidation().Validate(
StringNotEmpty("", "tmpA"),
).Check()

if err == nil {
t.Errorf("Expected an error.")
t.FailNow()
}
}

0 comments on commit bfe9b50

Please sign in to comment.