@@ -4567,56 +4567,49 @@ def test_match_properties_semver_invalid_values(self):
45674567 with self .assertRaises (InconclusiveMatchError ):
45684568 match_property (prop_bad , {"version" : "1.2.3" })
45694569
4570- def test_match_properties_semver_rejects_leading_zeros (self ):
4571- """Semver 2.0.0 §2: numeric identifiers MUST NOT include leading zeros."""
4570+ # Semver 2.0.0 §2: numeric identifiers MUST NOT include leading zeros.
4571+ @parameterized .expand (
4572+ [
4573+ ("major" , "01.2.3" ),
4574+ ("minor" , "1.02.3" ),
4575+ ("patch" , "1.2.03" ),
4576+ ("all_components" , "01.02.03" ),
4577+ ("two_digit_minor" , "1.07.3" ),
4578+ ("triple_zero_major" , "001.2.3" ),
4579+ ]
4580+ )
4581+ def test_match_properties_semver_rejects_leading_zero_override_value (
4582+ self , _name , bad_value
4583+ ):
45724584 prop = self .property (key = "version" , value = "1.2.3" , operator = "semver_eq" )
4573-
4574- # Leading zero in any numeric component is invalid
4575- for bad_value in [
4576- "01.2.3" ,
4577- "1.02.3" ,
4578- "1.2.03" ,
4579- "01.02.03" ,
4580- "1.07.3" ,
4581- "001.2.3" ,
4582- ]:
4583- with self .assertRaises (InconclusiveMatchError ):
4584- match_property (prop , {"version" : bad_value })
4585-
4586- # A literal "0" component is fine
4587- prop_zero = self .property (key = "version" , value = "0.1.0" , operator = "semver_eq" )
4588- self .assertTrue (match_property (prop_zero , {"version" : "0.1.0" }))
4589-
4590- prop_zero_patch = self .property (
4591- key = "version" , value = "1.0.0" , operator = "semver_eq"
4592- )
4593- self .assertTrue (match_property (prop_zero_patch , {"version" : "1.0.0" }))
4594-
4595- # Leading zeros in the flag value also raise (flag values are also validated)
4596- prop_bad_flag = self .property (
4597- key = "version" , value = "01.2.3" , operator = "semver_gt"
4598- )
4599- with self .assertRaises (InconclusiveMatchError ):
4600- match_property (prop_bad_flag , {"version" : "2.0.0" })
4601-
4602- # Range operators reject leading-zero flag values
4603- prop_caret = self .property (
4604- key = "version" , value = "1.07.0" , operator = "semver_caret"
4605- )
46064585 with self .assertRaises (InconclusiveMatchError ):
4607- match_property (prop_caret , {"version" : "1.2.0" })
4586+ match_property (prop , {"version" : bad_value })
46084587
4609- prop_tilde = self .property (
4610- key = "version" , value = "1.07.0" , operator = "semver_tilde"
4611- )
4612- with self .assertRaises (InconclusiveMatchError ):
4613- match_property (prop_tilde , {"version" : "1.2.0" })
4588+ @parameterized .expand (
4589+ [
4590+ ("zero_major" , "0.1.0" ),
4591+ ("zero_patch" , "1.0.0" ),
4592+ ("all_zero" , "0.0.0" ),
4593+ ]
4594+ )
4595+ def test_match_properties_semver_literal_zero_components_match (self , _name , value ):
4596+ prop = self .property (key = "version" , value = value , operator = "semver_eq" )
4597+ self .assertTrue (match_property (prop , {"version" : value }))
46144598
4615- prop_wild = self .property (
4616- key = "version" , value = "01.*" , operator = "semver_wildcard"
4617- )
4599+ @parameterized .expand (
4600+ [
4601+ ("semver_gt" , "01.2.3" ),
4602+ ("semver_caret" , "1.07.0" ),
4603+ ("semver_tilde" , "1.07.0" ),
4604+ ("semver_wildcard" , "01.*" ),
4605+ ]
4606+ )
4607+ def test_match_properties_semver_rejects_leading_zero_flag_value (
4608+ self , operator , flag_value
4609+ ):
4610+ prop = self .property (key = "version" , value = flag_value , operator = operator )
46184611 with self .assertRaises (InconclusiveMatchError ):
4619- match_property (prop_wild , {"version" : "1.2.0" })
4612+ match_property (prop , {"version" : "1.2.0" })
46204613
46214614 def test_unknown_operator (self ):
46224615 property_a = self .property (key = "key" , value = "2022-05-01" , operator = "is_unknown" )
0 commit comments