Skip to content

Commit

Permalink
Add test coverage for CowStr impl Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten committed Dec 10, 2023
1 parent d4e3d8a commit 804df46
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/tests/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,59 @@ mod cow_str {
);
}

#[test]
fn impl_clone_boxed_long() {
let s = "this string won't fit in a box".to_owned();
let s: CowStr = s.into();
if let CowStr::Boxed(_) = s {
} else {
panic!("Expected Boxed case");
}

let s2 = s.clone();
assert_eq!(s.deref(), s2.deref());

if let CowStr::Boxed(_) = s2 {
} else {
panic!("Expected Boxed clone");
}
}

#[test]
fn impl_clone_borrowed() {
let s = "this long string is borrowed";
let s: CowStr = s.into();
if let CowStr::Borrowed(_) = s {
} else {
panic!("Expected Borrowed case");
}

let s2 = s.clone();
assert_eq!(s.deref(), s2.deref());

if let CowStr::Borrowed(_) = s2 {
} else {
panic!("Expected Borrowed clone");
}
}

#[test]
fn impl_clone_inlined() {
let s: CowStr = 's'.into();
if let CowStr::Inlined(_) = s {
} else {
panic!("Expected Inlined case");
}

let s2 = s.clone();
assert_eq!(s.deref(), s2.deref());

if let CowStr::Inlined(_) = s2 {
} else {
panic!("Expected Inlined clone");
}
}

#[test]
fn impl_hash() {
use std::{
Expand Down

0 comments on commit 804df46

Please sign in to comment.