TestAppendElapsed
Vladimir Bauer
9 years ago
| 224 | 224 | t.Errorf("%q not found in bar: %s\n", want, barOut) |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | ||
| 228 | func TestAppendElapsed(t *testing.T) { | |
| 229 | var buf bytes.Buffer | |
| 230 | p := mpb.New().SetOut(&buf) | |
| 231 | ||
| 232 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 233 | AppendElapsed(0, 0) | |
| 234 | ||
| 235 | for i := 0; i < 100; i++ { | |
| 236 | time.Sleep(10 * time.Millisecond) | |
| 237 | bar.Incr(1) | |
| 238 | } | |
| 239 | ||
| 240 | p.Stop() | |
| 241 | ||
| 242 | want := "]1s" | |
| 243 | barOut := buf.String() | |
| 244 | if !strings.Contains(barOut, want) { | |
| 245 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 246 | } | |
| 247 | } | |
| 248 | ||
| 249 | func TestAppendElapsedDindentRight(t *testing.T) { | |
| 250 | var buf bytes.Buffer | |
| 251 | p := mpb.New().SetOut(&buf) | |
| 252 | ||
| 253 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 254 | AppendElapsed(3, mpb.DidentRight) | |
| 255 | ||
| 256 | for i := 0; i < 100; i++ { | |
| 257 | time.Sleep(10 * time.Millisecond) | |
| 258 | bar.Incr(1) | |
| 259 | } | |
| 260 | ||
| 261 | p.Stop() | |
| 262 | ||
| 263 | want := "]1s " | |
| 264 | barOut := buf.String() | |
| 265 | if !strings.Contains(barOut, want) { | |
| 266 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 267 | } | |
| 268 | } |