Codebase list golang-github-vbauerster-mpb / 980ee59
TestPrependPercentage Vladimir Bauer 9 years ago
1 changed file(s) with 22 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
6565
6666 p.Stop()
6767
68 bytes := removeLastRune(buf.Bytes())
69 out := string(bytes)
70 out = out[strings.LastIndex(out, "]")+1:]
7168 want := "100 %"
72 if out != want {
73 t.Errorf("Expected: %s, got %s\n", want, out)
69 if !strings.Contains(buf.String(), want) {
70 t.Errorf("%q not found in bar\n", want)
7471 }
7572 }
73
74 func TestPrependPercentage(t *testing.T) {
75 var buf bytes.Buffer
76 p := mpb.New().SetOut(&buf)
77
78 bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace().
79 PrependPercentage(0, 0)
80
81 for i := 0; i < 100; i++ {
82 time.Sleep(10 * time.Millisecond)
83 bar.Incr(1)
84 }
85
86 p.Stop()
87
88 want := "100 %"
89 if !strings.Contains(buf.String(), want) {
90 t.Errorf("%q not found in bar\n", want)
91 }
92 }