-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathequals_test.go
134 lines (113 loc) · 4.13 KB
/
equals_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package hamcrest_test
import (
"testing"
. "github.com/pepinns/go-hamcrest"
)
func TestStringEqualsReturnsTrueOnEquality(t *testing.T) {
eq := &StringEqualsMatcher{MatchValue: "other"}
result := eq.Match("other")
if !result.Matched() {
t.Fatal("expected 2 strings to match")
}
}
func TestStringEqualsReturnsFalseOnEquality(t *testing.T) {
eq := &StringEqualsMatcher{MatchValue: "other"}
result := eq.Match("something different")
if result.Matched() {
t.Fatal("expected 2 strings to NOT match")
}
}
func TestStringNotEqualsMessageIsClear(t *testing.T) {
AssertFailureMessage(t, "stringToMatch", Equals("otherString"), Equals(`"stringToMatch" is not equal to "otherString"`))
}
func TestStringEqualsMessageIsClear(t *testing.T) {
AssertFailureMessage(t, "stringToMatch", Equals("stringToMatch"), Equals(`"stringToMatch" is equal to "stringToMatch"`))
}
func TestStringEqualsWithAsserter(t *testing.T) {
Assert(t).That("prefix", Equals("prefix"))
}
func TestIntegerEqualsAnotherInteger(t *testing.T) {
Assert(t).That(23, Equals(23))
}
func TestIntEqualsMessageIsClear(t *testing.T) {
AssertFailureMessage(t, 42, Equals(42), Equals("'42' is equal to '42'"))
}
func TestIntNotEqualsMessageIsClear(t *testing.T) {
AssertFailureMessage(t, 45, Equals(42), Equals("'45' is not equal to '42'"))
}
func TestInt8EqualsAnotherInteger(t *testing.T) {
Assert(t).That(int8(23), Equals(23))
}
func TestInt16EqualsAnotherInteger(t *testing.T) {
Assert(t).That(int16(23), Equals(23))
}
func TestInt32EqualsAnotherInteger(t *testing.T) {
Assert(t).That(int32(23), Equals(23))
}
func TestInt32EqualsAnotherInt32(t *testing.T) {
Assert(t).That(int32(23), Equals(int32(23)))
}
func TestUInt32EqualsMatcherInt(t *testing.T) {
Assert(t).That(uint32(23), Equals(23))
}
func TestUInt64EqualsMatcherInt(t *testing.T) {
Assert(t).That(uint64(23), Equals(23))
}
func TestUInt64EqualsMatcherUInt(t *testing.T) {
Assert(t).That(uint64(23), Equals(uint64(23)))
}
func TestUInt64EqualsMatcherUInt32(t *testing.T) {
Assert(t).That(uint64(23), Equals(uint32(23)))
}
func TestUintInMatcherWontAllowOverflows(t *testing.T) {
Assert(t).That(-45, Not(Equals(uint64(18446744073709551571))))
AssertFailureMessage(t, -45, Equals(uint64(18446744073709551571)), Equals("'-45' is < 0 and cannot be converted to uint"))
}
func TestUIntEqualsMessageIsClear(t *testing.T) {
Assert(t).That(42, Equals(uint64(42)))
AssertFailureMessage(t, 42, Equals(uint64(42)), Equals("'42' is equal to '42'"))
}
func TestUIntNotEqualsMessageIsClear(t *testing.T) {
AssertFailureMessage(t, 45, Equals(uint64(42)), Equals("'45' is not equal to '42'"))
}
func TestFloatEqualsAnotherFloat(t *testing.T) {
Assert(t).That(23.41, Equals(23.41))
}
func TestFloat32EqualsAnotherFloat(t *testing.T) {
Assert(t).That(float32(23.41), Equals(23.41))
}
func TestFloatMessageIsClear(t *testing.T) {
AssertFailureMessage(t, 23.41, Equals(55.12), Equals(`"23.4100" is not equal to "55.1200"`))
}
func TestBoolEqualsAnotherBool(t *testing.T) {
Assert(t).That(false, Equals(false))
}
func TestByteslicecanequalbyteslice(t *testing.T) {
Assert(t).That([]byte("somestuff"), Equals([]byte("somestuff")))
}
func TestByteSliceEqualsMessageIsClear(t *testing.T) {
AssertFailureMessage(t, []byte("deadbeef"), Equals([]byte("deadbeef")), Equals(`"6465616462656566" is equal to "6465616462656566"`))
AssertFailureMessage(t, []byte("deadbeefff"), Equals([]byte("deadbeef")), Equals(`"64656164626565666666" is not equal to "6465616462656566"`))
}
func TestStringNotEqualsAnotherString(t *testing.T) {
Assert(t).That("somestring", Not(Equals("xxxsomestring")))
}
func TestEqualsCanCompareMaps(t *testing.T) {
sourceMap := make(map[string]string)
testMap := make(map[string]string)
sourceMap["foo"] = "bar"
testMap["foo"] = "bar"
Assert(t).That(sourceMap, Equals(testMap))
}
func TestIsTrueMatches(t *testing.T) {
Assert(t).That(true, IsTrue())
}
func TestIsTrueFails(t *testing.T) {
AssertFailureMessage(t, false, IsTrue(), Equals(`"false" is not equal to "true"`))
}
func TestIsFalse(t *testing.T) {
Assert(t).That(false, IsFalse())
}
func TestIsFalseFails(t *testing.T) {
AssertFailureMessage(t, true, IsFalse(), Equals(`"true" is not equal to "false"`))
}