diff options
| author | Josh Stone <jistone@redhat.com> | 2020-10-20 17:18:08 -0700 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2020-10-20 17:18:08 -0700 |
| commit | 9202fbdbdbd60adb62839c3230738274e30f15fc (patch) | |
| tree | 6d3e5083973900ea887238e6b3e7ec6ebcc249ce /library/alloc | |
| parent | 9fd79a39044be777a39604856d0a276484d6480f (diff) | |
| download | rust-9202fbdbdbd60adb62839c3230738274e30f15fc.tar.gz rust-9202fbdbdbd60adb62839c3230738274e30f15fc.zip | |
Check for exhaustion in SliceIndex for RangeInclusive
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/tests/str.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index ed8ee2d8823..834dd4656ff 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -529,6 +529,13 @@ mod slice_index { message: "out of bounds"; } + in mod rangeinclusive_len { + data: "abcdef"; + good: data[0..=5] == "abcdef"; + bad: data[0..=6]; + message: "out of bounds"; + } + in mod range_len_len { data: "abcdef"; good: data[6..6] == ""; @@ -545,6 +552,28 @@ mod slice_index { } panic_cases! { + in mod rangeinclusive_exhausted { + data: "abcdef"; + + good: data[0..=5] == "abcdef"; + good: data[{ + let mut iter = 0..=5; + iter.by_ref().count(); // exhaust it + iter + }] == ""; + + // 0..=6 is out of bounds before exhaustion, so it + // stands to reason that it still would be after. + bad: data[{ + let mut iter = 0..=6; + iter.by_ref().count(); // exhaust it + iter + }]; + message: "out of bounds"; + } + } + + panic_cases! { in mod range_neg_width { data: "abcdef"; good: data[4..4] == ""; |
