diff --git a/decorators_test.go b/decorators_test.go index 35ee393..90f5cb1 100644 --- a/decorators_test.go +++ b/decorators_test.go @@ -225,3 +225,45 @@ t.Errorf("%q not found in bar: %s\n", want, barOut) } } + +func TestAppendElapsed(t *testing.T) { + var buf bytes.Buffer + p := mpb.New().SetOut(&buf) + + bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). + AppendElapsed(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 TestAppendElapsedDindentRight(t *testing.T) { + var buf bytes.Buffer + p := mpb.New().SetOut(&buf) + + bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). + AppendElapsed(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) + } +}