diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-09-04 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-09-04 00:00:00 +0000 |
| commit | f8cfb2f5ad847b871399dfef9b8b8ff4e84a75cb (patch) | |
| tree | 27fc68092fa517bc10b36d4f1ce485bf3e15e6df /library/alloc/tests/string.rs | |
| parent | d98bac4e4e3cc87ec9b848c173d570ebe2aa30b6 (diff) | |
| download | rust-f8cfb2f5ad847b871399dfef9b8b8ff4e84a75cb.tar.gz rust-f8cfb2f5ad847b871399dfef9b8b8ff4e84a75cb.zip | |
Add tests for overflow in String / VecDeque operations using ranges
Diffstat (limited to 'library/alloc/tests/string.rs')
| -rw-r--r-- | library/alloc/tests/string.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/library/alloc/tests/string.rs b/library/alloc/tests/string.rs index d38655af78c..e2eb042f791 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 @@ -464,6 +465,20 @@ fn test_drain() { } #[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(7..12, "世界"); @@ -501,6 +516,20 @@ fn test_replace_range_inclusive_out_of_bounds() { } #[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"); s.replace_range(1..2, ""); |
