Codebase list golang-github-vbauerster-mpb / 4674919
refactoring: bar_test Vladimir Bauer 5 years ago
1 changed file(s) with 24 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
6060
6161 total := 100
6262 till := 30
63 refillRune, _ := utf8.DecodeLastRuneInString(mpb.BarDefaultStyle)
64
65 bar := p.AddBar(int64(total), mpb.BarFillerTrim())
63 refiller := "+"
64
65 bar := p.Add(int64(total), mpb.NewBarFiller(mpb.BarStyle().Refiller(refiller)), mpb.BarFillerTrim())
6666
6767 bar.SetRefill(int64(till))
6868 bar.IncrBy(till)
7575 p.Wait()
7676
7777 wantBar := fmt.Sprintf("[%s%s]",
78 strings.Repeat(string(refillRune), till-1),
78 strings.Repeat(refiller, till-1),
7979 strings.Repeat("=", total-till-1),
8080 )
8181
142142 func TestBarStyle(t *testing.T) {
143143 var buf bytes.Buffer
144144 customFormat := "╢▌▌░╟"
145 runes := []rune(customFormat)
145146 total := 80
146147 p := mpb.New(mpb.WithWidth(total), mpb.WithOutput(&buf))
147 bar := p.Add(int64(total), mpb.NewBarFiller(customFormat), mpb.BarFillerTrim())
148
149 for i := 0; i < total; i++ {
150 bar.Increment()
151 time.Sleep(10 * time.Millisecond)
152 }
153
154 p.Wait()
155
156 runes := []rune(customFormat)
157 wantBar := fmt.Sprintf("%s%s%s",
148 bs := mpb.BarStyle()
149 bs.Lbound(string(runes[0]))
150 bs.Filler(string(runes[1]))
151 bs.Tip(string(runes[2]))
152 bs.Padding(string(runes[3]))
153 bs.Rbound(string(runes[4]))
154 bar := p.Add(int64(total), mpb.NewBarFiller(bs), mpb.BarFillerTrim())
155
156 for i := 0; i < total; i++ {
157 bar.Increment()
158 time.Sleep(10 * time.Millisecond)
159 }
160
161 p.Wait()
162
163 wantBar := fmt.Sprintf("%s%s%s%s",
158164 string(runes[0]),
159 strings.Repeat(string(runes[1]), total-2),
160 string(runes[len(runes)-1]),
165 strings.Repeat(string(runes[1]), total-3),
166 string(runes[2]),
167 string(runes[4]),
161168 )
162169 got := string(getLastLine(buf.Bytes()))
163170