|
|
|
@ -3,6 +3,7 @@ package assert
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"reflect"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
@ -61,6 +62,20 @@ func NotEqual(t *testing.T, actual, other interface{}) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Regexp(t *testing.T, actual, pattern string) {
|
|
|
|
|
rx := regexp.MustCompile(pattern)
|
|
|
|
|
if !(rx.MatchString(actual)) {
|
|
|
|
|
t.Errorf("Received (type %v):\n% #v", reflect.TypeOf(actual), pretty.Formatter(actual))
|
|
|
|
|
t.Errorf("\n---\n")
|
|
|
|
|
t.Errorf("But expected to match regexp:\n% #v", pretty.Formatter(pattern))
|
|
|
|
|
t.Errorf("\n---\n")
|
|
|
|
|
t.Errorf("Diff:\n")
|
|
|
|
|
for _, diff := range pretty.Diff(actual, pattern) {
|
|
|
|
|
t.Errorf("\t% #v", diff)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toJSON(t *testing.T, obj interface{}) string {
|
|
|
|
|
json, err := json.Marshal(obj)
|
|
|
|
|
// json, err := json.MarshalIndent(obj, "", " ")
|
|
|
|
|