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 package issue530
30
31 import (
32 "strings"
33 "testing"
34 )
35
36
37
38
39 func TestStringNNMessageNNString(t *testing.T) {
40 exp := "MessageWith&Ampersand"
41 m := &Foo5{
42 Bar1: Bar1{Str: exp},
43 }
44 check(t, "Bar1", m.String(), exp)
45 }
46
47 func TestStringNMessageNNString(t *testing.T) {
48 exp := "MessageWith&Ampersand"
49 m := &Foo5{
50 Bar2: &Bar1{Str: exp},
51 }
52 check(t, "Bar2", m.String(), exp)
53 }
54
55 func TestStringNNMessageNString(t *testing.T) {
56 exp := "MessageWith&Ampersand"
57 m := &Foo5{
58 Bar3: Bar2{Str: &exp},
59 }
60 check(t, "Bar3", m.String(), exp)
61 }
62
63 func TestStringNMessageNString(t *testing.T) {
64 exp := "MessageWith&Ampersand"
65 m := &Foo5{
66 Bar4: &Bar2{Str: &exp},
67 }
68 check(t, "Bar4", m.String(), exp)
69 }
70
71 func TestStringRNNMessageNNString(t *testing.T) {
72 exp1 := "MessageWith&Ampersand1"
73 exp2 := "MessageWith&Ampersand2"
74 m := &Foo5{
75 Bars1: []Bar1{{Str: exp1}, {Str: exp2}},
76 }
77 check(t, "Bars1", m.String(), exp1, exp2)
78 }
79
80 func TestStringRNMessageNNString(t *testing.T) {
81 exp1 := "MessageWith&Ampersand1"
82 exp2 := "MessageWith&Ampersand2"
83 m := &Foo5{
84 Bars2: []*Bar1{{Str: exp1}, nil, {Str: exp2}},
85 }
86 check(t, "Bars2", m.String(), exp1, exp2)
87 }
88
89 func TestStringRNNMessageNString(t *testing.T) {
90 exp1 := "MessageWith&Ampersand1"
91 exp2 := "MessageWith&Ampersand2"
92 m := &Foo5{
93 Bars3: []Bar2{{Str: &exp1}, {Str: &exp2}},
94 }
95 check(t, "Bars3", m.String(), exp1, exp2)
96 }
97
98 func TestStringRNMessageNString(t *testing.T) {
99 exp1 := "MessageWith&Ampersand1"
100 exp2 := "MessageWith&Ampersand2"
101 m := &Foo5{
102 Bars4: []*Bar2{{Str: &exp1}, {Str: &exp2}},
103 }
104 check(t, "Bars4", m.String(), exp1, exp2)
105 }
106
107 func TestStringDeepRNNMessageRNNMessageNNStringAndNString(t *testing.T) {
108 exp1 := "MessageWith&Ampersand1"
109 exp2 := "MessageWith&Ampersand2"
110 m := &Foo5{
111 Barrs1: []Bar3{
112 {
113 Bars4: []Bar4{
114 {
115 Str: exp1,
116 },
117 },
118 Bars2: []Bar2{
119 {
120 Str: &exp2,
121 },
122 },
123 },
124 },
125 }
126 check(t, "Barrs1", m.String(), exp1, exp2)
127 }
128
129 func TestStringDeepRNNMessageRNMessageNNStringAndNString(t *testing.T) {
130 exp1 := "MessageWith&Ampersand1"
131 exp2 := "MessageWith&Ampersand2"
132 m := &Foo5{
133 Barrs2: []Bar5{
134 {
135 Bars2: []*Bar2{
136 {
137 Str: &exp1,
138 },
139 },
140 Bars1: []*Bar1{
141 {
142 Str: exp2,
143 },
144 },
145 },
146 },
147 }
148 check(t, "Barrs2", m.String(), exp1, exp2)
149 }
150
151 func TestStringMapNMessageRNNMessageNNStringAndNString(t *testing.T) {
152 exp1 := "MessageWith&Ampersand1"
153 exp2 := "MessageWith&Ampersand2"
154 m := &Foo5{
155 Barmap1: map[string]*Bar3{
156 "one": {
157 Bars4: []Bar4{
158 {
159 Str: exp1,
160 },
161 },
162 Bars2: []Bar2{
163 {
164 Str: &exp2,
165 },
166 },
167 },
168 },
169 }
170 check(t, "Barmap1", m.String(), exp1, exp2)
171 }
172
173 func TestStringMapNMessageRNMessageNNStringAndNString(t *testing.T) {
174 exp1 := "MessageWith&Ampersand1"
175 exp2 := "MessageWith&Ampersand2"
176 m := &Foo5{
177 Barmap2: map[string]*Bar5{
178 "one": {
179 Bars2: []*Bar2{
180 {
181 Str: &exp1,
182 },
183 },
184 Bars1: []*Bar1{
185 {
186 Str: exp2,
187 },
188 },
189 },
190 },
191 }
192 check(t, "Barmap2", m.String(), exp1, exp2)
193 }
194
195 func TestStringRNNMessageNNStringRNMessageNStringNString(t *testing.T) {
196 exp1 := "MessageWith&Ampersand1"
197 exp2 := "MessageWith&Ampersand2"
198 exp3 := "MessageWith&Ampersand3"
199 m := &Bar7{
200 Bars71: []Bar7{
201 {
202 Bars72: []*Bar7{
203 {
204 Str2: &exp3,
205 },
206 },
207 Str2: &exp2,
208 },
209 },
210 Str1: exp1,
211 }
212 check(t, "Bar7", m.String(), exp1, exp2, exp3)
213 }
214
215 func TestStringRNNMessageWithNoStringerNNString(t *testing.T) {
216 exp1 := "MessageWith&Ampersand1"
217 exp2 := "MessageWith&Ampersand2"
218 m := &Bar8{
219 Bars1: []Bar9{{Str: exp1}, {Str: exp2}},
220 }
221 check(t, "Bars1", m.String(), exp1, exp2)
222 }
223
224 func check(t *testing.T, field, result string, expects ...string) {
225
226 for _, expect := range expects {
227 if !strings.Contains(result, expect) {
228 t.Fatalf("Expected %s to contain: %s, but got: %s\n", field, expect, result)
229 }
230 }
231 }
232
View as plain text