|
1 | 1 | # goassert
|
| 2 | + |
| 3 | +`goassert` is a simple assertion library for go/golang. |
| 4 | +It does not try to do anything fancy and keeps things as simple as possible. |
| 5 | +Its primary goal is to make assertions as short and simple as possible. |
| 6 | +It also takes advantage of go generics as much as possible to be able to handle as many types as possible |
| 7 | +with as fewest assertion methods as possible |
| 8 | + |
| 9 | +## Installation |
| 10 | +```bash |
| 11 | +go get -t -u github.com/golanglibs/goassert@latest |
| 12 | +``` |
| 13 | + |
| 14 | +## Usage |
| 15 | +```go |
| 16 | +package yourpackage |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing", |
| 20 | + |
| 21 | + "github.com/golanglibs/goassert" |
| 22 | +) |
| 23 | + |
| 24 | +func Test_1Plus1ShouldEqual2(t *testing.T) { |
| 25 | + actual := 1 + 1 |
| 26 | + expected := 2 |
| 27 | + |
| 28 | + goassert.Equal(t, expected, actual) |
| 29 | + // on assertion error |
| 30 | + // --- FAIL: Test_1Plus1ShouldEqual2 (0.00s) |
| 31 | + // module_test.go: 11: Expected 2. Actual: 1 |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +## Available Assertions |
| 36 | + |
| 37 | +### Truth |
| 38 | +* `True` - asserts the value is true |
| 39 | +* `False` - asserts the value is false |
| 40 | + |
| 41 | +### Equality |
| 42 | +* `Equal` - asserts two values are equal. Values must be comparable |
| 43 | +* `NotEqual` - asserts two values are not equal. Values must be comparable |
| 44 | +* `Nil` - asserts the value is nil |
| 45 | +* `NotNil` - asserts the value is not nil |
| 46 | +* `EqualSlice` - asserts two slices have the same values in the same order. The elements must be comparable |
| 47 | +* `NotEqualSlice` - asserts two slices do not have the same values in the same order. The elements must be comparable |
| 48 | +* `SimilarSlice` - asserts two slices have the same values in either different or same order. The elements must be comparable |
| 49 | +* `NotSimilarSlice` - asserts two slices do not have the same values. The elements must be comparable |
| 50 | +* `EqualMap` - asserts two maps have same key-value pairs. The values must be comparable |
| 51 | +* `NotEqualMap` - asserts two maps do not have same key-value pairs. The values must be comparable |
| 52 | + |
| 53 | +### Collection |
| 54 | +* `EmptySlice` - asserts the slice is empty. The assertion will fail if the slice is nil |
| 55 | +* `NotEmptySlice` - asserts the slice is not nil or empty |
| 56 | +* `SliceLength` - asserts the slice has the specified length |
| 57 | +* `SliceContains` - asserts the slice contains the specified value. The value must be comparable |
| 58 | +* `SliceNotContains` - asserts the slice does not contain the specified value. The value must be comparable |
| 59 | +* `EmptyMap` - asserts the map is empty. The assertion will fail if the map is nil |
| 60 | +* `NotEmptyMap` - asserts the map is not nil or empty |
| 61 | +* `MapLength` - asserts the map has the specified length |
| 62 | +* `MapContains` - asserts the map contains the specified key-value pair |
| 63 | +* `MapNotContains` - asserts the map does not contain the specified key-value pair |
| 64 | + |
| 65 | +### Panic |
| 66 | +* `Panic` - asserts given function panics |
| 67 | +* `NotPanic` - asserts given function does not panic |
| 68 | +* `PanicWithError` - asserts given function panics with the specified error |
| 69 | +* `NotPanicWithError` - asserts given functoin does not panic with the specified error |
0 commit comments