TestPrependElapsed
Vladimir Bauer
9 years ago
| 182 | 182 | t.Errorf("%q not found in bar: %s\n", want, barOut) |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | ||
| 186 | func TestPrependElapsed(t *testing.T) { | |
| 187 | var buf bytes.Buffer | |
| 188 | p := mpb.New().SetOut(&buf) | |
| 189 | ||
| 190 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 191 | PrependElapsed(0, 0) | |
| 192 | ||
| 193 | for i := 0; i < 100; i++ { | |
| 194 | time.Sleep(10 * time.Millisecond) | |
| 195 | bar.Incr(1) | |
| 196 | } | |
| 197 | ||
| 198 | p.Stop() | |
| 199 | ||
| 200 | want := "1s[" | |
| 201 | barOut := buf.String() | |
| 202 | if !strings.Contains(barOut, want) { | |
| 203 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 204 | } | |
| 205 | } | |
| 206 | ||
| 207 | func TestPrependElapsedDindentRight(t *testing.T) { | |
| 208 | var buf bytes.Buffer | |
| 209 | p := mpb.New().SetOut(&buf) | |
| 210 | ||
| 211 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 212 | PrependElapsed(3, mpb.DidentRight) | |
| 213 | ||
| 214 | for i := 0; i < 100; i++ { | |
| 215 | time.Sleep(10 * time.Millisecond) | |
| 216 | bar.Incr(1) | |
| 217 | } | |
| 218 | ||
| 219 | p.Stop() | |
| 220 | ||
| 221 | want := "1s [" | |
| 222 | barOut := buf.String() | |
| 223 | if !strings.Contains(barOut, want) { | |
| 224 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 225 | } | |
| 226 | } |