Codebase list golang-github-vbauerster-mpb / 36b6f0e
TestDecorStatisticsAvailableWidth Vladimir Bauer 5 years ago
1 changed file(s) with 34 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
253253 }
254254 }
255255
256 func TestDecorStatisticsAvailableWidth(t *testing.T) {
257 td1 := func(s decor.Statistics) string {
258 if s.AvailableWidth != 80 {
259 t.Errorf("expected AvailableWidth %d got %d\n", 80, s.AvailableWidth)
260 }
261 return fmt.Sprintf("\x1b[31;1;4m%s\x1b[0m", strings.Repeat("1", 20))
262 }
263 td2 := func(s decor.Statistics) string {
264 if s.AvailableWidth != 60 {
265 t.Errorf("expected AvailableWidth %d got %d\n", 60, s.AvailableWidth)
266 }
267 return ""
268 }
269 total := 100
270 p := mpb.New(
271 mpb.WithWidth(100),
272 mpb.WithOutput(ioutil.Discard),
273 )
274 bar := p.AddBar(int64(total),
275 mpb.BarFillerTrim(),
276 mpb.PrependDecorators(
277 decor.Name(strings.Repeat("0", 20)),
278 decor.Any(td1),
279 ),
280 mpb.AppendDecorators(
281 decor.Any(td2),
282 ),
283 )
284 for i := 0; i < total; i++ {
285 time.Sleep(10 * time.Millisecond)
286 bar.Increment()
287 }
288 }
289
256290 func panicDecorator(panicMsg string, cond func(decor.Statistics) bool) decor.Decorator {
257291 return decor.Any(func(st decor.Statistics) string {
258292 if cond(st) {