@@ -2,31 +2,43 @@ import assert from 'node:assert'
22import { describe , it } from 'node:test'
33import { prettierBytes } from './prettierBytes'
44
5- const testData = [
6- [ 2 , '2 B' ] ,
7- [ 9 , '9 B' ] ,
8- [ 25 , '25 B' ] ,
9- [ 235 , '235 B' ] ,
10- [ 2335 , '2.3 KB' ] ,
11- [ 23552 , '23 KB' ] ,
12- [ 235520 , '230 KB' ] ,
13- [ 2355520 , '2.2 MB' ] ,
14- [ 23555520 , '22 MB' ] ,
15- [ 235555520 , '225 MB' ] ,
16- [ 2355555520 , '2.2 GB' ] ,
17- [ 23555555520 , '22 GB' ] ,
18- [ 235556555520 , '219 GB' ] ,
19- [ 2355556655520 , '2.1 TB' ] ,
20- [ 23555566655520 , '21 TB' ] ,
21- [ 235555566665520 , '214 TB' ] ,
22- ] satisfies [ input : number , output : string ] [ ]
5+ const testData : [ number , string , string , string , string ] [ ] = [
6+ [ 2 , '2 B' , '2 B' , '0.0 MB' , '0.0 TB' ] ,
7+ [ 9 , '9 B' , '9 B' , '0.0 MB' , '0.0 TB' ] ,
8+ [ 25 , '25 B' , '25 B' , '0.0 MB' , '0.0 TB' ] ,
9+ [ 235 , '235 B' , '235 B' , '0.0 MB' , '0.0 TB' ] ,
10+ [ 2335 , '2.3 KB' , '2335 B' , '0.0 MB' , '0.0 TB' ] ,
11+ [ 23552 , '23 KB' , '23552 B' , '0.0 MB' , '0.0 TB' ] ,
12+ [ 235520 , '230 KB' , '235520 B' , '0.2 MB' , '0.0 TB' ] ,
13+ [ 2355520 , '2.2 MB' , '2355520 B' , '2.2 MB' , '0.0 TB' ] ,
14+ [ 23555520 , '22 MB' , '23555520 B' , '22 MB' , '0.0 TB' ] ,
15+ [ 235555520 , '225 MB' , '235555520 B' , '225 MB' , '0.0 TB' ] ,
16+ [ 2355555520 , '2.2 GB' , '2355555520 B' , '2246 MB' , '0.0 TB' ] ,
17+ [ 23555555520 , '22 GB' , '23555555520 B' , '22464 MB' , '0.0 TB' ] ,
18+ [ 235556555520 , '219 GB' , '235556555520 B' , '224644 MB' , '0.2 TB' ] ,
19+ [ 2355556655520 , '2.1 TB' , '2355556655520 B' , '2246434 MB' , '2.1 TB' ] ,
20+ [ 23555566655520 , '21 TB' , '23555566655520 B' , '22464339 MB' , '21 TB' ] ,
21+ [ 235555566665520 , '214 TB' , '235555566665520 B' , '224643294 MB' , '214 TB' ] ,
22+ ]
2323
2424describe ( 'prettierBytes' , ( ) => {
25- it ( 'should convert the specified number of bytes to a human-readable string like 236 MB' , ( ) => {
26- for ( const [ input , expected ] of testData ) {
25+ for ( const [ input , expected , expectedB , expectedMB , expectedTB ] of testData ) {
26+ it ( `should convert ${ input } to ${ expected } ` , ( ) => {
2727 assert . strictEqual ( prettierBytes ( input ) , expected )
28- }
29- } )
28+ } )
29+
30+ it ( `should convert ${ input } to ${ expectedB } ` , ( ) => {
31+ assert . strictEqual ( prettierBytes ( input , 'B' ) , expectedB )
32+ } )
33+
34+ it ( `should convert ${ input } to ${ expectedMB } ` , ( ) => {
35+ assert . strictEqual ( prettierBytes ( input , 'MB' ) , expectedMB )
36+ } )
37+
38+ it ( `should convert ${ input } to ${ expectedTB } ` , ( ) => {
39+ assert . strictEqual ( prettierBytes ( input , 'TB' ) , expectedTB )
40+ } )
41+ }
3042
3143 it ( 'throws on non-number' , ( ) => {
3244 assert . throws ( ( ) => {
0 commit comments