|
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
|
@@ -467,6 +468,20 @@ fn test_drain() {
|
467 | 468 | assert_eq!(t, "");
|
468 | 469 | }
|
469 | 470 |
|
| 471 | +#[test] |
| 472 | +#[should_panic] |
| 473 | +fn test_drain_start_overflow() { |
| 474 | + let mut s = String::from("abc"); |
| 475 | + s.drain((Excluded(usize::MAX), Included(0))); |
| 476 | +} |
| 477 | + |
| 478 | +#[test] |
| 479 | +#[should_panic] |
| 480 | +fn test_drain_end_overflow() { |
| 481 | + let mut s = String::from("abc"); |
| 482 | + s.drain((Included(0), Included(usize::MAX))); |
| 483 | +} |
| 484 | + |
470 | 485 | #[test]
|
471 | 486 | fn test_replace_range() {
|
472 | 487 | let mut s = "Hello, world!".to_owned();
|
@@ -504,6 +519,20 @@ fn test_replace_range_inclusive_out_of_bounds() {
|
504 | 519 | s.replace_range(5..=5, "789");
|
505 | 520 | }
|
506 | 521 |
|
| 522 | +#[test] |
| 523 | +#[should_panic] |
| 524 | +fn test_replace_range_start_overflow() { |
| 525 | + let mut s = String::from("123"); |
| 526 | + s.replace_range((Excluded(usize::MAX), Included(0)), ""); |
| 527 | +} |
| 528 | + |
| 529 | +#[test] |
| 530 | +#[should_panic] |
| 531 | +fn test_replace_range_end_overflow() { |
| 532 | + let mut s = String::from("456"); |
| 533 | + s.replace_range((Included(0), Included(usize::MAX)), ""); |
| 534 | +} |
| 535 | + |
507 | 536 | #[test]
|
508 | 537 | fn test_replace_range_empty() {
|
509 | 538 | let mut s = String::from("12345");
|
|
0 commit comments