|
8 | 8 |
|
9 | 9 | A collection of Golang assertion functions for verifying invariants.
|
10 | 10 |
|
| 11 | +- [Installation](#installation) |
| 12 | +- [Getting Started](#getting-started) |
| 13 | +- [Available Assertions](#available-assertions) |
| 14 | + - [Equality](#equality) |
| 15 | + - [Value](#value) |
| 16 | + - [String](#string) |
| 17 | + - [Slice or Array](#slice-or-array) |
| 18 | + - [Error Handling](#error-handling) |
| 19 | +- [License](#license) |
| 20 | + |
11 | 21 | ## Installation
|
12 | 22 |
|
13 | 23 | To install this library, just use `go get` command like the following line:
|
@@ -68,6 +78,16 @@ func TestExample(t *testing.T) {
|
68 | 78 | }
|
69 | 79 | ```
|
70 | 80 |
|
| 81 | +Since v0.2.0, we also provided some assertions for array/slice, for example, you can use `ContainsElement` to check whether an array or a slice contains a specified element. |
| 82 | + |
| 83 | +```go |
| 84 | +func TestExample(t *testing.T) { |
| 85 | + arr := []int{1, 2, 3} |
| 86 | + assert.ContainsElement(arr, 1) // success |
| 87 | + assert.ContainsElement(arr, 4) // fail |
| 88 | +} |
| 89 | +``` |
| 90 | + |
71 | 91 | It also provided assertion functions to verify a function will panic or not:
|
72 | 92 |
|
73 | 93 | ```go
|
@@ -133,29 +153,56 @@ func TestExample(t *testing.T) {
|
133 | 153 | ### Equality
|
134 | 154 |
|
135 | 155 | - [`DeepEqual`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.DeepEqual) and [`NotDeepEqual`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotDeepEqual): assert the deep equality or inequality.
|
| 156 | + |
| 157 | + > Since v0.1.0 |
| 158 | +
|
136 | 159 | - [`Equal`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.Equal) and [`NotEqual`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotEqual): assert the equality or inequality.
|
137 | 160 |
|
| 161 | + > Since v0.1.5 |
| 162 | +
|
138 | 163 | ### Value
|
139 | 164 |
|
140 | 165 | - [`Nil`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.Nil) and [`NotNil`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotNil): assert the value is nil or not.
|
| 166 | + |
| 167 | + > Since v0.1.1 |
| 168 | +
|
141 | 169 | - [`True`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.True) and [`NotTrue`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotTrue): assert the truthy of the value.
|
142 | 170 |
|
| 171 | + > Since v0.1.4 |
| 172 | +
|
143 | 173 | ### String
|
144 | 174 |
|
145 | 175 | - [`ContainsString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.ContainsString) and [`NotContainsString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotContainsString): assert whether the string contains the substring or not.
|
| 176 | + |
| 177 | + > Since v0.1.7 |
| 178 | +
|
146 | 179 | - [`HasPrefixString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.HasPrefixString) and [`NotHasPrefixString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotHasPrefixString): assert whether the string have the prefix string or not.
|
| 180 | + |
| 181 | + > Since v0.1.7 |
| 182 | +
|
147 | 183 | - [`HasSuffixString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.HasSuffixString) and [`NotHasSuffixString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotHasSuffixString): assert whether the string have the suffix string or not.
|
| 184 | + |
| 185 | + > Since v0.1.7 |
| 186 | +
|
148 | 187 | - [`Match`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.Match) and [`NotMatch`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotMatch): assert whether the string matches the regular expression pattern or not.
|
| 188 | + |
| 189 | + > Since v0.1.5 |
| 190 | +
|
149 | 191 | - [`MatchString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.MatchString) and [`NotMatchString`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotMatchString): compile the regular expression pattern and assert whether the string matches the pattern or not.
|
150 | 192 |
|
| 193 | + > Since v0.1.5 |
| 194 | +
|
151 | 195 | ### Slice or Array
|
152 | 196 |
|
153 | 197 | - [`ContainsElement`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.ContainsElement) and [`NotContainsElement`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotContainsElement): assert whether the array or slice contains the specified element or not.
|
154 | 198 |
|
| 199 | + > Since v0.2.0 |
| 200 | +
|
155 | 201 | ### Error Handling
|
156 | 202 |
|
157 | 203 | - [`Panic`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.Panic) and [`NotPanic`](https://pkg.go.dev/github.com/ghosind/go-assert#Assertion.NotPanic): assert the function will panic or not.
|
158 | 204 |
|
| 205 | + > Since v0.1.0 |
159 | 206 |
|
160 | 207 | ## License
|
161 | 208 |
|
|
0 commit comments