|
1 | 1 | use std::borrow::Cow;
|
2 | 2 | use std::collections::TryReserveError::*;
|
3 | 3 | use std::mem::size_of;
|
| 4 | +use std::ops::Bound::*; |
4 | 5 |
|
5 | 6 | pub trait IntoCow<'a, B: ?Sized>
|
6 | 7 | where
|
@@ -463,6 +464,20 @@ fn test_drain() {
|
463 | 464 | assert_eq!(t, "");
|
464 | 465 | }
|
465 | 466 |
|
| 467 | +#[test] |
| 468 | +#[should_panic] |
| 469 | +fn test_drain_start_overflow() { |
| 470 | + let mut s = String::from("abc"); |
| 471 | + s.drain((Excluded(usize::MAX), Included(0))); |
| 472 | +} |
| 473 | + |
| 474 | +#[test] |
| 475 | +#[should_panic] |
| 476 | +fn test_drain_end_overflow() { |
| 477 | + let mut s = String::from("abc"); |
| 478 | + s.drain((Included(0), Included(usize::MAX))); |
| 479 | +} |
| 480 | + |
466 | 481 | #[test]
|
467 | 482 | fn test_replace_range() {
|
468 | 483 | let mut s = "Hello, world!".to_owned();
|
@@ -500,6 +515,20 @@ fn test_replace_range_inclusive_out_of_bounds() {
|
500 | 515 | s.replace_range(5..=5, "789");
|
501 | 516 | }
|
502 | 517 |
|
| 518 | +#[test] |
| 519 | +#[should_panic] |
| 520 | +fn test_replace_range_start_overflow() { |
| 521 | + let mut s = String::from("123"); |
| 522 | + s.replace_range((Excluded(usize::MAX), Included(0)), ""); |
| 523 | +} |
| 524 | + |
| 525 | +#[test] |
| 526 | +#[should_panic] |
| 527 | +fn test_replace_range_end_overflow() { |
| 528 | + let mut s = String::from("456"); |
| 529 | + s.replace_range((Included(0), Included(usize::MAX)), ""); |
| 530 | +} |
| 531 | + |
503 | 532 | #[test]
|
504 | 533 | fn test_replace_range_empty() {
|
505 | 534 | let mut s = String::from("12345");
|
|
0 commit comments