Skip to content

Commit 84ac190

Browse files
committed
refactor(test): Turn WildStr panic into compiler error
1 parent 1b76a90 commit 84ac190

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,12 @@ pub(crate) fn match_contains(
343343
let expected = normalize_expected(expected, redactions);
344344
let actual = normalize_actual(actual, redactions);
345345
let e: Vec<_> = expected.lines().map(|line| WildStr::new(line)).collect();
346-
let a: Vec<_> = actual.lines().map(|line| WildStr::new(line)).collect();
346+
let a: Vec<_> = actual.lines().collect();
347347
if e.len() == 0 {
348348
bail!("expected length must not be zero");
349349
}
350350
for window in a.windows(e.len()) {
351-
if window == e {
351+
if e == window {
352352
return Ok(());
353353
}
354354
}
@@ -407,7 +407,6 @@ pub(crate) fn match_with_without(
407407

408408
let matches: Vec<_> = actual
409409
.lines()
410-
.map(WildStr::new)
411410
.filter(|line| with_wild.iter().all(|with| with == line))
412411
.filter(|line| !without_wild.iter().any(|without| without == line))
413412
.collect();
@@ -472,13 +471,12 @@ impl<'a> WildStr<'a> {
472471
}
473472
}
474473

475-
impl<'a> PartialEq for WildStr<'a> {
476-
fn eq(&self, other: &Self) -> bool {
477-
match (self.has_meta, other.has_meta) {
478-
(false, false) => self.line == other.line,
479-
(true, false) => meta_cmp(self.line, other.line),
480-
(false, true) => meta_cmp(other.line, self.line),
481-
(true, true) => panic!("both lines cannot have [..]"),
474+
impl PartialEq<&str> for WildStr<'_> {
475+
fn eq(&self, other: &&str) -> bool {
476+
if self.has_meta {
477+
meta_cmp(self.line, other)
478+
} else {
479+
self.line == *other
482480
}
483481
}
484482
}
@@ -666,10 +664,10 @@ mod test {
666664
("[..]", "a b"),
667665
("[..]b", "a b"),
668666
] {
669-
assert_eq!(WildStr::new(a), WildStr::new(b));
667+
assert_eq!(WildStr::new(a), b);
670668
}
671669
for (a, b) in &[("[..]b", "c"), ("b", "c"), ("b", "cb")] {
672-
assert_ne!(WildStr::new(a), WildStr::new(b));
670+
assert_ne!(WildStr::new(a), b);
673671
}
674672
}
675673

0 commit comments

Comments
 (0)