refactoring bar_test: no need for '\n' in t.Errorf
Vladimir Bauer
3 years ago
| 107 | 107 | |
| 108 | 108 | gotID := bar.ID() |
| 109 | 109 | 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) | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | bar.IncrBy(total) |
| 140 | 140 | got := string(bytes.Split(buf.Bytes(), []byte("\n"))[0]) |
| 141 | 141 | |
| 142 | 142 | 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) | |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 162 | 162 | |
| 163 | 163 | hundred := "100 %" |
| 164 | 164 | 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) | |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
| 193 | 193 | got := string(bytes.Split(buf.Bytes(), []byte("\n"))[0]) |
| 194 | 194 | |
| 195 | 195 | 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)) | |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 201 | 201 | var called [2]bool |
| 202 | 202 | td1 := func(s decor.Statistics) string { |
| 203 | 203 | 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) | |
| 205 | 205 | } |
| 206 | 206 | called[0] = true |
| 207 | 207 | return fmt.Sprintf("\x1b[31;1;4m%s\x1b[0m", strings.Repeat("0", 20)) |
| 208 | 208 | } |
| 209 | 209 | td2 := func(s decor.Statistics) string { |
| 210 | 210 | 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) | |
| 212 | 212 | } |
| 213 | 213 | called[1] = true |
| 214 | 214 | return "" |