Skip to content

Commit

Permalink
Add tests for Cow::from for strings, vectors and slices
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Feb 3, 2016
1 parent f30f569 commit b27b8f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libcollectionstest/str.rs
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::borrow::Cow;
use std::cmp::Ordering::{Equal, Greater, Less};
use std::str::from_utf8;

Expand Down Expand Up @@ -1267,6 +1268,16 @@ fn test_box_slice_clone() {
assert_eq!(data, data2);
}

#[test]
fn test_cow_from() {
let borrowed = "borrowed";
let owned = String::from("owned");
match (Cow::from(owned.clone()), Cow::from(borrowed)) {
(Cow::Owned(o), Cow::Borrowed(b)) => assert!(o == owned && b == borrowed),
_ => panic!("invalid `Cow::from`"),
}
}

mod pattern {
use std::str::pattern::Pattern;
use std::str::pattern::{Searcher, ReverseSearcher};
Expand Down
11 changes: 11 additions & 0 deletions src/libcollectionstest/vec.rs
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::borrow::Cow;
use std::iter::{FromIterator, repeat};
use std::mem::size_of;

Expand Down Expand Up @@ -466,6 +467,16 @@ fn test_into_iter_count() {
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
}

#[test]
fn test_cow_from() {
let borrowed: &[_] = &["borrowed", "(slice)"];
let owned = vec!["owned", "(vec)"];
match (Cow::from(owned.clone()), Cow::from(borrowed)) {
(Cow::Owned(o), Cow::Borrowed(b)) => assert!(o == owned && b == borrowed),
_ => panic!("invalid `Cow::from`"),
}
}

#[bench]
fn bench_new(b: &mut Bencher) {
b.iter(|| {
Expand Down

0 comments on commit b27b8f6

Please sign in to comment.