Codebase list golang-github-vbauerster-mpb / c74cf66
test update Vladimir Bauer 9 years ago
1 changed file(s) with 47 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
55 )
66
77 func TestFillBar(t *testing.T) {
8 s := newTestState(80, 60)
98 tests := []struct {
109 termWidth int
1110 barWidth int
11 total int64
12 current int64
13 barRefill *refill
1214 want []byte
1315 }{
1416 {
1517 termWidth: 1,
16 barWidth: 60,
18 barWidth: 100,
1719 want: []byte{},
1820 },
1921 {
2022 termWidth: 2,
21 barWidth: 60,
23 barWidth: 100,
24 total: 100,
25 current: 20,
2226 want: []byte("[]"),
2327 },
2428 {
25 termWidth: 4,
26 barWidth: 60,
27 want: []byte("[=>]"),
29 termWidth: 20,
30 barWidth: 100,
31 total: 100,
32 current: 20,
33 want: []byte("[==>---------------]"),
2834 },
2935 {
30 termWidth: 6,
31 barWidth: 60,
32 want: []byte("[==>-]"),
36 termWidth: 50,
37 barWidth: 100,
38 total: 100,
39 current: 20,
40 want: []byte("[========>---------------------------------------]"),
3341 },
3442 {
35 termWidth: 8,
36 barWidth: 60,
37 want: []byte("[====>-]"),
43 termWidth: 100,
44 barWidth: 100,
45 total: 100,
46 current: 40,
47 want: []byte("[======================================>-----------------------------------------------------------]"),
3848 },
3949 {
40 termWidth: 80,
41 barWidth: 60,
42 want: []byte("[===========================================>--------------]"),
50 termWidth: 100,
51 barWidth: 100,
52 total: 100,
53 current: 40,
54 barRefill: &refill{'+', 32},
55 want: []byte("[+++++++++++++++++++++++++++++++=======>-----------------------------------------------------------]"),
4356 },
4457 {
45 termWidth: 80,
46 barWidth: 62,
47 want: []byte("[============================================>---------------]"),
58 termWidth: 100,
59 barWidth: 100,
60 total: 100,
61 current: 99,
62 want: []byte("[=================================================================================================>]"),
63 },
64 {
65 termWidth: 100,
66 barWidth: 100,
67 total: 100,
68 current: 100,
69 want: []byte("[==================================================================================================]"),
4870 },
4971 }
5072
5173 for _, test := range tests {
74 s := newTestState()
5275 s.width = test.barWidth
76 s.total = test.total
77 s.current = test.current
78 if test.barRefill != nil {
79 s.refill = test.barRefill
80 }
5381 got := draw(s, test.termWidth)
5482 if !reflect.DeepEqual(test.want, got) {
5583 t.Errorf("Want: %q, Got: %q\n", test.want, got)
5785 }
5886 }
5987
60 func newTestState(total, current int64) *state {
88 func newTestState() *state {
6189 return &state{
6290 format: barFmtRunes{'[', '=', '>', '-', ']'},
63 total: total,
64 current: current,
6591 trimLeftSpace: true,
6692 trimRightSpace: true,
6793 }