diff --git a/decorators_test.go b/decorators_test.go index 356a992..35ee393 100644 --- a/decorators_test.go +++ b/decorators_test.go @@ -183,3 +183,45 @@ t.Errorf("%q not found in bar: %s\n", want, barOut) } } + +func TestPrependElapsed(t *testing.T) { + var buf bytes.Buffer + p := mpb.New().SetOut(&buf) + + bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). + PrependElapsed(0, 0) + + for i := 0; i < 100; i++ { + time.Sleep(10 * time.Millisecond) + bar.Incr(1) + } + + p.Stop() + + want := "1s[" + barOut := buf.String() + if !strings.Contains(barOut, want) { + t.Errorf("%q not found in bar: %s\n", want, barOut) + } +} + +func TestPrependElapsedDindentRight(t *testing.T) { + var buf bytes.Buffer + p := mpb.New().SetOut(&buf) + + bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). + PrependElapsed(3, mpb.DidentRight) + + for i := 0; i < 100; i++ { + time.Sleep(10 * time.Millisecond) + bar.Incr(1) + } + + p.Stop() + + want := "1s [" + barOut := buf.String() + if !strings.Contains(barOut, want) { + t.Errorf("%q not found in bar: %s\n", want, barOut) + } +}