Skip to content

Commit 5ebcdcd

Browse files
authored
[feature] add annotations for all assertion methods to allow users to see method documentations on hover (#7)
1 parent be9dbdc commit 5ebcdcd

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Test_1Plus1ShouldEqual2(t *testing.T) {
4545
* `NotNil` - asserts the value is not nil
4646
* `EqualSlice` - asserts two slices have the same values in the same order. The elements must be comparable
4747
* `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
48+
* `SimilarSlice` - asserts two slices have the same values in any order. The elements must be comparable
4949
* `NotSimilarSlice` - asserts two slices do not have the same values. The elements must be comparable
5050
* `EqualMap` - asserts two maps have same key-value pairs. The values must be comparable
5151
* `NotEqualMap` - asserts two maps do not have same key-value pairs. The values must be comparable

assert_collections.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package goassert
22

33
import "testing"
44

5+
/*
6+
Asserts that the given slice is empty. The assertion fails if the given slice is nil
7+
*/
58
func EmptySlice[T any](t testing.TB, s []T) {
69
t.Helper()
710

@@ -16,6 +19,9 @@ func EmptySlice[T any](t testing.TB, s []T) {
1619
}
1720
}
1821

22+
/*
23+
Asserts that the given slice is not nil or empty
24+
*/
1925
func NotEmptySlice[T any](t testing.TB, s []T) {
2026
t.Helper()
2127

@@ -29,6 +35,9 @@ func NotEmptySlice[T any](t testing.TB, s []T) {
2935
}
3036
}
3137

38+
/*
39+
Asserts that the given slice has length equal to the specified expected length
40+
*/
3241
func SliceLength[T any](t testing.TB, s []T, expectedLength int) {
3342
t.Helper()
3443

@@ -38,6 +47,9 @@ func SliceLength[T any](t testing.TB, s []T, expectedLength int) {
3847
}
3948
}
4049

50+
/*
51+
Asserts that the given slice contains the given element. The element must be [comparable]
52+
*/
4153
func SliceContains[K comparable](t testing.TB, s []K, element K) {
4254
t.Helper()
4355

@@ -46,6 +58,9 @@ func SliceContains[K comparable](t testing.TB, s []K, element K) {
4658
}
4759
}
4860

61+
/*
62+
Asserts that the given slice does not contain the given element. The element must be [comparable]
63+
*/
4964
func SliceNotContains[K comparable](t testing.TB, s []K, element K) {
5065
t.Helper()
5166

@@ -64,6 +79,9 @@ func sliceContains[K comparable](s []K, element K) bool {
6479
return false
6580
}
6681

82+
/*
83+
Asserts that the given map is empty. The assertion will fail if the given map is nil
84+
*/
6785
func EmptyMap[K comparable, V any](t testing.TB, m map[K]V) {
6886
t.Helper()
6987

@@ -78,6 +96,9 @@ func EmptyMap[K comparable, V any](t testing.TB, m map[K]V) {
7896
}
7997
}
8098

99+
/*
100+
Asserts that the given map is not nil or empty
101+
*/
81102
func NotEmptyMap[K comparable, V any](t testing.TB, m map[K]V) {
82103
t.Helper()
83104

@@ -91,6 +112,9 @@ func NotEmptyMap[K comparable, V any](t testing.TB, m map[K]V) {
91112
}
92113
}
93114

115+
/*
116+
Asserts that the given map has length equal to the specified length
117+
*/
94118
func MapLength[K comparable, V any](t testing.TB, m map[K]V, expectedLength int) {
95119
t.Helper()
96120

@@ -100,6 +124,9 @@ func MapLength[K comparable, V any](t testing.TB, m map[K]V, expectedLength int)
100124
}
101125
}
102126

127+
/*
128+
Asserts that the given map contains the given key-value pair. The key and value must be [comparable]
129+
*/
103130
func MapContains[K, V comparable](t testing.TB, m map[K]V, k K, v V) {
104131
t.Helper()
105132

@@ -115,6 +142,9 @@ func MapContains[K, V comparable](t testing.TB, m map[K]V, k K, v V) {
115142
}
116143
}
117144

145+
/*
146+
Asserts that the given map does not contain the given key-value pair. The key and value must be [comparable]
147+
*/
118148
func MapNotContains[K, V comparable](t testing.TB, m map[K]V, k K, v V) {
119149
t.Helper()
120150

assert_equality.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"testing"
66
)
77

8+
/*
9+
Asserts that the two given values are equal. The given values must be [comparable]
10+
*/
811
func Equal[K comparable](t testing.TB, expected K, actual K) {
912
t.Helper()
1013

@@ -13,6 +16,9 @@ func Equal[K comparable](t testing.TB, expected K, actual K) {
1316
}
1417
}
1518

19+
/*
20+
Asserts that the two given values are not equal. The given values must be [comparable]
21+
*/
1622
func NotEqual[K comparable](t testing.TB, expected K, actual K) {
1723
t.Helper()
1824

@@ -21,6 +27,9 @@ func NotEqual[K comparable](t testing.TB, expected K, actual K) {
2127
}
2228
}
2329

30+
/*
31+
Asserts that the given value is nil
32+
*/
2433
func Nil(t testing.TB, actual interface{}) {
2534
t.Helper()
2635

@@ -29,6 +38,9 @@ func Nil(t testing.TB, actual interface{}) {
2938
}
3039
}
3140

41+
/*
42+
Asserts that the given value is not nil
43+
*/
3244
func NotNil(t testing.TB, actual interface{}) {
3345
t.Helper()
3446

@@ -50,6 +62,9 @@ func isNil(value interface{}) bool {
5062
return false
5163
}
5264

65+
/*
66+
Asserts that the two given slices have the same elements in the same order. The elements must be [comparable]
67+
*/
5368
func EqualSlice[K comparable](t testing.TB, expected []K, actual []K) {
5469
t.Helper()
5570

@@ -58,6 +73,9 @@ func EqualSlice[K comparable](t testing.TB, expected []K, actual []K) {
5873
}
5974
}
6075

76+
/*
77+
Asserts that the two given slices does not have the same elements in the same order. The elements must be [comparable]
78+
*/
6179
func NotEqualSlice[K comparable](t testing.TB, expected []K, actual []K) {
6280
t.Helper()
6381

@@ -82,6 +100,9 @@ func areEqualSlices[K comparable](expected []K, actual []K) bool {
82100
return true
83101
}
84102

103+
/*
104+
Asserts that the two given slices have the same values in any order. The elements must be [comparable]
105+
*/
85106
func SimilarSlice[K comparable](t testing.TB, expected []K, actual []K) {
86107
t.Helper()
87108

@@ -90,6 +111,9 @@ func SimilarSlice[K comparable](t testing.TB, expected []K, actual []K) {
90111
}
91112
}
92113

114+
/*
115+
Asserts that the two given slices does not have the same values. The elements must be [comparable]
116+
*/
93117
func NotSimilarSlice[K comparable](t testing.TB, expected []K, actual []K) {
94118
t.Helper()
95119

@@ -118,6 +142,9 @@ func areSimilarSlices[K comparable](expected []K, actual []K) bool {
118142
return isEqualMap(expectedElementsMap, actualElementsMap)
119143
}
120144

145+
/*
146+
Asserts that the two given maps have the same key-value pairs. The values must be [comparable]
147+
*/
121148
func EqualMap[K, V comparable](t testing.TB, expected map[K]V, actual map[K]V) {
122149
t.Helper()
123150

@@ -126,6 +153,9 @@ func EqualMap[K, V comparable](t testing.TB, expected map[K]V, actual map[K]V) {
126153
}
127154
}
128155

156+
/*
157+
Asserts that the two given maps does not have the same key-value pairs. The values must be [comparable]
158+
*/
129159
func NotEqualMap[K, V comparable](t testing.TB, expected map[K]V, actual map[K]V) {
130160
t.Helper()
131161

assert_panic.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"testing"
55
)
66

7+
/*
8+
Asserts that the given function panics
9+
*/
710
func Panic(t testing.TB, underTest func()) {
811
t.Helper()
912

@@ -16,6 +19,9 @@ func Panic(t testing.TB, underTest func()) {
1619
underTest()
1720
}
1821

22+
/*
23+
Asserts that the given function does not panic
24+
*/
1925
func NotPanic(t testing.TB, underTest func()) {
2026
t.Helper()
2127

@@ -28,6 +34,10 @@ func NotPanic(t testing.TB, underTest func()) {
2834
underTest()
2935
}
3036

37+
/*
38+
Asserts that the given function panics with the specified error.
39+
The actual error must be of the same type and value as the given error
40+
*/
3141
func PanicWithError[K comparable](t testing.TB, expectedError K, underTest func()) {
3242
t.Helper()
3343

@@ -53,6 +63,10 @@ func PanicWithError[K comparable](t testing.TB, expectedError K, underTest func(
5363
underTest()
5464
}
5565

66+
/*
67+
Asserts that the given function does not panic with the specified error.
68+
The assertion succeeds if the given function does not panic or panics with a different error
69+
*/
5670
func NotPanicWithError[K comparable](t testing.TB, expectedError K, underTest func()) {
5771
t.Helper()
5872

assert_true.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package goassert
22

33
import "testing"
44

5+
/*
6+
Asserts that the given value is true
7+
*/
58
func True(t testing.TB, assertion bool) {
69
t.Helper()
710

@@ -10,6 +13,9 @@ func True(t testing.TB, assertion bool) {
1013
}
1114
}
1215

16+
/*
17+
Asserts that the given value is false
18+
*/
1319
func False(t testing.TB, assertion bool) {
1420
t.Helper()
1521

0 commit comments

Comments
 (0)