@@ -110,13 +110,58 @@ test('coerce tests', (t) => {
110110 [ '1.2.3/6' , '6.0.0' , { rtl : true } ] ,
111111 [ '1.2.3.4' , '2.3.4' , { rtl : true } ] ,
112112 [ '1.2.3.4xyz' , '2.3.4' , { rtl : true } ] ,
113+
114+ [ '1-rc.5' , '1.0.0-rc.5' , { full : true } , true ] ,
115+ [ '1.2-rc.5' , '1.2.0-rc.5' , { full : true } , true ] ,
116+ [ '1.2.3-rc.5' , '1.2.3-rc.5' , { full : true } , true ] ,
117+ [ '1.2.3-rc.5/a' , '1.2.3-rc.5' , { full : true } , true ] ,
118+ [ '1.2.3.4-rc.5' , '1.2.3' , { full : true } , true ] ,
119+ [ '1.2.3.4+rev.6' , '1.2.3' , { full : true } , true ] ,
120+
121+ [ '1+rev.6' , '1.0.0+rev.6' , { full : true } , true ] ,
122+ [ '1.2+rev.6' , '1.2.0+rev.6' , { full : true } , true ] ,
123+ [ '1.2.3+rev.6' , '1.2.3+rev.6' , { full : true } , true ] ,
124+ [ '1.2.3+rev.6/a' , '1.2.3+rev.6' , { full : true } , true ] ,
125+ [ '1.2.3.4-rc.5' , '1.2.3' , { full : true } , true ] ,
126+ [ '1.2.3.4+rev.6' , '1.2.3' , { full : true } , true ] ,
127+
128+ [ '1-rc.5+rev.6' , '1.0.0-rc.5+rev.6' , { full : true } , true ] ,
129+ [ '1.2-rc.5+rev.6' , '1.2.0-rc.5+rev.6' , { full : true } , true ] ,
130+ [ '1.2.3-rc.5+rev.6' , '1.2.3-rc.5+rev.6' , { full : true } , true ] ,
131+ [ '1.2.3-rc.5+rev.6/a' , '1.2.3-rc.5+rev.6' , { full : true } , true ] ,
132+
133+ [ '1.2-rc.5+rev.6' , '1.2.0-rc.5+rev.6' , { rtl : true , full : true } , true ] ,
134+ [ '1.2.3-rc.5+rev.6' , '1.2.3-rc.5+rev.6' , { rtl : true , full : true } , true ] ,
135+ [ '1.2.3.4-rc.5+rev.6' , '2.3.4-rc.5+rev.6' , { rtl : true , full : true } , true ] ,
136+ [ '1.2.3.4-rc.5' , '2.3.4-rc.5' , { rtl : true , full : true } , true ] ,
137+ [ '1.2.3.4+rev.6' , '2.3.4+rev.6' , { rtl : true , full : true } , true ] ,
138+ [ '1.2.3.4-rc.5+rev.6/7' , '7.0.0' , { rtl : true , full : true } , true ] ,
139+ [ '1.2.3.4-rc/7.5+rev.6' , '7.5.0+rev.6' , { rtl : true , full : true } , true ] ,
140+ [ '1.2.3.4/7-rc.5+rev.6' , '7.0.0-rc.5+rev.6' , { rtl : true , full : true } , true ] ,
113141 ]
114- coerceToValid . forEach ( ( [ input , expected , options ] ) => {
115- const msg = `coerce(${ input } ) should become ${ expected } `
116- t . same ( ( coerce ( input , options ) || { } ) . version , expected , msg )
142+ coerceToValid . forEach ( ( [ input , expected , options , shouldParse ] ) => {
143+ const coerceExpression = `coerce(${ input } , ${ JSON . stringify ( options ) } )`
144+ const coercedVersion = coerce ( input , options ) || { }
145+ let expectedText = expected
146+
147+ if ( shouldParse ) {
148+ const expectedVersion = parse ( expected )
149+ expectedText = expectedVersion . version
150+ t . equal (
151+ expectedVersion . compare ( coercedVersion ) ,
152+ 0 ,
153+ `${ coerceExpression } should be equal to ${ expectedVersion } `
154+ )
155+ }
156+ t . same (
157+ coercedVersion . version ,
158+ expectedText ,
159+ `${ coerceExpression } should become ${ expectedText } `
160+ )
117161 } )
118162
119163 t . same ( valid ( coerce ( '42.6.7.9.3-alpha' ) ) , '42.6.7' )
164+ t . same ( valid ( coerce ( '42.6.7-alpha+rev.1' , { full : true } ) ) , '42.6.7-alpha' )
120165 t . same ( valid ( coerce ( 'v2' ) ) , '2.0.0' )
121166
122167 t . end ( )
0 commit comments