| 0 | 0 |
package mpb
|
| 1 | 1 |
|
| 2 | 2 |
import (
|
| 3 | |
"reflect"
|
|
3 |
"bytes"
|
| 4 | 4 |
"testing"
|
| 5 | 5 |
)
|
| 6 | 6 |
|
|
| 11 | 11 |
total int64
|
| 12 | 12 |
current int64
|
| 13 | 13 |
barRefill *refill
|
| 14 | |
want []byte
|
|
14 |
want string
|
| 15 | 15 |
}{
|
| 16 | |
{
|
| 17 | |
termWidth: 1,
|
| 18 | |
barWidth: 100,
|
| 19 | |
want: []byte{},
|
| 20 | |
},
|
| 21 | 16 |
{
|
| 22 | 17 |
termWidth: 2,
|
| 23 | 18 |
barWidth: 100,
|
|
19 |
want: "",
|
|
20 |
},
|
|
21 |
{
|
|
22 |
termWidth: 3,
|
|
23 |
barWidth: 100,
|
| 24 | 24 |
total: 100,
|
| 25 | 25 |
current: 20,
|
| 26 | |
want: []byte("[]"),
|
|
26 |
want: "[-]",
|
|
27 |
},
|
|
28 |
{
|
|
29 |
termWidth: 5,
|
|
30 |
barWidth: 100,
|
|
31 |
total: 100,
|
|
32 |
current: 20,
|
|
33 |
want: "[>--]",
|
|
34 |
},
|
|
35 |
{
|
|
36 |
termWidth: 6,
|
|
37 |
barWidth: 100,
|
|
38 |
total: 100,
|
|
39 |
current: 20,
|
|
40 |
want: "[>---]",
|
| 27 | 41 |
},
|
| 28 | 42 |
{
|
| 29 | 43 |
termWidth: 20,
|
| 30 | 44 |
barWidth: 100,
|
| 31 | 45 |
total: 100,
|
| 32 | 46 |
current: 20,
|
| 33 | |
want: []byte("[===>--------------]"),
|
|
47 |
want: "[===>--------------]",
|
| 34 | 48 |
},
|
| 35 | 49 |
{
|
| 36 | 50 |
termWidth: 50,
|
| 37 | 51 |
barWidth: 100,
|
| 38 | 52 |
total: 100,
|
| 39 | 53 |
current: 20,
|
| 40 | |
want: []byte("[=========>--------------------------------------]"),
|
|
54 |
want: "[=========>--------------------------------------]",
|
| 41 | 55 |
},
|
| 42 | 56 |
{
|
| 43 | 57 |
termWidth: 100,
|
| 44 | 58 |
barWidth: 100,
|
| 45 | 59 |
total: 100,
|
| 46 | 60 |
current: 0,
|
| 47 | |
want: []byte("[--------------------------------------------------------------------------------------------------]"),
|
|
61 |
want: "[--------------------------------------------------------------------------------------------------]",
|
| 48 | 62 |
},
|
| 49 | 63 |
{
|
| 50 | 64 |
termWidth: 100,
|
| 51 | 65 |
barWidth: 100,
|
| 52 | 66 |
total: 100,
|
| 53 | 67 |
current: 1,
|
| 54 | |
want: []byte("[>-------------------------------------------------------------------------------------------------]"),
|
|
68 |
want: "[>-------------------------------------------------------------------------------------------------]",
|
| 55 | 69 |
},
|
| 56 | 70 |
{
|
| 57 | 71 |
termWidth: 100,
|
| 58 | 72 |
barWidth: 100,
|
| 59 | 73 |
total: 100,
|
| 60 | 74 |
current: 40,
|
| 61 | |
want: []byte("[======================================>-----------------------------------------------------------]"),
|
|
75 |
want: "[======================================>-----------------------------------------------------------]",
|
| 62 | 76 |
},
|
| 63 | 77 |
{
|
| 64 | 78 |
termWidth: 100,
|
|
| 66 | 80 |
total: 100,
|
| 67 | 81 |
current: 40,
|
| 68 | 82 |
barRefill: &refill{'+', 32},
|
| 69 | |
want: []byte("[+++++++++++++++++++++++++++++++=======>-----------------------------------------------------------]"),
|
|
83 |
want: "[+++++++++++++++++++++++++++++++=======>-----------------------------------------------------------]",
|
| 70 | 84 |
},
|
| 71 | 85 |
{
|
| 72 | 86 |
termWidth: 100,
|
| 73 | 87 |
barWidth: 100,
|
| 74 | 88 |
total: 100,
|
| 75 | 89 |
current: 99,
|
| 76 | |
want: []byte("[================================================================================================>-]"),
|
|
90 |
want: "[================================================================================================>-]",
|
| 77 | 91 |
},
|
| 78 | 92 |
{
|
| 79 | 93 |
termWidth: 100,
|
| 80 | 94 |
barWidth: 100,
|
| 81 | 95 |
total: 100,
|
| 82 | 96 |
current: 100,
|
| 83 | |
want: []byte("[==================================================================================================]"),
|
|
97 |
want: "[==================================================================================================]",
|
| 84 | 98 |
},
|
| 85 | 99 |
}
|
| 86 | 100 |
|
|
| 94 | 108 |
if test.barRefill != nil {
|
| 95 | 109 |
s.refill = test.barRefill
|
| 96 | 110 |
}
|
| 97 | |
got := draw(s, test.termWidth, prependWs, appendWs)
|
| 98 | |
if !reflect.DeepEqual(test.want, got) {
|
|
111 |
// got := draw(s, test.termWidth, prependWs, appendWs)
|
|
112 |
s.draw(test.termWidth, prependWs, appendWs)
|
|
113 |
got := s.bufB.String()
|
|
114 |
if got != test.want {
|
| 99 | 115 |
t.Errorf("Want: %q, Got: %q\n", test.want, got)
|
| 100 | 116 |
}
|
| 101 | 117 |
}
|
|
| 105 | 121 |
s := &state{
|
| 106 | 122 |
trimLeftSpace: true,
|
| 107 | 123 |
trimRightSpace: true,
|
|
124 |
bufP: new(bytes.Buffer),
|
|
125 |
bufB: new(bytes.Buffer),
|
|
126 |
bufA: new(bytes.Buffer),
|
| 108 | 127 |
}
|
| 109 | 128 |
s.updateFormat("[=>-]")
|
| 110 | 129 |
return s
|