aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-08-17 10:45:22 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-08-17 10:45:22 -0400
commit5c323794b96d8c5582f4491be18fa34565757c15 (patch)
tree1bccee63d57c643734a232dd0b4f302d8fc036e2
parentAdjust docs to reference overview (diff)
downloadcheckmate-5c323794b96d8c5582f4491be18fa34565757c15.zip
Add usage example
-rw-r--r--README.md40
1 files changed, 40 insertions, 0 deletions
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: