@@ -31,6 +31,9 @@ func TestExample(t *testing.T) {
3131 // assert inequality
3232 assert.NotEqual (t, actual, expect)
3333
34+ // you can also use DeepEqual to assert the equality that also checks the type between the values
35+ assert.DeepEqual (t, actual, expect)
36+
3437 // var object
3538
3639 // assert for nil
@@ -41,6 +44,30 @@ func TestExample(t *testing.T) {
4144}
4245```
4346
47+ You can use ` True ` method to check whether a value is truthy or falsy (is the zero value of the type or not).
48+
49+ ``` go
50+ func TestExample (t *testing .T ) {
51+ assert.True (t, 1 ) // success
52+ assert.True (t, 0 ) // fail
53+ assert.True (t, " test" ) // success
54+ assert.True (t, " " ) // fail
55+ }
56+ ```
57+
58+ If you want to test the value of a string, you can use ` Match ` method to test it with a regular expression pattern.
59+
60+ ``` go
61+ func TestExample (t *testing .T ) {
62+ pattern := regexp.MustCompile (` ^https?:\/\/` )
63+ assert.Match (t, " https://example.com" , pattern) // success
64+ assert.Match (t, " example.com" , pattern) // fail
65+
66+ // you can also use `MatchString` to test it without compiling the regexp pattern
67+ assert.MatchString (t, " https://example.com" , ` ^https?:\/\/` ) // success
68+ }
69+ ```
70+
4471It also provided assertion functions to verify a function will panic or not:
4572
4673``` go
@@ -71,7 +98,7 @@ func TestExample(t *testing.T) {
7198 // The following line will set the test result to fail and stop the execution
7299 assert.EqualNow (t, actual, expect)
73100
74- // The following lines will never execute if they are not deep equal.
101+ // The following lines will never execute if they are not equal.
75102 // ...
76103}
77104```
0 commit comments