diff options
| -rw-r--r-- | README.md | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -20,6 +20,46 @@ To install Checkmate, use the following command: $ go get git.sr.ht/~eugenetriguba/checkmate ``` +## Example Usage + +```go +package main + +import ( + "errors" + "testing" + + "git.sr.ht/~eugenetriguba/checkmate/assert" + "git.sr.ht/~eugenetriguba/checkmate/check" +) + +func TestUserCreation(t *testing.T) { + user := &User{Name: "Alice", Age: 25} + + // assert functions fail the test and stop execution + // on failure + assert.NotNil(t, user) + assert.Equal(t, user.Name, "Alice") + assert.True(t, user.Age > 0) + + // check functions fail the test but continue execution + // of the test. + // + // They're useful for situation where you don't want to + // stop on the first assertion failure, so you get more + // output on test failure. + check.Equal(t, user.Age, 25) + check.DeepEqual(t, user, &User{Name: "Alice", Age: 25}) +} + +func TestValidateEmail_InvalidFormat(t *testing.T) { + err := validateEmail("invalid-email") + + assert.ErrorContains(t, err, "invalid email format") + assert.ErrorIs(t, err, ErrInvalidFormat) +} +``` + ## Reference For documentation on the API, see: |