verify that atoms that have versions have a version operator (and reverse)

This commit is contained in:
John Turner
2025-10-25 01:17:53 -04:00
parent ccf7aeb98d
commit 66d6e52b21

View File

@@ -216,6 +216,11 @@ pub fn atom<'a>() -> impl Parser<&'a str, Output = Atom> {
usedeps: usedeps.unwrap_or(Vec::new()), usedeps: usedeps.unwrap_or(Vec::new()),
}, },
) )
.verify_output(|atom| match (&atom.version_operator, &atom.version) {
(Some(_), Some(_)) => true,
(None, None) => true,
_ => false,
})
} }
#[cfg(test)] #[cfg(test)]
@@ -264,35 +269,49 @@ mod test {
#[test] #[test]
fn test_atom_with_star_in_non_empty_slot() { fn test_atom_with_star_in_non_empty_slot() {
let it = InputIter::new("foo/bar-1.0.0:*/subslot"); let it = InputIter::new("foo/bar:*/subslot");
assert!(atom().check_finished(it).is_err()); assert!(atom().check_finished(it).is_err());
} }
#[test] #[test]
fn test_invalid_usedep() { fn test_invalid_usedep() {
let it = InputIter::new("foo-bar-1.0.0:slot/sub=[!use]"); let it = InputIter::new("foo-bar:slot/sub=[!use]");
assert!(atom().check_finished(it).is_err()) assert!(atom().check_finished(it).is_err())
} }
#[test] #[test]
fn test_empty_slot() { fn test_empty_slot() {
let it = InputIter::new("foo/bar-1.0.0:="); let it = InputIter::new("foo/bar:=");
atom().check_finished(it).unwrap(); atom().check_finished(it).unwrap();
} }
#[test] #[test]
fn test_usedep_with_underscore() { fn test_usedep_with_underscore() {
let it = InputIter::new("foo/bar-1.0.0[use_dep]"); let it = InputIter::new("foo/bar[use_dep]");
atom().check_finished(it).unwrap(); atom().check_finished(it).unwrap();
} }
#[test] #[test]
fn test_version_with_uppercase_letter() { fn test_version_with_uppercase_letter() {
let it = InputIter::new("foo/bar-1.0.0V"); let it = InputIter::new("=foo/bar-1.0.0V");
assert!(atom().check_finished(it).is_err());
}
#[test]
fn test_version_with_version_operator_without_version() {
let it = InputIter::new("=foo/bar");
assert!(atom().check_finished(it).is_err());
}
#[test]
fn test_version_with_version_without_version_operator() {
let it = InputIter::new("foo/bar-1.0.0");
assert!(atom().check_finished(it).is_err()); assert!(atom().check_finished(it).is_err());
} }