@@ -93,6 +93,23 @@ func ExampleOptionClearOnFinish() {
93
93
// Finished
94
94
}
95
95
96
+ func TestSpinnerClearOnFinish (t * testing.T ) {
97
+ buf := strings.Builder {}
98
+ bar := NewOptions (- 1 , OptionSetWidth (100 ), OptionShowCount (), OptionShowBytes (true ), OptionShowIts (), OptionClearOnFinish (), OptionSetWriter (& buf ))
99
+ bar .Reset ()
100
+ time .Sleep (1 * time .Second )
101
+ bar .Add (10 )
102
+ time .Sleep (1 * time .Second )
103
+ bar .Finish ()
104
+ result := buf .String ()
105
+ expect := "" +
106
+ "\r - (10 B, 10 B/s, 10 it/s) [1s] " +
107
+ "\r \r "
108
+ if result != expect {
109
+ t .Errorf ("Render miss-match\n Result: '%s'\n Expect: '%s'\n %+v" , result , expect , bar )
110
+ }
111
+ }
112
+
96
113
func ExampleProgressBar_Finish () {
97
114
bar := NewOptions (100 , OptionSetWidth (10 ), OptionShowCount (), OptionShowBytes (true ), OptionShowIts ())
98
115
bar .Reset ()
@@ -102,6 +119,24 @@ func ExampleProgressBar_Finish() {
102
119
// 100% |██████████| (100/100 B, 100 B/s, 100 it/s)
103
120
}
104
121
122
+ func TestSpinnerFinish (t * testing.T ) {
123
+ buf := strings.Builder {}
124
+ bar := NewOptions (- 1 , OptionSetWidth (100 ), OptionShowCount (), OptionShowBytes (true ), OptionShowIts (), OptionSetWriter (& buf ))
125
+ bar .Reset ()
126
+ time .Sleep (1 * time .Second )
127
+ bar .Add (10 )
128
+ time .Sleep (1 * time .Second )
129
+ bar .Finish ()
130
+ result := buf .String ()
131
+ expect := "" +
132
+ "\r - (10 B, 10 B/s, 10 it/s) [1s] " +
133
+ "\r \r " +
134
+ "\r | (10 B, 5 B/s, 5 it/s) [2s] "
135
+ if result != expect {
136
+ t .Errorf ("Render miss-match\n Result: '%s'\n Expect: '%s'\n %+v" , result , expect , bar )
137
+ }
138
+ }
139
+
105
140
func Example_xOutOfY () {
106
141
bar := NewOptions (100 , OptionSetPredictTime (true ))
107
142
0 commit comments