Skip to content

Commit b2111b6

Browse files
committed
impl: fix cow partialeq impl
Twas a silly mistake. One of the impls was comparing against itself, which is obviously wrong. We fix it here and add a regression test. We should probably add tests for other impls as well. Fixes #82
1 parent e9d337d commit b2111b6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎src/impls.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ macro_rules! impl_partial_eq_cow {
3333
#[inline]
3434
fn eq(&self, other: &$lhs) -> bool {
3535
let this: &[u8] = (&**other).as_ref();
36-
PartialEq::eq(this, other.as_bytes())
36+
PartialEq::eq(this, self.as_bytes())
3737
}
3838
}
3939
};
@@ -967,3 +967,18 @@ fn test_debug() {
967967
B(&format!("{:?}", b"\xFF\xEF\xBF\xBD\xFF".as_bstr())).as_bstr(),
968968
);
969969
}
970+
971+
// See: https://github.com/BurntSushi/bstr/issues/82
972+
#[test]
973+
fn test_cows_regression() {
974+
use crate::ByteSlice;
975+
use std::borrow::Cow;
976+
977+
let c1 = Cow::from(b"hello bstr".as_bstr());
978+
let c2 = b"goodbye bstr".as_bstr();
979+
assert_ne!(c1, c2);
980+
981+
let c3 = Cow::from("hello str");
982+
let c4 = "goodbye str";
983+
assert_ne!(c3, c4);
984+
}

0 commit comments

Comments
 (0)