@@ -4,17 +4,26 @@ import (
4
4
"path/filepath"
5
5
"reflect"
6
6
"runtime"
7
+ "strings"
7
8
"testing"
8
9
)
9
10
10
- func formattedLog (t * testing.T , fmt string , args ... interface {}) {
11
- _ , file , line , _ := runtime .Caller (2 )
12
- file = filepath .Base (file )
13
- targs := make ([]interface {}, len (args )+ 2 )
14
- targs [0 ] = file
15
- targs [1 ] = line
16
- copy (targs [2 :], args )
17
- t .Logf ("\033 [31m%s:%d:\n \n \t " + fmt + "\033 [39m\n \n " , targs ... )
11
+ func Contains (t * testing.T , expected , actual interface {}) {
12
+ if reflect .TypeOf (expected ) != reflect .TypeOf (actual ) {
13
+ formattedLog (t , "value type not match %T (expected)\n \n \t != %T (actual)" , expected , actual )
14
+ }
15
+ switch e := expected .(type ) {
16
+ case string :
17
+ a := actual .(string )
18
+ if ! strings .Contains (a , e ) {
19
+ formattedLog (t , " %v (expected)\n \n \t != %v (actual)" ,
20
+ expected , actual )
21
+ t .FailNow ()
22
+ }
23
+ default :
24
+ formattedLog (t , "unsupported type %T(expected)" , expected )
25
+ t .FailNow ()
26
+ }
18
27
}
19
28
20
29
func Equal (t * testing.T , expected , actual interface {}) {
@@ -59,3 +68,13 @@ func isNil(object interface{}) bool {
59
68
60
69
return false
61
70
}
71
+
72
+ func formattedLog (t * testing.T , fmt string , args ... interface {}) {
73
+ _ , file , line , _ := runtime .Caller (2 )
74
+ file = filepath .Base (file )
75
+ targs := make ([]interface {}, len (args )+ 2 )
76
+ targs [0 ] = file
77
+ targs [1 ] = line
78
+ copy (targs [2 :], args )
79
+ t .Logf ("\033 [31m%s:%d:\n \n \t " + fmt + "\033 [39m\n \n " , targs ... )
80
+ }
0 commit comments