use std::borrow::Cow;
use std::collections::TryReserveError::*;
use std::mem::size_of;
+use std::ops::Bound::*;
pub trait IntoCow<'a, B: ?Sized>
where
#[test]
fn test_split_off_ascii() {
let mut ab = String::from("ABCD");
+ let orig_capacity = ab.capacity();
let cd = ab.split_off(2);
assert_eq!(ab, "AB");
assert_eq!(cd, "CD");
+ assert_eq!(ab.capacity(), orig_capacity);
}
#[test]
fn test_split_off_unicode() {
let mut nihon = String::from("日本語");
+ let orig_capacity = nihon.capacity();
let go = nihon.split_off("日本".len());
assert_eq!(nihon, "日本");
assert_eq!(go, "語");
+ assert_eq!(nihon.capacity(), orig_capacity);
}
#[test]
assert_eq!(t, "");
}
+#[test]
+#[should_panic]
+fn test_drain_start_overflow() {
+ let mut s = String::from("abc");
+ s.drain((Excluded(usize::MAX), Included(0)));
+}
+
+#[test]
+#[should_panic]
+fn test_drain_end_overflow() {
+ let mut s = String::from("abc");
+ s.drain((Included(0), Included(usize::MAX)));
+}
+
#[test]
fn test_replace_range() {
let mut s = "Hello, world!".to_owned();
s.replace_range(5..=5, "789");
}
+#[test]
+#[should_panic]
+fn test_replace_range_start_overflow() {
+ let mut s = String::from("123");
+ s.replace_range((Excluded(usize::MAX), Included(0)), "");
+}
+
+#[test]
+#[should_panic]
+fn test_replace_range_end_overflow() {
+ let mut s = String::from("456");
+ s.replace_range((Included(0), Included(usize::MAX)), "");
+}
+
#[test]
fn test_replace_range_empty() {
let mut s = String::from("12345");