Test fixes
Vladimir Bauer
8 years ago
| 37 | 37 |
|
| 38 | 38 |
p.Stop()
|
| 39 | 39 |
|
| 40 | |
gotWidth := len(buf.Bytes())
|
|
40 |
gotWidth := utf8.RuneCount(buf.Bytes())
|
| 41 | 41 |
if gotWidth != tc.expected {
|
| 42 | 42 |
t.Errorf("%s: Expected width: %d, got: %d\n", k, tc.expected, gotWidth)
|
| 43 | 43 |
}
|
| 44 | 44 |
gotWidth := utf8.RuneCount(buf.Bytes())
|
| 45 | 45 |
if gotWidth != wantWidth+1 { // +1 for new line
|
| 46 | 46 |
t.Errorf("Expected default width: %d, got: %d\n", wantWidth, gotWidth)
|
| 47 | |
}
|
| 48 | |
}
|
| 49 | |
|
| 50 | |
func TestInvalidWidth(t *testing.T) {
|
| 51 | |
var buf bytes.Buffer
|
| 52 | |
p := mpb.New(mpb.WithWidth(1), mpb.Output(&buf))
|
| 53 | |
bar := p.AddBar(100, mpb.BarTrim())
|
| 54 | |
|
| 55 | |
for i := 0; i < 100; i++ {
|
| 56 | |
bar.Incr(1)
|
| 57 | |
}
|
| 58 | |
p.Stop()
|
| 59 | |
|
| 60 | |
wantWidth := 80
|
| 61 | |
gotWidth := utf8.RuneCount(buf.Bytes())
|
| 62 | |
if gotWidth != wantWidth+1 { // +1 for new line
|
| 63 | |
t.Errorf("Expected width: %d, got: %d\n", wantWidth, gotWidth)
|
| 64 | 47 |
}
|
| 65 | 48 |
}
|
| 66 | 49 |
|