X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=library%2Falloc%2Ftests%2Fstring.rs;h=7ba1c2c611686c8a128f66a448fdc29266e6e7cf;hb=fb9bb2b5ca517d85e1041ea9f80d06f48054624c;hp=f7f78046d089b09479a2c7067c06e7de70115d76;hpb=4f0c245429a0a42ea652b85a5390203bd6a12bbc;p=rust.git diff --git a/library/alloc/tests/string.rs b/library/alloc/tests/string.rs index f7f78046d08..7ba1c2c6116 100644 --- a/library/alloc/tests/string.rs +++ b/library/alloc/tests/string.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; use std::collections::TryReserveError::*; use std::mem::size_of; +use std::ops::Bound::*; pub trait IntoCow<'a, B: ?Sized> where @@ -467,6 +468,20 @@ fn test_drain() { 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(); @@ -504,6 +519,20 @@ fn test_replace_range_inclusive_out_of_bounds() { 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");