From 5c323794b96d8c5582f4491be18fa34565757c15 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 17 Aug 2025 10:45:22 -0400 Subject: Add usage example --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 10fd5bf..2af23c7 100644 --- a/README.md +++ b/README.md @@ -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: -- cgit v1.2.3