Add additional tests to val_or_vec

This commit is contained in:
Jonas Platte 2020-05-23 18:47:11 +02:00
parent b5f436d511
commit 964aae00ff
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -234,3 +234,31 @@ where
deserialize_map,
}
}
#[cfg(test)]
mod tests {
use std::borrow::Cow;
use matches::assert_matches;
use super::ValOrVec;
#[test]
fn cow_borrowed() {
let mut x = ValOrVec::Val(Cow::Borrowed("a"));
x.push(Cow::Borrowed("b"));
x.push(Cow::Borrowed("c"));
assert_matches!(x, ValOrVec::Vec(v) if v == vec!["a", "b", "c"]);
}
#[test]
fn cow_owned() {
let mut x = ValOrVec::Val(Cow::from("a".to_owned()));
x.push(Cow::from("b".to_owned()));
x.push(Cow::from("c".to_owned()));
assert_matches!(
x,
ValOrVec::Vec(v) if v == vec!["a".to_owned(), "b".to_owned(), "c".to_owned()]
);
}
}