| 9 | 9 |
"time"
|
| 10 | 10 |
"unicode/utf8"
|
| 11 | 11 |
|
| 12 | |
. "github.com/vbauerster/mpb/v5"
|
|
12 |
"github.com/vbauerster/mpb/v5"
|
| 13 | 13 |
"github.com/vbauerster/mpb/v5/decor"
|
| 14 | 14 |
)
|
| 15 | 15 |
|
| 16 | 16 |
func TestBarCompleted(t *testing.T) {
|
| 17 | |
p := New(WithWidth(80), WithOutput(ioutil.Discard))
|
|
17 |
p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard))
|
| 18 | 18 |
total := 80
|
| 19 | 19 |
bar := p.AddBar(int64(total))
|
| 20 | 20 |
|
|
| 32 | 32 |
}
|
| 33 | 33 |
|
| 34 | 34 |
func TestBarID(t *testing.T) {
|
| 35 | |
p := New(WithWidth(80), WithOutput(ioutil.Discard))
|
|
35 |
p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard))
|
| 36 | 36 |
total := 100
|
| 37 | 37 |
wantID := 11
|
| 38 | |
bar := p.AddBar(int64(total), BarID(wantID))
|
|
38 |
bar := p.AddBar(int64(total), mpb.BarID(wantID))
|
| 39 | 39 |
|
| 40 | 40 |
go func() {
|
| 41 | 41 |
for i := 0; i < total; i++ {
|
|
| 56 | 56 |
func TestBarSetRefill(t *testing.T) {
|
| 57 | 57 |
var buf bytes.Buffer
|
| 58 | 58 |
|
| 59 | |
p := New(WithOutput(&buf), WithWidth(100))
|
|
59 |
p := mpb.New(mpb.WithOutput(&buf), mpb.WithWidth(100))
|
| 60 | 60 |
|
| 61 | 61 |
total := 100
|
| 62 | 62 |
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())
|
| 66 | 66 |
|
| 67 | 67 |
bar.SetRefill(int64(till))
|
| 68 | 68 |
bar.IncrBy(till)
|
|
| 89 | 89 |
func TestBarHas100PercentWithOnCompleteDecorator(t *testing.T) {
|
| 90 | 90 |
var buf bytes.Buffer
|
| 91 | 91 |
|
| 92 | |
p := New(WithWidth(80), WithOutput(&buf))
|
|
92 |
p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(&buf))
|
| 93 | 93 |
|
| 94 | 94 |
total := 50
|
| 95 | 95 |
|
| 96 | 96 |
bar := p.AddBar(int64(total),
|
| 97 | |
AppendDecorators(
|
|
97 |
mpb.AppendDecorators(
|
| 98 | 98 |
decor.OnComplete(
|
| 99 | 99 |
decor.Percentage(), "done",
|
| 100 | 100 |
),
|
|
| 117 | 117 |
func TestBarHas100PercentWithBarRemoveOnComplete(t *testing.T) {
|
| 118 | 118 |
var buf bytes.Buffer
|
| 119 | 119 |
|
| 120 | |
p := New(WithWidth(80), WithOutput(&buf))
|
|
120 |
p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(&buf))
|
| 121 | 121 |
|
| 122 | 122 |
total := 50
|
| 123 | 123 |
|
| 124 | 124 |
bar := p.AddBar(int64(total),
|
| 125 | |
BarRemoveOnComplete(),
|
| 126 | |
AppendDecorators(decor.Percentage()),
|
|
125 |
mpb.BarRemoveOnComplete(),
|
|
126 |
mpb.AppendDecorators(decor.Percentage()),
|
| 127 | 127 |
)
|
| 128 | 128 |
|
| 129 | 129 |
for i := 0; i < total; i++ {
|
|
| 143 | 143 |
var buf bytes.Buffer
|
| 144 | 144 |
customFormat := "╢▌▌░╟"
|
| 145 | 145 |
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())
|
| 148 | 148 |
|
| 149 | 149 |
for i := 0; i < total; i++ {
|
| 150 | 150 |
bar.Increment()
|
|
| 168 | 168 |
|
| 169 | 169 |
func TestBarPanicBeforeComplete(t *testing.T) {
|
| 170 | 170 |
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),
|
| 175 | 175 |
)
|
| 176 | 176 |
|
| 177 | 177 |
total := 100
|
| 178 | 178 |
panicMsg := "Upps!!!"
|
| 179 | 179 |
var pCount uint32
|
| 180 | 180 |
bar := p.AddBar(int64(total),
|
| 181 | |
PrependDecorators(panicDecorator(panicMsg,
|
|
181 |
mpb.PrependDecorators(panicDecorator(panicMsg,
|
| 182 | 182 |
func(st decor.Statistics) bool {
|
| 183 | 183 |
if st.Current >= 42 {
|
| 184 | 184 |
atomic.AddUint32(&pCount, 1)
|
|
| 208 | 208 |
|
| 209 | 209 |
func TestBarPanicAfterComplete(t *testing.T) {
|
| 210 | 210 |
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),
|
| 215 | 215 |
)
|
| 216 | 216 |
|
| 217 | 217 |
total := 100
|
| 218 | 218 |
panicMsg := "Upps!!!"
|
| 219 | 219 |
var pCount uint32
|
| 220 | 220 |
bar := p.AddBar(int64(total),
|
| 221 | |
PrependDecorators(panicDecorator(panicMsg,
|
|
221 |
mpb.PrependDecorators(panicDecorator(panicMsg,
|
| 222 | 222 |
func(st decor.Statistics) bool {
|
| 223 | 223 |
if st.Completed {
|
| 224 | 224 |
atomic.AddUint32(&pCount, 1)
|