1
- import { describe , expect , test } from 'vitest'
1
+ import { describe , expect , it } from 'vitest'
2
2
import { sprintf } from './debug'
3
3
4
4
describe ( 'debug/sprintf' , ( ) => {
5
- test ( ' %s', ( ) => {
5
+ it ( 'formats strings with %s', ( ) => {
6
6
expect ( sprintf ( '%s' , 'foo' ) ) . toBe ( 'foo' )
7
7
expect ( sprintf ( '%s' , 1 ) ) . toBe ( '1' )
8
8
expect ( sprintf ( '%s' , true ) ) . toBe ( 'true' )
@@ -11,7 +11,31 @@ describe('debug/sprintf', () => {
11
11
expect ( sprintf ( '%s' , { } ) ) . toBe ( '[object Object]' )
12
12
expect ( sprintf ( '%s' , [ ] ) ) . toBe ( '' )
13
13
} )
14
- test ( '%O' , ( ) => {
14
+ it ( 'formats integers with %d' , ( ) => {
15
+ expect ( sprintf ( '%d' , 1 ) ) . toBe ( '1' )
16
+ expect ( sprintf ( '%d' , 1.5 ) ) . toBe ( '1.5' )
17
+ expect ( sprintf ( '%d' , '1' ) ) . toBe ( '1' )
18
+ expect ( sprintf ( '%d' , '1.5' ) ) . toBe ( '1.5' )
19
+ expect ( sprintf ( '%d' , true ) ) . toBe ( 'true' )
20
+ expect ( sprintf ( '%d' , false ) ) . toBe ( 'false' )
21
+ expect ( sprintf ( '%d' , null ) ) . toBe ( 'null' )
22
+ expect ( sprintf ( '%d' , undefined ) ) . toBe ( 'undefined' )
23
+ expect ( sprintf ( '%d' , { } ) ) . toBe ( '[object Object]' )
24
+ expect ( sprintf ( '%d' , [ ] ) ) . toBe ( '' )
25
+ } )
26
+ it ( 'formats floats with %f' , ( ) => {
27
+ expect ( sprintf ( '%f' , 1 ) ) . toBe ( '1' )
28
+ expect ( sprintf ( '%f' , 1.5 ) ) . toBe ( '1.5' )
29
+ expect ( sprintf ( '%f' , '1' ) ) . toBe ( '1' )
30
+ expect ( sprintf ( '%f' , '1.5' ) ) . toBe ( '1.5' )
31
+ expect ( sprintf ( '%f' , true ) ) . toBe ( 'true' )
32
+ expect ( sprintf ( '%f' , false ) ) . toBe ( 'false' )
33
+ expect ( sprintf ( '%f' , null ) ) . toBe ( 'null' )
34
+ expect ( sprintf ( '%f' , undefined ) ) . toBe ( 'undefined' )
35
+ expect ( sprintf ( '%f' , { } ) ) . toBe ( '[object Object]' )
36
+ expect ( sprintf ( '%f' , [ ] ) ) . toBe ( '' )
37
+ } )
38
+ it ( 'formats objects with %O' , ( ) => {
15
39
expect ( sprintf ( '%O' , 'foo' ) ) . toBe ( '"foo"' )
16
40
expect ( sprintf ( '%O' , 1 ) ) . toBe ( '1' )
17
41
expect ( sprintf ( '%O' , true ) ) . toBe ( 'true' )
@@ -21,12 +45,16 @@ describe('debug/sprintf', () => {
21
45
expect ( sprintf ( '%O' , [ ] ) ) . toBe ( '[]' )
22
46
expect ( sprintf ( '%O' , { hello : 'world' } ) ) . toBe ( '{hello:"world"}' )
23
47
} )
24
- test ( 'All together now ', ( ) => {
48
+ it ( 'formats multiple arguments ', ( ) => {
25
49
expect ( sprintf ( '%s %O' , 'foo' , { hello : 'world' } ) ) . toBe (
26
50
'foo {hello:"world"}'
27
51
)
28
52
expect ( sprintf ( '%O %s' , { hello : 'world' } , 'foo' ) ) . toBe (
29
53
'{hello:"world"} foo'
30
54
)
31
55
} )
56
+ it ( 'supports mismatching numbers of arguments and placeholders' , ( ) => {
57
+ expect ( sprintf ( '%s %s' , 'foo' ) ) . toBe ( 'foo undefined' )
58
+ expect ( sprintf ( '%s %s' , 'foo' , 'bar' , 'baz' ) ) . toBe ( 'foo bar' )
59
+ } )
32
60
} )
0 commit comments