-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteq_diff_test.go
141 lines (131 loc) · 2.65 KB
/
teq_diff_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
135
136
137
138
139
140
141
package teq_test
import (
"net/http"
"testing"
"time"
"github.com/seiyab/teq"
)
func TestEqual_StringFormat(t *testing.T) {
assert := teq.New()
a := `abc
def
ghi
jkl
mno`
b := `abc
ghi
jkl
mno`
mt := &mockT{}
assert.Equal(mt, a, b)
if len(mt.errors) != 1 {
t.Fatalf("expected 1 error, got %d", len(mt.errors))
}
expected := `not equal
differences:
--- expected
+++ actual
@@ -1,3 +1,2 @@
abc
-def
ghi
`
if mt.errors[0] != expected {
t.Errorf("expected %q, got %q", expected, mt.errors[0])
}
assert.Equal(t, expected, mt.errors[0])
}
func TestEqual_Format(t *testing.T) {
assert := teq.New()
t.Run("array", func(t *testing.T) {
mt := &mockT{}
assert.Equal(mt, [1]int{0}, [1]int{1})
if len(mt.errors) != 1 {
t.Fatalf("expected 1 error, got %d", len(mt.errors))
}
expected := `not equal
differences:
--- expected
+++ actual
@@ -1,3 +1,3 @@
[1]int{
- int(0),
+ int(1),
}
`
if mt.errors[0] != expected {
t.Errorf("expected %q, got %q", expected, mt.errors[0])
}
assert.Equal(t, expected, mt.errors[0])
})
t.Run("pointer", func(t *testing.T) {
t.Run("nil", func(t *testing.T) {
mt := &mockT{}
x := 100
a := &x
b := (*int)(nil)
assert.Equal(mt, a, b)
if len(mt.errors) != 1 {
t.Fatalf("expected 1 error, got %d", len(mt.errors))
}
expected := `not equal
differences:
--- expected
+++ actual
@@ -1 +1 @@
-*int(100)
+<nil>
`
if mt.errors[0] != expected {
t.Errorf("expected %q, got %q", expected, mt.errors[0])
}
assert.Equal(t, expected, mt.errors[0])
})
t.Run("pointer of struct", func(t *testing.T) {
mt := &mockT{}
assert.Equal(mt, &http.Client{Timeout: time.Second}, http.DefaultClient)
if len(mt.errors) != 1 {
t.Fatalf("expected 1 error, got %d", len(mt.errors))
}
expected := `not equal
differences:
--- expected
+++ actual
@@ -4,3 +4,3 @@
Jar: http.CookieJar(<nil>),
- Timeout: time.Duration(1000000000),
+ Timeout: time.Duration(0),
}
`
if mt.errors[0] != expected {
t.Errorf("expected %q, got %q", expected, mt.errors[0])
}
assert.Equal(t, expected, mt.errors[0])
})
t.Run("slice of pointer", func(t *testing.T) {
ref := func(s string) *string { return &s }
mt := &mockT{}
assert.Equal(mt,
[]*string{ref("a"), ref("b"), ref("c"), nil},
[]*string{ref("a"), ref("b"), ref("d"), nil},
)
if len(mt.errors) != 1 {
t.Fatalf("expected 1 error, got %d", len(mt.errors))
}
expected := `not equal
differences:
--- expected
+++ actual
@@ -3,3 +3,3 @@
*"b",
- *"c",
+ *"d",
<nil>,
`
if mt.errors[0] != expected {
t.Errorf("expected %q, got %q", expected, mt.errors[0])
}
assert.Equal(t, expected, mt.errors[0])
})
})
}