dot import
Vladimir Bauer
8 years ago
| 8 | 8 | "testing" |
| 9 | 9 | "time" |
| 10 | 10 | |
| 11 | "github.com/vbauerster/mpb" | |
| 11 | . "github.com/vbauerster/mpb" | |
| 12 | 12 | "github.com/vbauerster/mpb/decor" |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | 15 | func TestBarCompleted(t *testing.T) { |
| 16 | p := mpb.New(mpb.WithOutput(ioutil.Discard)) | |
| 16 | p := New(WithOutput(ioutil.Discard)) | |
| 17 | 17 | total := 80 |
| 18 | 18 | bar := p.AddBar(int64(total)) |
| 19 | 19 | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | func TestBarID(t *testing.T) { |
| 34 | p := mpb.New(mpb.WithOutput(ioutil.Discard)) | |
| 34 | p := New(WithOutput(ioutil.Discard)) | |
| 35 | 35 | |
| 36 | 36 | numBars := 3 |
| 37 | bars := make([]*mpb.Bar, numBars) | |
| 37 | bars := make([]*Bar, numBars) | |
| 38 | 38 | for i := 0; i < numBars; i++ { |
| 39 | bars[i] = p.AddBar(80, mpb.BarID(i)) | |
| 40 | go func(bar *mpb.Bar) { | |
| 39 | bars[i] = p.AddBar(80, BarID(i)) | |
| 40 | go func(bar *Bar) { | |
| 41 | 41 | for i := 0; i < 80; i++ { |
| 42 | 42 | time.Sleep(10 * time.Millisecond) |
| 43 | 43 | bar.Increment() |
| 58 | 58 | var buf bytes.Buffer |
| 59 | 59 | |
| 60 | 60 | width := 100 |
| 61 | p := mpb.New( | |
| 62 | mpb.WithOutput(&buf), | |
| 63 | mpb.WithWidth(width), | |
| 64 | ) | |
| 61 | p := New(WithOutput(&buf), WithWidth(width)) | |
| 65 | 62 | |
| 66 | 63 | total := 100 |
| 67 | 64 | till := 30 |
| 68 | 65 | refillChar := '+' |
| 69 | 66 | |
| 70 | bar := p.AddBar(100, mpb.BarTrim()) | |
| 67 | bar := p.AddBar(100, BarTrim()) | |
| 71 | 68 | |
| 72 | 69 | bar.ResumeFill(refillChar, int64(till)) |
| 73 | 70 | |
| 90 | 87 | func TestBarPanics(t *testing.T) { |
| 91 | 88 | var wg sync.WaitGroup |
| 92 | 89 | var buf bytes.Buffer |
| 93 | p := mpb.New(mpb.WithOutput(&buf), mpb.WithWaitGroup(&wg)) | |
| 90 | p := New(WithOutput(&buf), WithWaitGroup(&wg)) | |
| 94 | 91 | |
| 95 | 92 | wantPanic := "Upps!!!" |
| 96 | 93 | numBars := 3 |
| 98 | 95 | |
| 99 | 96 | for i := 0; i < numBars; i++ { |
| 100 | 97 | name := fmt.Sprintf("b#%02d:", i) |
| 101 | bar := p.AddBar(100, mpb.BarID(i), mpb.PrependDecorators( | |
| 98 | bar := p.AddBar(100, BarID(i), PrependDecorators( | |
| 102 | 99 | func(s *decor.Statistics, _ chan<- int, _ <-chan int) string { |
| 103 | 100 | if s.ID == 2 && s.Current >= 42 { |
| 104 | 101 | panic(wantPanic) |