Codebase list golang-github-vbauerster-mpb / f6c17d7
TestAppendPercentage Vladimir Bauer 9 years ago
1 changed file(s) with 24 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
66 "io/ioutil"
77 "strings"
88 "testing"
9 "time"
910
1011 "github.com/vbauerster/mpb"
1112 )
4950 t.Errorf("Expected: %s, got %s\n", want, out)
5051 }
5152 }
53
54 func TestAppendPercentage(t *testing.T) {
55 var buf bytes.Buffer
56 p := mpb.New().SetOut(&buf)
57
58 bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace().
59 AppendPercentage(0, 0)
60
61 for i := 0; i < 100; i++ {
62 time.Sleep(10 * time.Millisecond)
63 bar.Incr(1)
64 }
65
66 p.Stop()
67
68 bytes := removeLastRune(buf.Bytes())
69 out := string(bytes)
70 out = out[strings.LastIndex(out, "]")+1:]
71 want := "100 %"
72 if out != want {
73 t.Errorf("Expected: %s, got %s\n", want, out)
74 }
75 }