Codebase list golang-github-vbauerster-mpb / c8a7e9f
TestGetSpinner Vladimir Bauer 9 years ago
1 changed file(s) with 26 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
128128 }
129129 }
130130
131 func TestGetSpinner(t *testing.T) {
132 var buf bytes.Buffer
133 p := mpb.New().SetOut(&buf)
134 bar := p.AddBar(0).TrimLeftSpace().TrimRightSpace()
135
136 for i := 0; i < 100; i++ {
137 time.Sleep(10 * time.Millisecond)
138 bar.Incr(1)
139 }
140
141 p.Stop()
142
143 spinnerChars := []byte(`-\|/`)
144 seen := make(map[byte]bool)
145 for _, b := range buf.Bytes() {
146 if !seen[b] {
147 seen[b] = true
148 }
149 }
150 for _, b := range spinnerChars {
151 if !seen[b] {
152 t.Errorf("Char %#U not found in bar's output\n", b)
153 }
154 }
155 }
156
131157 func removeLastRune(bytes []byte) []byte {
132158 _, size := utf8.DecodeLastRune(bytes)
133159 return bytes[:len(bytes)-size]