1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package assertions
import (
"fmt"
"path"
"runtime"
"strings"
"testing"
)
func pass(t *testing.T, result string) {
if result != success {
_, file, line, _ := runtime.Caller(1)
base := path.Base(file)
t.Errorf("Expectation should have passed but failed (see %s: line %d): '%s'", base, line, result)
}
}
func fail(t *testing.T, actual string, expected string) {
actual = format(actual)
expected = format(expected)
if actual != expected {
if actual == "" {
actual = "(empty)"
}
_, file, line, _ := runtime.Caller(1)
base := path.Base(file)
t.Errorf("Expectation should have failed but passed (see %s: line %d). \nExpected: %s\nActual: %s\n",
base, line, expected, actual)
}
}
func format(message string) string {
message = strings.Replace(message, "\n", " ", -1)
for strings.Contains(message, " ") {
message = strings.Replace(message, " ", " ", -1)
}
return message
}
type Thing1 struct {
a string
}
type Thing2 struct {
a string
}
type Thinger interface {
Hi()
}
type Thing struct{}
func (self *Thing) Hi() {}
type IntAlias int
type StringAlias string
type StringSliceAlias []string
type StringStringMapAlias map[string]string
/******** FakeSerialzier ********/
type fakeSerializer struct{}
func (self *fakeSerializer) serialize(expected, actual interface{}, message string) string {
return fmt.Sprintf("%v|%v|%s", expected, actual, message)
}
func (self *fakeSerializer) serializeDetailed(expected, actual interface{}, message string) string {
return fmt.Sprintf("%v|%v|%s", expected, actual, message)
}
func newFakeSerializer() *fakeSerializer {
return new(fakeSerializer)
}
|