TestPrependPercentage
Vladimir Bauer
9 years ago
| 65 | 65 | |
| 66 | 66 | p.Stop() |
| 67 | 67 | |
| 68 | bytes := removeLastRune(buf.Bytes()) | |
| 69 | out := string(bytes) | |
| 70 | out = out[strings.LastIndex(out, "]")+1:] | |
| 71 | 68 | want := "100 %" |
| 72 | if out != want { | |
| 73 | t.Errorf("Expected: %s, got %s\n", want, out) | |
| 69 | if !strings.Contains(buf.String(), want) { | |
| 70 | t.Errorf("%q not found in bar\n", want) | |
| 74 | 71 | } |
| 75 | 72 | } |
| 73 | ||
| 74 | func TestPrependPercentage(t *testing.T) { | |
| 75 | var buf bytes.Buffer | |
| 76 | p := mpb.New().SetOut(&buf) | |
| 77 | ||
| 78 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 79 | PrependPercentage(0, 0) | |
| 80 | ||
| 81 | for i := 0; i < 100; i++ { | |
| 82 | time.Sleep(10 * time.Millisecond) | |
| 83 | bar.Incr(1) | |
| 84 | } | |
| 85 | ||
| 86 | p.Stop() | |
| 87 | ||
| 88 | want := "100 %" | |
| 89 | if !strings.Contains(buf.String(), want) { | |
| 90 | t.Errorf("%q not found in bar\n", want) | |
| 91 | } | |
| 92 | } |