Codebase list golang-github-vbauerster-mpb / 210ea27
fix tests Vladimir Bauer 5 years ago
2 changed file(s) with 27 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
99 "time"
1010 "unicode/utf8"
1111
12 . "github.com/vbauerster/mpb/v5"
12 "github.com/vbauerster/mpb/v5"
1313 "github.com/vbauerster/mpb/v5/decor"
1414 )
1515
1616 func TestBarCompleted(t *testing.T) {
17 p := New(WithWidth(80), WithOutput(ioutil.Discard))
17 p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard))
1818 total := 80
1919 bar := p.AddBar(int64(total))
2020
3232 }
3333
3434 func TestBarID(t *testing.T) {
35 p := New(WithWidth(80), WithOutput(ioutil.Discard))
35 p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard))
3636 total := 100
3737 wantID := 11
38 bar := p.AddBar(int64(total), BarID(wantID))
38 bar := p.AddBar(int64(total), mpb.BarID(wantID))
3939
4040 go func() {
4141 for i := 0; i < total; i++ {
5656 func TestBarSetRefill(t *testing.T) {
5757 var buf bytes.Buffer
5858
59 p := New(WithOutput(&buf), WithWidth(100))
59 p := mpb.New(mpb.WithOutput(&buf), mpb.WithWidth(100))
6060
6161 total := 100
6262 till := 30
63 refillRune, _ := utf8.DecodeLastRuneInString(DefaultBarStyle)
64
65 bar := p.AddBar(int64(total), TrimSpace())
63 refillRune, _ := utf8.DecodeLastRuneInString(mpb.BarDefaultStyle)
64
65 bar := p.AddBar(int64(total), mpb.BarFillerTrim())
6666
6767 bar.SetRefill(int64(till))
6868 bar.IncrBy(till)
8989 func TestBarHas100PercentWithOnCompleteDecorator(t *testing.T) {
9090 var buf bytes.Buffer
9191
92 p := New(WithWidth(80), WithOutput(&buf))
92 p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(&buf))
9393
9494 total := 50
9595
9696 bar := p.AddBar(int64(total),
97 AppendDecorators(
97 mpb.AppendDecorators(
9898 decor.OnComplete(
9999 decor.Percentage(), "done",
100100 ),
117117 func TestBarHas100PercentWithBarRemoveOnComplete(t *testing.T) {
118118 var buf bytes.Buffer
119119
120 p := New(WithWidth(80), WithOutput(&buf))
120 p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(&buf))
121121
122122 total := 50
123123
124124 bar := p.AddBar(int64(total),
125 BarRemoveOnComplete(),
126 AppendDecorators(decor.Percentage()),
125 mpb.BarRemoveOnComplete(),
126 mpb.AppendDecorators(decor.Percentage()),
127127 )
128128
129129 for i := 0; i < total; i++ {
143143 var buf bytes.Buffer
144144 customFormat := "╢▌▌░╟"
145145 total := 80
146 p := New(WithWidth(total), WithOutput(&buf))
147 bar := p.AddBar(int64(total), BarStyle(customFormat), TrimSpace())
146 p := mpb.New(mpb.WithWidth(total), mpb.WithOutput(&buf))
147 bar := p.Add(int64(total), mpb.NewBarFiller(customFormat), mpb.BarFillerTrim())
148148
149149 for i := 0; i < total; i++ {
150150 bar.Increment()
168168
169169 func TestBarPanicBeforeComplete(t *testing.T) {
170170 var buf bytes.Buffer
171 p := New(
172 WithWidth(80),
173 WithDebugOutput(&buf),
174 WithOutput(ioutil.Discard),
171 p := mpb.New(
172 mpb.WithWidth(80),
173 mpb.WithDebugOutput(&buf),
174 mpb.WithOutput(ioutil.Discard),
175175 )
176176
177177 total := 100
178178 panicMsg := "Upps!!!"
179179 var pCount uint32
180180 bar := p.AddBar(int64(total),
181 PrependDecorators(panicDecorator(panicMsg,
181 mpb.PrependDecorators(panicDecorator(panicMsg,
182182 func(st decor.Statistics) bool {
183183 if st.Current >= 42 {
184184 atomic.AddUint32(&pCount, 1)
208208
209209 func TestBarPanicAfterComplete(t *testing.T) {
210210 var buf bytes.Buffer
211 p := New(
212 WithWidth(80),
213 WithDebugOutput(&buf),
214 WithOutput(ioutil.Discard),
211 p := mpb.New(
212 mpb.WithWidth(80),
213 mpb.WithDebugOutput(&buf),
214 mpb.WithOutput(ioutil.Discard),
215215 )
216216
217217 total := 100
218218 panicMsg := "Upps!!!"
219219 var pCount uint32
220220 bar := p.AddBar(int64(total),
221 PrependDecorators(panicDecorator(panicMsg,
221 mpb.PrependDecorators(panicDecorator(panicMsg,
222222 func(st decor.Statistics) bool {
223223 if st.Completed {
224224 atomic.AddUint32(&pCount, 1)
3232
3333 tReader := &testReader{strings.NewReader(content), false}
3434
35 bar := p.AddBar(int64(len(content)), mpb.TrimSpace())
35 bar := p.AddBar(int64(len(content)), mpb.BarFillerTrim())
3636
3737 var buf bytes.Buffer
3838 _, err := io.Copy(&buf, bar.ProxyReader(tReader))
6969 wt := reader.(io.WriterTo)
7070 tReader := &testWriterTo{reader, wt, false}
7171
72 bar := p.AddBar(int64(len(content)), mpb.TrimSpace())
72 bar := p.AddBar(int64(len(content)), mpb.BarFillerTrim())
7373
7474 var buf bytes.Buffer
7575 _, err := io.Copy(&buf, bar.ProxyReader(tReader))