diff --git a/decorators_test.go b/decorators_test.go index 17b13b7..7ad40e0 100644 --- a/decorators_test.go +++ b/decorators_test.go @@ -7,6 +7,7 @@ "io/ioutil" "strings" "testing" + "time" "github.com/vbauerster/mpb" ) @@ -50,3 +51,26 @@ t.Errorf("Expected: %s, got %s\n", want, out) } } + +func TestAppendPercentage(t *testing.T) { + var buf bytes.Buffer + p := mpb.New().SetOut(&buf) + + bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). + AppendPercentage(0, 0) + + for i := 0; i < 100; i++ { + time.Sleep(10 * time.Millisecond) + bar.Incr(1) + } + + p.Stop() + + bytes := removeLastRune(buf.Bytes()) + out := string(bytes) + out = out[strings.LastIndex(out, "]")+1:] + want := "100 %" + if out != want { + t.Errorf("Expected: %s, got %s\n", want, out) + } +}