Skip to content

Commit a5620a2

Browse files
committed
doc: fix doc errors.
Signed-off-by: Chen Su <ghosind@gmail.com>
1 parent 1009f66 commit a5620a2

File tree

7 files changed

+432
-368
lines changed

7 files changed

+432
-368
lines changed

builtin.go

Lines changed: 203 additions & 203 deletions
Large diffs are not rendered by default.

compare.go

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
// DeepEqual tests the deep equality between actual and expect parameters. It'll set the result to
1010
// fail if they are not deeply equal, and it doesn't stop the execution.
1111
//
12-
// assertion.DeepEqual(1, 1) // success
13-
// assertion.DeepEqual("ABC", "ABC") // success
14-
// assertion.DeepEqual(1, 0) // fail
15-
// assertion.DeepEqual(1, int64(1)) // fail
12+
// a := assert.New(t)
13+
// a.DeepEqual(1, 1) // success
14+
// a.DeepEqual("ABC", "ABC") // success
15+
// a.DeepEqual(1, 0) // fail
16+
// a.DeepEqual(1, int64(1)) // fail
1617
func (a *Assertion) DeepEqual(actual, expect any, message ...any) error {
1718
a.Helper()
1819

@@ -22,9 +23,10 @@ func (a *Assertion) DeepEqual(actual, expect any, message ...any) error {
2223
// DeepEqualNow tests the deep equality between actual and expect parameters, and it'll stop the
2324
// execution if they are not deeply equal.
2425
//
25-
// assertion.DeepEqualNow(1, 1) // success
26-
// assertion.DeepEqualNow("ABC", "ABC") // success
27-
// assertion.DeepEqualNow(1, int64(1)) // fail and terminate
26+
// a := assert.New(t)
27+
// a.DeepEqualNow(1, 1) // success
28+
// a.DeepEqualNow("ABC", "ABC") // success
29+
// a.DeepEqualNow(1, int64(1)) // fail and terminate
2830
// // never run
2931
func (a *Assertion) DeepEqualNow(actual, expect any, message ...any) error {
3032
a.Helper()
@@ -35,10 +37,11 @@ func (a *Assertion) DeepEqualNow(actual, expect any, message ...any) error {
3537
// NotDeepEqual tests the deep inequality between actual and expected parameters. It'll set the
3638
// result to fail if they are deeply equal, but it doesn't stop the execution.
3739
//
38-
// assertion.NotDeepEqual(1, 0) // success
39-
// assertion.NotDeepEqual(1, int64(1)) // success
40-
// assertion.NotDeepEqual(1, 1) // fail
41-
// assertion.NotDeepEqual("ABC", "ABC") // fail
40+
// a := assert.New(t)
41+
// a.NotDeepEqual(1, 0) // success
42+
// a.NotDeepEqual(1, int64(1)) // success
43+
// a.NotDeepEqual(1, 1) // fail
44+
// a.NotDeepEqual("ABC", "ABC") // fail
4245
func (a *Assertion) NotDeepEqual(actual, expect any, message ...any) error {
4346
a.Helper()
4447

@@ -48,9 +51,10 @@ func (a *Assertion) NotDeepEqual(actual, expect any, message ...any) error {
4851
// NotDeepEqualNow tests the deep inequality between actual and expected parameters, and it'll stop
4952
// the execution if they are deeply equal.
5053
//
51-
// assertion.NotDeepEqual1, 0) // success
52-
// assertion.NotDeepEqual1, int64(1)) // success
53-
// assertion.NotDeepEqual"ABC", "ABC") // fail and terminate
54+
// a := assert.New(t)
55+
// a.NotDeepEqual1, 0) // success
56+
// a.NotDeepEqual1, int64(1)) // success
57+
// a.NotDeepEqual"ABC", "ABC") // fail and terminate
5458
// // never run
5559
func (a *Assertion) NotDeepEqualNow(actual, expect any, message ...any) error {
5660
a.Helper()
@@ -89,11 +93,12 @@ func tryNotDeepEqual(t *testing.T, failedNow bool, actual, expect any, message .
8993
// Equal tests the equality between actual and expect parameters. It'll set the result to fail if
9094
// they are not equal, and it doesn't stop the execution.
9195
//
92-
// assertion.Equal(1, 1) // success
93-
// assertion.Equal("ABC", "ABC") // success
94-
// assertion.Equal(1, int64(1)) // success
95-
// assertion.Equal(1, uint64(1)) // fail
96-
// assertion.Equal(1, 0) // fail
96+
// a := assert.New(t)
97+
// a.Equal(1, 1) // success
98+
// a.Equal("ABC", "ABC") // success
99+
// a.Equal(1, int64(1)) // success
100+
// a.Equal(1, uint64(1)) // fail
101+
// a.Equal(1, 0) // fail
97102
func (a *Assertion) Equal(actual, expect any, message ...any) error {
98103
a.Helper()
99104

@@ -103,10 +108,11 @@ func (a *Assertion) Equal(actual, expect any, message ...any) error {
103108
// EqualNow tests the equality between actual and expect parameters, and it'll stop the execution
104109
// if they are not equal.
105110
//
106-
// assertion.EqualNow(1, 1) // success
107-
// assertion.EqualNow("ABC", "ABC") // success
108-
// assertion.EqualNow(1, int64(1)) // success
109-
// assertion.EqualNow(1, 0) // fail and terminate
111+
// a := assert.New(t)
112+
// a.EqualNow(1, 1) // success
113+
// a.EqualNow("ABC", "ABC") // success
114+
// a.EqualNow(1, int64(1)) // success
115+
// a.EqualNow(1, 0) // fail and terminate
110116
// never run
111117
func (a *Assertion) EqualNow(actual, expect any, message ...any) error {
112118
a.Helper()
@@ -117,12 +123,13 @@ func (a *Assertion) EqualNow(actual, expect any, message ...any) error {
117123
// NotEqual tests the inequality between actual and expected parameters. It'll set the result to
118124
// fail if they are equal, but it doesn't stop the execution.
119125
//
120-
// assertion.NotEqual(1, 0) // success
121-
// assertion.NotEqual("ABC", "CBA") // success
122-
// assertion.NotEqual(1, uint64(1)) // success
123-
// assertion.NotEqual(1, 1) // fail
124-
// assertion.NotEqual("ABC", "ABC") // fail
125-
// assertion.NotEqual(1, int64(1)) // fail
126+
// a := assert.New(t)
127+
// a.NotEqual(1, 0) // success
128+
// a.NotEqual("ABC", "CBA") // success
129+
// a.NotEqual(1, uint64(1)) // success
130+
// a.NotEqual(1, 1) // fail
131+
// a.NotEqual("ABC", "ABC") // fail
132+
// a.NotEqual(1, int64(1)) // fail
126133
func (a *Assertion) NotEqual(actual, expect any, message ...any) error {
127134
a.Helper()
128135

@@ -132,9 +139,10 @@ func (a *Assertion) NotEqual(actual, expect any, message ...any) error {
132139
// NotEqualNow tests the inequality between actual and expected parameters, and it'll stop the
133140
// execution if they are equal.
134141
//
135-
// assertion.NotEqualNow(1, 0) // success
136-
// assertion.NotEqualNow("ABC", "CBA") // success
137-
// assertion.NotEqualNow(1, 1) // fail and terminate
142+
// a := assert.New(t)
143+
// a.NotEqualNow(1, 0) // success
144+
// a.NotEqualNow("ABC", "CBA") // success
145+
// a.NotEqualNow(1, 1) // fail and terminate
138146
// // never run
139147
func (a *Assertion) NotEqualNow(actual, expect any, message ...any) error {
140148
a.Helper()
@@ -174,11 +182,12 @@ func tryNotEqual(t *testing.T, failedNow bool, actual, expect any, message ...an
174182
// always return false if the value is a bool, an integer, a floating number, a complex, or a
175183
// string.
176184
//
185+
// a := assert.New(t)
177186
// var err error // nil
178-
// assertion.Nil(err) // success
187+
// a.Nil(err) // success
179188
//
180189
// err = errors.New("some error")
181-
// assertion.Nil(err) // fail
190+
// a.Nil(err) // fail
182191
func (a *Assertion) Nil(val any, message ...any) error {
183192
a.Helper()
184193

@@ -191,11 +200,12 @@ func (a *Assertion) Nil(val any, message ...any) error {
191200
//
192201
// This function will set the result to fail, and stop the execution if the value is not nil.
193202
//
203+
// a := assert.New(t)
194204
// var err error // nil
195-
// assertion.NilNow(err) // success
205+
// a.NilNow(err) // success
196206
//
197207
// err = errors.New("some error")
198-
// assertion.NilNow(err) // fail and terminate
208+
// a.NilNow(err) // fail and terminate
199209
// // never run
200210
func (a *Assertion) NilNow(val any, message ...any) error {
201211
a.Helper()
@@ -207,11 +217,12 @@ func (a *Assertion) NilNow(val any, message ...any) error {
207217
// always return true if the value is a bool, an integer, a floating number, a complex, or a
208218
// string.
209219
//
220+
// a := assert.New(t)
210221
// var err error // nil
211-
// assertion.NotNil(err) // fail
222+
// a.NotNil(err) // fail
212223
//
213224
// err = errors.New("some error")
214-
// assertion.NotNil(err) // success
225+
// a.NotNil(err) // success
215226
func (a *Assertion) NotNil(val any, message ...any) error {
216227
a.Helper()
217228

@@ -224,11 +235,12 @@ func (a *Assertion) NotNil(val any, message ...any) error {
224235
//
225236
// This function will set the result to fail, and stop the execution if the value is nil.
226237
//
238+
// a := assert.New(t)
227239
// var err error = errors.New("some error")
228-
// assertion.NotNilNow(err) // success
240+
// a.NotNilNow(err) // success
229241
//
230242
// err = nil
231-
// assertion.NotNilNow(err) // fail and terminate
243+
// a.NotNilNow(err) // fail and terminate
232244
// // never run
233245
func (a *Assertion) NotNilNow(val any, message ...any) error {
234246
a.Helper()
@@ -267,10 +279,11 @@ func tryNotNil(t *testing.T, failedNow bool, val any, message ...any) error {
267279
// slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the
268280
// value is always falsy.
269281
//
270-
// assertion.True(1) // success
271-
// assertion.True("test") // success
272-
// assertion.True(0) // fail
273-
// assertion.True("") // fail
282+
// a := assert.New(t)
283+
// a.True(1) // success
284+
// a.True("test") // success
285+
// a.True(0) // fail
286+
// a.True("") // fail
274287
func (a *Assertion) True(val any, message ...any) error {
275288
a.Helper()
276289

@@ -284,9 +297,10 @@ func (a *Assertion) True(val any, message ...any) error {
284297
//
285298
// The function will stop the execution if the value is falsy.
286299
//
287-
// assertion.TrueNow(1) // success
288-
// assertion.TrueNow("test") // success
289-
// assertion.TrueNow("") // fail and terminate
300+
// a := assert.New(t)
301+
// a.TrueNow(1) // success
302+
// a.TrueNow("test") // success
303+
// a.TrueNow("") // fail and terminate
290304
// // never run
291305
func (a *Assertion) TrueNow(val any, message ...any) error {
292306
a.Helper()
@@ -299,10 +313,11 @@ func (a *Assertion) TrueNow(val any, message ...any) error {
299313
// slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the
300314
// value is always falsy.
301315
//
302-
// assertion.NotTrue(0) // success
303-
// assertion.NotTrue("") // success
304-
// assertion.NotTrue(1) // fail
305-
// assertion.NotTrue("test") // fail
316+
// a := assert.New(t)
317+
// a.NotTrue(0) // success
318+
// a.NotTrue("") // success
319+
// a.NotTrue(1) // fail
320+
// a.NotTrue("test") // fail
306321
func (a *Assertion) NotTrue(val any, message ...any) error {
307322
a.Helper()
308323

@@ -316,9 +331,10 @@ func (a *Assertion) NotTrue(val any, message ...any) error {
316331
//
317332
// The function will stop the execution if the value is truthy.
318333
//
319-
// assertion.NotTrueNow(0) // success
320-
// assertion.NotTrueNow("") // success
321-
// assertion.NotTrueNow("test") // fail and terminate
334+
// a := assert.New(t)
335+
// a.NotTrueNow(0) // success
336+
// a.NotTrueNow("") // success
337+
// a.NotTrueNow("test") // fail and terminate
322338
// // never run
323339
func (a *Assertion) NotTrueNow(val any, message ...any) error {
324340
a.Helper()

map.go

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
// MapHasKey tests whether the map contains the specified key or not, it will fail if the map does
1010
// not contain the key, or the type of the key cannot assign to the type of the key of the map.
1111
//
12-
// assertion.MapHasKey(map[string]int{"a":1}, "a") // success
13-
// assertion.MapHasKey(map[string]int{"a":1}, "b") // fail
14-
// assertion.MapHasKey(map[string]int{"a":1}, 1) // fail
12+
// a := assert.New(t)
13+
// a.MapHasKey(map[string]int{"a":1}, "a") // success
14+
// a.MapHasKey(map[string]int{"a":1}, "b") // fail
15+
// a.MapHasKey(map[string]int{"a":1}, 1) // fail
1516
func (a *Assertion) MapHasKey(m, key any, message ...any) error {
1617
a.Helper()
1718

@@ -22,8 +23,9 @@ func (a *Assertion) MapHasKey(m, key any, message ...any) error {
2223
// execution if the test fails. It will fail if the map does not contain the key, or the type of
2324
// the key cannot assign to the type of the key of the map.
2425
//
25-
// assertion.MapHasKeyNow(map[string]int{"a":1}, "a") // success
26-
// assertion.MapHasKeyNow(map[string]int{"a":1}, "b") // fail and terminate
26+
// a := assert.New(t)
27+
// a.MapHasKeyNow(map[string]int{"a":1}, "a") // success
28+
// a.MapHasKeyNow(map[string]int{"a":1}, "b") // fail and terminate
2729
// // never run
2830
func (a *Assertion) MapHasKeyNow(m, key any, message ...any) error {
2931
a.Helper()
@@ -35,9 +37,10 @@ func (a *Assertion) MapHasKeyNow(m, key any, message ...any) error {
3537
// contain the key. It will also set the test result to success if the type of the key cannot
3638
// assign to the type of the key of the map.
3739
//
38-
// assertion.NotMapHasKey(map[string]int{"a":1}, "b") // success
39-
// assertion.NotMapHasKey(map[string]int{"a":1}, 1) // success
40-
// assertion.NotMapHasKey(map[string]int{"a":1}, "a") // fail
40+
// a := assert.New(t)
41+
// a.NotMapHasKey(map[string]int{"a":1}, "b") // success
42+
// a.NotMapHasKey(map[string]int{"a":1}, 1) // success
43+
// a.NotMapHasKey(map[string]int{"a":1}, "a") // fail
4144
func (a *Assertion) NotMapHasKey(m, key any, message ...any) error {
4245
a.Helper()
4346

@@ -48,9 +51,10 @@ func (a *Assertion) NotMapHasKey(m, key any, message ...any) error {
4851
// contain the key, and it will terminate the execution if the test fails. It will also set the
4952
// test result to success if the type of the key cannot assign to the type of the key of the map.
5053
//
51-
// assertion.NotMapHasKeyNow(map[string]int{"a":1}, "b") // success
52-
// assertion.NotMapHasKeyNow(map[string]int{"a":1}, 1) // success
53-
// assertion.NotMapHasKeyNow(map[string]int{"a":1}, "a") // fail and terminate
54+
// a := assert.New(t)
55+
// a.NotMapHasKeyNow(map[string]int{"a":1}, "b") // success
56+
// a.NotMapHasKeyNow(map[string]int{"a":1}, 1) // success
57+
// a.NotMapHasKeyNow(map[string]int{"a":1}, "a") // fail and terminate
5458
// // never run
5559
func (a *Assertion) NotMapHasKeyNow(m, key any, message ...any) error {
5660
a.Helper()
@@ -100,9 +104,10 @@ func tryNotMapHasKey(
100104
// does not contain the value, or the type of the value cannot assign to the type of the values of
101105
// the map.
102106
//
103-
// assertion.MapHasValue(map[string]int{"a":1}, 1) // success
104-
// assertion.MapHasValue(map[string]int{"a":1}, 2) // fail
105-
// assertion.MapHasValue(map[string]int{"a":1}, "a") // fail
107+
// a := assert.New(t)
108+
// a.MapHasValue(map[string]int{"a":1}, 1) // success
109+
// a.MapHasValue(map[string]int{"a":1}, 2) // fail
110+
// a.MapHasValue(map[string]int{"a":1}, "a") // fail
106111
func (a *Assertion) MapHasValue(m, value any, message ...any) error {
107112
a.Helper()
108113

@@ -113,8 +118,9 @@ func (a *Assertion) MapHasValue(m, value any, message ...any) error {
113118
// the execution if the test fails. It will fail if the map does not contain the value, or the type
114119
// of the value cannot assign to the type of the value of the map.
115120
//
116-
// assertion.MapHasValueNow(map[string]int{"a":1}, 1) // success
117-
// assertion.MapHasValueNow(map[string]int{"a":1}, 2) // fail and terminate
121+
// a := assert.New(t)
122+
// a.MapHasValueNow(map[string]int{"a":1}, 1) // success
123+
// a.MapHasValueNow(map[string]int{"a":1}, 2) // fail and terminate
118124
// // never run
119125
func (a *Assertion) MapHasValueNow(m, value any, message ...any) error {
120126
a.Helper()
@@ -126,9 +132,10 @@ func (a *Assertion) MapHasValueNow(m, value any, message ...any) error {
126132
// map contain the value. It will also set the test result to success if the type of the value
127133
// cannot assign to the type of the value of the map.
128134
//
129-
// assertion.NotMapHasValue(map[string]int{"a":1}, 2) // success
130-
// assertion.NotMapHasValue(map[string]int{"a":1}, "a") // success
131-
// assertion.NotMapHasValue(map[string]int{"a":1}, 1) // fail
135+
// a := assert.New(t)
136+
// a.NotMapHasValue(map[string]int{"a":1}, 2) // success
137+
// a.NotMapHasValue(map[string]int{"a":1}, "a") // success
138+
// a.NotMapHasValue(map[string]int{"a":1}, 1) // fail
132139
func (a *Assertion) NotMapHasValue(m, value any, message ...any) error {
133140
a.Helper()
134141

@@ -140,9 +147,10 @@ func (a *Assertion) NotMapHasValue(m, value any, message ...any) error {
140147
// the test result to success if the type of the value cannot assign to the type of the value of
141148
// the map.
142149
//
143-
// assertion.NotMapHasValueNow(map[string]int{"a":1}, 2) // success
144-
// assertion.NotMapHasValueNow(map[string]int{"a":1}, "a") // success
145-
// assertion.NotMapHasValueNow(map[string]int{"a":1}, 1) // fail and terminate
150+
// a := assert.New(t)
151+
// a.NotMapHasValueNow(map[string]int{"a":1}, 2) // success
152+
// a.NotMapHasValueNow(map[string]int{"a":1}, "a") // success
153+
// a.NotMapHasValueNow(map[string]int{"a":1}, 1) // fail and terminate
146154
// // never run
147155
func (a *Assertion) NotMapHasValueNow(m, value any, message ...any) error {
148156
a.Helper()

0 commit comments

Comments
 (0)