@@ -139,3 +139,60 @@ Deno.test("ProgressBar() does not leak resources when immediately stopped", asyn
139139 const progressBar = new ProgressBar ( { max : 10 } ) ;
140140 await progressBar . stop ( ) ;
141141} ) ;
142+
143+ Deno . test ( "ProgressBar() handles value < 0" , async ( ) => {
144+ using _fakeTime = new FakeTime ( ) ;
145+ const { readable, writable } = new TransformStream ( ) ;
146+ const bar = new ProgressBar ( { writable, max : 2 ** 10 , value : - 1 } ) ;
147+ bar . stop ( ) . then ( ( ) => writable . close ( ) ) ;
148+
149+ const expected = [
150+ "\r\x1b[K[00:00] [--------------------------------------------------] [-0.00/1.00 KiB]" ,
151+ "\r\x1b[K[00:00] [--------------------------------------------------] [-0.00/1.00 KiB]" ,
152+ "\n" ,
153+ ] ;
154+
155+ const actual : string [ ] = [ ] ;
156+ for await ( const buffer of readable ) {
157+ actual . push ( decoder . decode ( buffer ) ) ;
158+ }
159+ assertEquals ( actual , expected ) ;
160+ } ) ;
161+
162+ Deno . test ( "ProgressBar() handles max < 0" , async ( ) => {
163+ using _fakeTime = new FakeTime ( ) ;
164+ const { readable, writable } = new TransformStream ( ) ;
165+ const bar = new ProgressBar ( { writable, max : - 1 } ) ;
166+ bar . stop ( ) . then ( ( ) => writable . close ( ) ) ;
167+
168+ const expected = [
169+ "\r\x1b[K[00:00] [--------------------------------------------------] [0.00/-0.00 KiB]" ,
170+ "\r\x1b[K[00:00] [--------------------------------------------------] [0.00/-0.00 KiB]" ,
171+ "\n" ,
172+ ] ;
173+
174+ const actual : string [ ] = [ ] ;
175+ for await ( const buffer of readable ) {
176+ actual . push ( decoder . decode ( buffer ) ) ;
177+ }
178+ assertEquals ( actual , expected ) ;
179+ } ) ;
180+
181+ Deno . test ( "ProgressBar() handles value > max" , async ( ) => {
182+ using _fakeTime = new FakeTime ( ) ;
183+ const { readable, writable } = new TransformStream ( ) ;
184+ const bar = new ProgressBar ( { writable, max : 2 ** 10 , value : 2 ** 10 + 1 } ) ;
185+ bar . stop ( ) . then ( ( ) => writable . close ( ) ) ;
186+
187+ const expected = [
188+ "\r\x1b[K[00:00] [##################################################] [1.00/1.00 KiB]" ,
189+ "\r\x1b[K[00:00] [##################################################] [1.00/1.00 KiB]" ,
190+ "\n" ,
191+ ] ;
192+
193+ const actual : string [ ] = [ ] ;
194+ for await ( const buffer of readable ) {
195+ actual . push ( decoder . decode ( buffer ) ) ;
196+ }
197+ assertEquals ( actual , expected ) ;
198+ } ) ;
0 commit comments