mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
improve tests for version parser (#696)
The high level goal here is to improve the tests for the version parser. Namely, we now check not just that version strings parse successfully, but that they parse to the expected result. We also do a few other cleanups. Most notably, `Version` is now an opaque type so that we can more easily change its representation going forward. Reviewing commit-by-commit is suggested. :-)
This commit is contained in:
parent
6f90edda78
commit
aa9f47bbde
9 changed files with 968 additions and 646 deletions
|
@ -977,30 +977,11 @@ mod tests {
|
|||
[
|
||||
VersionSpecifier::new(
|
||||
Operator::GreaterThanEqual,
|
||||
Version {
|
||||
epoch: 0,
|
||||
release: vec![2, 8, 1],
|
||||
pre: None,
|
||||
post: None,
|
||||
dev: None,
|
||||
local: None,
|
||||
},
|
||||
Version::new([2, 8, 1]),
|
||||
false,
|
||||
)
|
||||
.unwrap(),
|
||||
VersionSpecifier::new(
|
||||
Operator::Equal,
|
||||
Version {
|
||||
epoch: 0,
|
||||
release: vec![2, 8],
|
||||
pre: None,
|
||||
post: None,
|
||||
dev: None,
|
||||
local: None,
|
||||
},
|
||||
true,
|
||||
)
|
||||
.unwrap(),
|
||||
VersionSpecifier::new(Operator::Equal, Version::new([2, 8]), true).unwrap(),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
|
|
|
@ -715,14 +715,14 @@ impl MarkerExpression {
|
|||
///
|
||||
/// # fn main() -> Result<(), Pep508Error> {
|
||||
/// let marker_tree = MarkerTree::from_str(r#"("linux" in sys_platform) and extra == 'day'"#)?;
|
||||
/// let versions: Vec<Version> = (8..12).map(|minor| Version::from_release(vec![3, minor])).collect();
|
||||
/// let versions: Vec<Version> = (8..12).map(|minor| Version::new([3, minor])).collect();
|
||||
/// assert!(marker_tree.evaluate_extras_and_python_version(&["day".to_string()].into(), &versions));
|
||||
/// assert!(!marker_tree.evaluate_extras_and_python_version(&["night".to_string()].into(), &versions));
|
||||
///
|
||||
/// let marker_tree = MarkerTree::from_str(r#"extra == 'day' and python_version < '3.11' and '3.10' <= python_version"#)?;
|
||||
/// assert!(!marker_tree.evaluate_extras_and_python_version(&["day".to_string()].into(), &vec![Version::from_release(vec![3, 9])]));
|
||||
/// assert!(marker_tree.evaluate_extras_and_python_version(&["day".to_string()].into(), &vec![Version::from_release(vec![3, 10])]));
|
||||
/// assert!(!marker_tree.evaluate_extras_and_python_version(&["day".to_string()].into(), &vec![Version::from_release(vec![3, 11])]));
|
||||
/// assert!(!marker_tree.evaluate_extras_and_python_version(&["day".to_string()].into(), &vec![Version::new([3, 9])]));
|
||||
/// assert!(marker_tree.evaluate_extras_and_python_version(&["day".to_string()].into(), &vec![Version::new([3, 10])]));
|
||||
/// assert!(!marker_tree.evaluate_extras_and_python_version(&["day".to_string()].into(), &vec![Version::new([3, 11])]));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
|
@ -1556,7 +1556,7 @@ mod test {
|
|||
fn test_marker_environment_from_json() {
|
||||
let _env: MarkerEnvironment = serde_json::from_str(
|
||||
r##"{
|
||||
"implementation_name": "cpython",
|
||||
"implementation_name": "cpython",
|
||||
"implementation_version": "3.7.13",
|
||||
"os_name": "posix",
|
||||
"platform_machine": "x86_64",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue