From 66d6e52b21c57da9d1207c5203bdfa635539236a Mon Sep 17 00:00:00 2001 From: John Turner Date: Sat, 25 Oct 2025 01:17:53 -0400 Subject: [PATCH] verify that atoms that have versions have a version operator (and reverse) --- src/atom/parsers.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/atom/parsers.rs b/src/atom/parsers.rs index e1954c0..f6fdd6c 100644 --- a/src/atom/parsers.rs +++ b/src/atom/parsers.rs @@ -216,6 +216,11 @@ pub fn atom<'a>() -> impl Parser<&'a str, Output = Atom> { usedeps: usedeps.unwrap_or(Vec::new()), }, ) + .verify_output(|atom| match (&atom.version_operator, &atom.version) { + (Some(_), Some(_)) => true, + (None, None) => true, + _ => false, + }) } #[cfg(test)] @@ -264,35 +269,49 @@ mod test { #[test] 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()); } #[test] 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()) } #[test] fn test_empty_slot() { - let it = InputIter::new("foo/bar-1.0.0:="); + let it = InputIter::new("foo/bar:="); atom().check_finished(it).unwrap(); } #[test] 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(); } #[test] 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()); }