Codebase list golang-github-vbauerster-mpb / f3afc6e
TestBarInvalidFormat Vladimir Bauer 9 years ago
1 changed file(s) with 30 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
6262 close(cancel)
6363 p.Stop()
6464
65 bytes := buf.Bytes()
66 _, size := utf8.DecodeLastRune(bytes)
67 bytes = bytes[:len(bytes)-size] // removing new line
65 // removing new line
66 bytes := removeLastRune(buf.Bytes())
6867
6968 seen := make(map[rune]bool)
7069 for _, r := range string(bytes) {
7675 if !seen[r] {
7776 t.Errorf("Rune %#U not found in bar\n", r)
7877 }
78 }
79 }
80
81 func TestBarInvalidFormat(t *testing.T) {
82 var buf bytes.Buffer
83 customWidth := 60
84 p := mpb.New().SetWidth(customWidth).SetOut(&buf)
85 customFormat := "(#>=_)"
86 bar := p.AddBar(100).Format(customFormat).
87 TrimLeftSpace().TrimRightSpace()
88
89 for i := 0; i < 100; i++ {
90 time.Sleep(10 * time.Millisecond)
91 bar.Incr(1)
92 }
93
94 p.Stop()
95
96 bytes := removeLastRune(buf.Bytes())
97 got := string(bytes[len(bytes)-customWidth:])
98 want := "[==========================================================]"
99 if got != want {
100 t.Errorf("Expected format: %s, got %s\n", want, got)
79101 }
80102 }
81103
105127 t.Error("bar.InProgress returns true after cancel")
106128 }
107129 }
130
131 func removeLastRune(bytes []byte) []byte {
132 _, size := utf8.DecodeLastRune(bytes)
133 return bytes[:len(bytes)-size]
134 }