Fix multiaddr::util::BytesWriter. (#1068)

The current implementation does not properly reserve enough space for
`Write::write_all` to succeed. The property test has been improved to
trigger that issue.
This commit is contained in:
Toralf Wittner
2019-04-18 14:28:47 +02:00
committed by GitHub
parent ca58f8029c
commit 5a465b7f50
2 changed files with 10 additions and 23 deletions

View File

@@ -34,10 +34,14 @@ fn to_from_str_identity() {
#[test]
fn byteswriter() {
fn prop(a: Ma, p: Proto) -> bool {
a.0.with(p.clone().0).pop() == Some(p.0)
fn prop(a: Ma, b: Ma) -> bool {
let mut x = a.0.clone();
for p in b.0.iter() {
x = x.with(p)
}
x.iter().zip(a.0.iter().chain(b.0.iter())).all(|(x, y)| x == y)
}
QuickCheck::new().quickcheck(prop as fn(Ma, Proto) -> bool)
QuickCheck::new().quickcheck(prop as fn(Ma, Ma) -> bool)
}
#[test]