Codebase list golang-github-vbauerster-mpb / 7bdf41b
TestInvalidWidth Vladimir Bauer 9 years ago
1 changed file(s) with 28 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
1919 bar.Incr(1)
2020 }
2121 p.Stop()
22 runeCount := utf8.RuneCountInString(buf.String())
23 defWidth := 81 // + 1 for new line
24 if runeCount != defWidth {
25 t.Errorf("Expected default width: %d, got: %d\n", defWidth, runeCount)
22
23 wantWidth := 80
24 gotWidth := utf8.RuneCount(buf.Bytes())
25 if gotWidth != wantWidth+1 { // + 1 for new line
26 t.Errorf("Expected default width: %d, got: %d\n", wantWidth, gotWidth)
2627 }
2728 }
2829
2930 func TestCustomWidth(t *testing.T) {
30 customWidth := 60
31 var buf bytes.Buffer
32 p := mpb.New().SetWidth(customWidth).SetOut(&buf)
31 wantWidth := 60
32 var buf bytes.Buffer
33 p := mpb.New().SetWidth(wantWidth).SetOut(&buf)
3334 bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace()
3435 for i := 0; i < 100; i++ {
3536 bar.Incr(1)
3637 }
3738 p.Stop()
38 runeCount := utf8.RuneCountInString(buf.String())
39 if runeCount != customWidth+1 { // +1 for new line
40 t.Errorf("Expected default width: %d, got: %d\n", customWidth, runeCount)
39
40 gotWidth := utf8.RuneCount(buf.Bytes())
41 if gotWidth != wantWidth+1 { // +1 for new line
42 t.Errorf("Expected default width: %d, got: %d\n", wantWidth, gotWidth)
43 }
44 }
45
46 func TestInvalidWidth(t *testing.T) {
47 var buf bytes.Buffer
48 p := mpb.New().SetWidth(1).SetOut(&buf)
49 bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace()
50 for i := 0; i < 100; i++ {
51 bar.Incr(1)
52 }
53 p.Stop()
54
55 wantWidth := 80
56 gotWidth := utf8.RuneCount(buf.Bytes())
57 if gotWidth != wantWidth+1 { // +1 for new line
58 t.Errorf("Expected width: %d, got: %d\n", wantWidth, gotWidth)
4159 }
4260 }
4361