diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-17 10:45:22 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-17 10:45:22 -0400 |
| commit | 5c323794b96d8c5582f4491be18fa34565757c15 (patch) | |
| tree | 1bccee63d57c643734a232dd0b4f302d8fc036e2 | |
| parent | Adjust docs to reference overview (diff) | |
| download | checkmate-5c323794b96d8c5582f4491be18fa34565757c15.zip | |
Add usage example
| -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: |