Codebase list golang-github-vbauerster-mpb / 8ee5289
refactoring bar_test: no need for '\n' in t.Errorf Vladimir Bauer 3 years ago
1 changed file(s) with 6 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
107107
108108 gotID := bar.ID()
109109 if gotID != wantID {
110 t.Errorf("Expected bar id: %d, got %d\n", wantID, gotID)
110 t.Errorf("Expected bar id: %d, got %d", wantID, gotID)
111111 }
112112
113113 bar.IncrBy(total)
140140 got := string(bytes.Split(buf.Bytes(), []byte("\n"))[0])
141141
142142 if !strings.Contains(got, wantBar) {
143 t.Errorf("Want bar: %q, got bar: %q\n", wantBar, got)
143 t.Errorf("Want bar: %q, got bar: %q", wantBar, got)
144144 }
145145 }
146146
162162
163163 hundred := "100 %"
164164 if !bytes.Contains(buf.Bytes(), []byte(hundred)) {
165 t.Errorf("Bar's buffer does not contain: %q\n", hundred)
165 t.Errorf("Bar's buffer does not contain: %q", hundred)
166166 }
167167 }
168168
193193 got := string(bytes.Split(buf.Bytes(), []byte("\n"))[0])
194194
195195 if !strings.Contains(got, wantBar) {
196 t.Errorf("Want bar: %q:%d, got bar: %q:%d\n", wantBar, utf8.RuneCountInString(wantBar), got, utf8.RuneCountInString(got))
196 t.Errorf("Want bar: %q:%d, got bar: %q:%d", wantBar, utf8.RuneCountInString(wantBar), got, utf8.RuneCountInString(got))
197197 }
198198 }
199199
201201 var called [2]bool
202202 td1 := func(s decor.Statistics) string {
203203 if s.AvailableWidth != 80 {
204 t.Errorf("expected AvailableWidth %d got %d\n", 80, s.AvailableWidth)
204 t.Errorf("expected AvailableWidth %d got %d", 80, s.AvailableWidth)
205205 }
206206 called[0] = true
207207 return fmt.Sprintf("\x1b[31;1;4m%s\x1b[0m", strings.Repeat("0", 20))
208208 }
209209 td2 := func(s decor.Statistics) string {
210210 if s.AvailableWidth != 40 {
211 t.Errorf("expected AvailableWidth %d got %d\n", 40, s.AvailableWidth)
211 t.Errorf("expected AvailableWidth %d got %d", 40, s.AvailableWidth)
212212 }
213213 called[1] = true
214214 return ""