Codebase list golang-github-vbauerster-mpb / 851cead
refactoring: draw_test Vladimir Bauer 5 years ago
1 changed file(s) with 12 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
88 func TestDraw(t *testing.T) {
99 // key is termWidth
1010 testSuite := map[int][]struct {
11 style BarStyleComposer
1112 name string
12 style string
1313 total int64
1414 current int64
1515 refill int64
1616 barWidth int
1717 trim bool
18 reverse bool
1918 want string
2019 }{
2120 0: {
258257 want: "[===============================>------------------------------------------------------------------]",
259258 },
260259 {
260 style: BarStyle().Tip("<").Reverse(),
261261 name: "t,c{100,33}trim,rev",
262262 total: 100,
263263 current: 33,
264264 trim: true,
265 reverse: true,
266265 want: "[------------------------------------------------------------------<===============================]",
267266 },
268267 {
281280 want: "[+++++++++++++++++++++++++++++++>------------------------------------------------------------------]",
282281 },
283282 {
283 style: BarStyle().Tip("<").Reverse(),
284284 name: "t,c,r{100,33,33}trim,rev",
285285 total: 100,
286286 current: 33,
287287 refill: 33,
288288 trim: true,
289 reverse: true,
290289 want: "[------------------------------------------------------------------<+++++++++++++++++++++++++++++++]",
291290 },
292291 {
305304 want: "[++++++++++++++++++++++++++++++++======>-----------------------------------------------------------]",
306305 },
307306 {
307 style: BarStyle().Tip("<").Reverse(),
308308 name: "t,c,r{100,40,33},rev",
309309 total: 100,
310310 current: 40,
311311 refill: 33,
312 reverse: true,
313312 want: " [----------------------------------------------------------<=====++++++++++++++++++++++++++++++++] ",
314313 },
315314 {
315 style: BarStyle().Tip("<").Reverse(),
316316 name: "t,c,r{100,40,33}trim,rev",
317317 total: 100,
318318 current: 40,
319319 refill: 33,
320320 trim: true,
321 reverse: true,
322321 want: "[-----------------------------------------------------------<======++++++++++++++++++++++++++++++++]",
323322 },
324323 {
324 style: BarStyle().Lbound("[").Filler("=").Tip("の").Padding("-").Rbound("]"),
325325 name: "[=の-] t,c{100,1}",
326 style: "[=の-]",
327326 total: 100,
328327 current: 1,
329328 want: " [の---------------------------------------------------------------------------------------------…] ",
345344 var tmpBuf bytes.Buffer
346345 for tw, cases := range testSuite {
347346 for _, tc := range cases {
348 s := newTestState(tc.style, tc.reverse)
347 if tc.style == nil {
348 tc.style = BarStyle()
349 }
350 s := newTestState(NewBarFiller(tc.style))
349351 s.reqWidth = tc.barWidth
350352 s.total = tc.total
351353 s.current = tc.current
366368 }
367369 }
368370
369 func newTestState(style string, rev bool) *bState {
371 func newTestState(filler BarFiller) *bState {
370372 s := &bState{
371 filler: NewBarFillerPick(style, rev),
373 filler: filler,
372374 bufP: new(bytes.Buffer),
373375 bufB: new(bytes.Buffer),
374376 bufA: new(bytes.Buffer),