support atoms with wildcard versions

This commit is contained in:
John Turner
2025-10-25 01:27:42 -04:00
parent 680ead0504
commit f854e97577

View File

@@ -28,7 +28,10 @@ pub fn version_operator<'a>() -> impl Parser<&'a str, Output = VersionOperator>
}
pub fn version_number<'a>() -> impl Parser<&'a str, Output = VersionNumber> {
numeric1().map(|output: &str| VersionNumber(output.to_string()))
numeric1()
.followed_by(opt(tag("*")))
.recognize()
.map(|output: &str| VersionNumber(output.to_string()))
}
pub fn version_suffix_kind<'a>() -> impl Parser<&'a str, Output = VersionSuffixKind> {
@@ -218,7 +221,15 @@ pub fn atom<'a>() -> impl Parser<&'a str, Output = Atom> {
},
)
.verify_output(|atom| match (&atom.version_operator, &atom.version) {
(Some(_), Some(_)) => true,
(Some(VersionOperator::Eq), Some(_)) => true,
(Some(_), Some(version))
if !version
.numbers()
.iter()
.any(|number| number.get().contains("*")) =>
{
true
}
(None, None) => true,
_ => false,
})
@@ -323,4 +334,18 @@ mod test {
atom().check_finished(it).unwrap();
}
#[test]
fn test_atom_with_star_in_version() {
let it = InputIter::new("=foo/bar-1.2*");
atom().check_finished(it).unwrap();
}
#[test]
fn test_atom_with_star_in_version_without_eq_version_operator() {
let it = InputIter::new(">=foo/bar-1.2*");
assert!(atom().check_finished(it).is_err());
}
}