Improve formatting of incompatible terms when there are two items (#866)

This commit is contained in:
Zanie Blue 2024-01-10 14:36:54 -06:00 committed by GitHub
parent 93d3093a2a
commit 845ba6801d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View file

@ -1542,7 +1542,7 @@ fn requires_transitive_prerelease_and_stable_dependency_many_versions() -> Resul
And because a==1.0.0 depends on c>=2.0.0b1 and there are no versions of a that satisfy any of:
a<1.0.0
a>1.0.0
we can conclude that b*, a* are incompatible.
we can conclude that b* and a* are incompatible.
And because root depends on b and root depends on a, we can conclude that the requirements are unsatisfiable.
hint: c was requested with a pre-release marker (e.g., c>=2.0.0b1), but pre-releases weren't enabled (try: `--prerelease=allow`)
@ -2151,7 +2151,7 @@ fn requires_transitive_incompatible_with_transitive() -> Result<()> {
And because a==1.0.0 depends on c==1.0.0 and there are no versions of a that satisfy any of:
a<1.0.0
a>1.0.0
we can conclude that a*, b* are incompatible.
we can conclude that a* and b* are incompatible.
And because root depends on b and root depends on a, we can conclude that the requirements are unsatisfiable.
"###);
});

View file

@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::cmp::Ordering;
use std::ops::Bound;
use derivative::Derivative;
@ -154,11 +155,25 @@ impl ReportFormatter<PubGrubPackage, Range<PubGrubVersion>> for PubGrubReportFor
&External::FromDependencyOf((*p2).clone(), r2.clone(), (*p1).clone(), r1.clone()),
),
slice => {
let mut result = String::new();
let str_terms: Vec<_> = slice
.iter()
.map(|(p, t)| format!("{}", PackageTerm::new(p, t)))
.collect();
str_terms.join(", ") + " are incompatible"
for (index, term) in str_terms.iter().enumerate() {
result.push_str(term);
match str_terms.len().cmp(&2) {
Ordering::Equal if index == 0 => {
result.push_str(" and ");
}
Ordering::Greater if index + 1 < str_terms.len() => {
result.push_str(", ");
}
_ => (),
}
}
result.push_str(" are incompatible");
result
}
}
}