forked from smarty/assertions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities_for_test.go
89 lines (69 loc) · 2 KB
/
utilities_for_test.go
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package assertions
import (
"fmt"
"strings"
"testing"
"github.com/smartystreets/assertions/internal/unit"
)
/**************************************************************************/
func TestAssertionsFixture(t *testing.T) {
unit.Run(new(AssertionsFixture), t)
}
type AssertionsFixture struct {
*unit.Fixture
}
func (this *AssertionsFixture) Setup() {
serializer = this
}
func (self *AssertionsFixture) serialize(expected, actual interface{}, message string) string {
return fmt.Sprintf("%v|%v|%s", expected, actual, message)
}
func (self *AssertionsFixture) serializeDetailed(expected, actual interface{}, message string) string {
return fmt.Sprintf("%v|%v|%s", expected, actual, message)
}
func (this *AssertionsFixture) pass(result string) {
this.Assert(result == success, result)
}
func (this *AssertionsFixture) fail(actual string, expected string) {
actual = format(actual)
expected = format(expected)
if actual != expected {
if actual == "" {
actual = "(empty)"
}
this.Errorf("Expected: %s\nActual: %s\n", expected, actual)
}
}
func format(message string) string {
message = strings.Replace(message, "\n", " ", -1)
for strings.Contains(message, " ") {
message = strings.Replace(message, " ", " ", -1)
}
message = strings.Replace(message, "\x1b[32m", "", -1)
message = strings.Replace(message, "\x1b[31m", "", -1)
message = strings.Replace(message, "\x1b[0m", "", -1)
return message
}
/**************************************************************************/
type Thing1 struct {
a string
}
type Thing2 struct {
a string
}
type ThingInterface interface {
Hi()
}
type ThingImplementation struct{}
func (self *ThingImplementation) Hi() {}
type IntAlias int
type StringAlias string
type StringSliceAlias []string
type StringStringMapAlias map[string]string
/**************************************************************************/
type ThingWithEqualMethod struct {
a string
}
func (this ThingWithEqualMethod) Equal(that ThingWithEqualMethod) bool {
return this.a == that.a
}