@@ -47,16 +47,30 @@ for (const [name, version] of [
4747 expect ( YAML . stringify ( - 0 , { version } ) ) . toBe ( '-0\n' )
4848 } )
4949
50- test ( 'float with trailing zeros' , ( ) => {
51- const doc = new YAML . Document < YAML . Scalar , false > ( 3 , { version } )
52- doc . contents . minFractionDigits = 2
53- expect ( String ( doc ) ) . toBe ( '3.00\n' )
54- } )
55- test ( 'scientific float ignores minFractionDigits' , ( ) => {
56- const doc = new YAML . Document < YAML . Scalar , false > ( 3 , { version } )
57- doc . contents . format = 'EXP'
58- doc . contents . minFractionDigits = 2
59- expect ( String ( doc ) ) . toBe ( '3e+0\n' )
50+ describe ( 'minFractionDigits' , ( ) => {
51+ for ( const [ n , exp ] of [
52+ [ 3 , '3.00\n' ] ,
53+ [ - 3 , '-3.00\n' ] ,
54+ [ 4.2 , '4.20\n' ] ,
55+ [ 4.21 , '4.21\n' ] ,
56+ [ 4.215 , '4.215\n' ] ,
57+ [ 0 , '0.00\n' ] ,
58+ [ - 0 , '-0.00\n' ] ,
59+ [ 1e32 , '1e+32\n' ] ,
60+ ] ) {
61+ test ( `number (${ n } ) with trailing zeros` , ( ) => {
62+ const doc = new YAML . Document < YAML . Scalar , false > ( n , { version } )
63+ doc . contents . minFractionDigits = 2
64+ expect ( doc . toString ( ) ) . toBe ( exp )
65+ } )
66+ }
67+
68+ test ( 'scientific float ignores minFractionDigits' , ( ) => {
69+ const doc = new YAML . Document < YAML . Scalar , false > ( 3 , { version } )
70+ doc . contents . format = 'EXP'
71+ doc . contents . minFractionDigits = 2
72+ expect ( String ( doc ) ) . toBe ( '3e+0\n' )
73+ } )
6074 } )
6175
6276 test ( 'integer with HEX format' , ( ) => {
0 commit comments