@@ -125,14 +125,12 @@ func TestSpec_PublicAPI_ParseVersion(t *testing.T) {
125125 })
126126
127127 t .Run ("Pre field is prerelease identifier without leading hyphen" , func (t * testing.T ) {
128- // Spec: Pre string // Prerelease identifier without leading hyphen (e.g. "beta.1")
129128 ver := ParseVersion ("v1.2.3-beta.1" )
130129 require .NotNil (t , ver , "ParseVersion should return non-nil for valid prerelease semver" )
131130 assert .Equal (t , "beta.1" , ver .Pre , "Pre field should contain prerelease identifier without leading hyphen" )
132131 })
133132
134133 t .Run ("Raw field is original version string without leading v prefix" , func (t * testing.T ) {
135- // Spec: Raw string // Original version string without leading "v"
136134 ver := ParseVersion ("v1.2.3" )
137135 require .NotNil (t , ver , "ParseVersion should return non-nil for valid semver" )
138136 assert .Equal (t , "1.2.3" , ver .Raw , "Raw field should contain version string without leading v prefix" )
@@ -216,6 +214,12 @@ func TestSpec_PublicAPI_Compare(t *testing.T) {
216214 v2 : "v1.0.0" ,
217215 expected : - 1 ,
218216 },
217+ {
218+ name : "bare versions without v prefix are accepted" ,
219+ v1 : "2.0.0" ,
220+ v2 : "1.9.9" ,
221+ expected : 1 ,
222+ },
219223 }
220224
221225 for _ , tt := range tests {
@@ -226,6 +230,43 @@ func TestSpec_PublicAPI_Compare(t *testing.T) {
226230 }
227231}
228232
233+ // TestSpec_PublicAPI_IsMorePreciseVersion validates the documented behavior of
234+ // IsMorePreciseVersion as described in the semverutil README.md specification.
235+ func TestSpec_PublicAPI_IsMorePreciseVersion (t * testing.T ) {
236+ tests := []struct {
237+ name string
238+ v1 string
239+ v2 string
240+ expected bool
241+ }{
242+ {
243+ name : "more specific version sorts ahead of less specific version" ,
244+ v1 : "v4.3.0" ,
245+ v2 : "v4" ,
246+ expected : true ,
247+ },
248+ {
249+ name : "less specific version does not sort ahead of more specific version" ,
250+ v1 : "v4" ,
251+ v2 : "v4.3.0" ,
252+ expected : false ,
253+ },
254+ {
255+ name : "equal precision and equal value returns false" ,
256+ v1 : "v4.3.0" ,
257+ v2 : "v4.3.0" ,
258+ expected : false ,
259+ },
260+ }
261+
262+ for _ , tt := range tests {
263+ t .Run (tt .name , func (t * testing.T ) {
264+ result := IsMorePreciseVersion (tt .v1 , tt .v2 )
265+ assert .Equal (t , tt .expected , result , "IsMorePreciseVersion(%q, %q) mismatch" , tt .v1 , tt .v2 )
266+ })
267+ }
268+ }
269+
229270// TestSpec_PublicAPI_IsCompatible validates the documented behavior of
230271// IsCompatible as described in the semverutil README.md specification.
231272func TestSpec_PublicAPI_IsCompatible (t * testing.T ) {
@@ -259,24 +300,6 @@ func TestSpec_PublicAPI_IsCompatible(t *testing.T) {
259300 requestedVersion : "also-not-a-version" ,
260301 expected : false ,
261302 },
262- {
263- name : "empty strings are not compatible" ,
264- pinVersion : "" ,
265- requestedVersion : "" ,
266- expected : false ,
267- },
268- {
269- name : "invalid pin with valid requested is not compatible" ,
270- pinVersion : "not-a-version" ,
271- requestedVersion : "v5.0.0" ,
272- expected : false ,
273- },
274- {
275- name : "valid pin with invalid requested is not compatible" ,
276- pinVersion : "v5.0.0" ,
277- requestedVersion : "not-a-version" ,
278- expected : false ,
279- },
280303 }
281304
282305 for _ , tt := range tests {
0 commit comments