aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-01-28 16:41:51 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-01-28 16:41:51 -0500
commit924258bdf03329e0a47e93f03619db49358e653b (patch)
tree1fb62225a1da50313a6a8ea0be7af6ad74501657
parentUpdate badge and changelog (diff)
downloadcheckmate-924258bdf03329e0a47e93f03619db49358e653b.zip
Add usage to readme
-rw-r--r--README.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/README.md b/README.md
index f409c02..8757a6e 100644
--- a/README.md
+++ b/README.md
@@ -24,3 +24,44 @@ To install Checkmate, use the following command:
```bash
$ go get github.com/eugenetriguba/checkmate
```
+
+## Usage
+
+To get a feel for what Checkmate has to offer, here is a simple example with some commentary that shows all the supported assertion functions. For a reference on each function, see the [GoDoc](https://godoc.org/github.com/eugenetriguba/checkmate).
+
+```go
+
+import (
+ "errors"
+ "os"
+ "testing"
+
+ "github.com/eugenetriguba/checkmate/assert"
+)
+
+func TestAssertions(t *testing.T) {
+ // Assert is the base general assertion function. It
+ // takes in any boolean expression and will fail the
+ // test if the expression is false.
+ assert.Assert(t, true)
+
+ // Also note, all functions in this library take in an
+ // optional message argument which may have placeholders
+ // that are formatted with the reaming arguments.
+ assert.Assert(t, false, "expected %v to be true", false)
+
+ // Check is like Assert, but it will not fail the test.
+ assert.Check(t, true)
+
+ assert.True(t, true)
+ assert.False(t, false)
+ assert.Equal(t, 1, 1)
+ assert.DeepEqual(t, []int{1, 2, 3}, []int{1, 2, 3})
+ assert.LenEqual(t, []int{1, 2, 3}, 3)
+ assert.NotEqual(t, 1, 2)
+ assert.Nil(t, nil)
+ assert.NotNil(t, "not nil")
+ assert.ErrorIs(t, os.ErrInvalid, os.ErrInvalid)
+ assert.ErrorContains(t, errors.New("error 1"), "error 1")
+}
+``` \ No newline at end of file