diff options
| author | Alex Burka <aburka@seas.upenn.edu> | 2016-01-28 11:20:48 -0500 |
|---|---|---|
| committer | Alex Burka <aburka@seas.upenn.edu> | 2016-02-27 02:01:41 -0500 |
| commit | 7eb7c56bd43b2ae12ef8b92e7258d520099a5347 (patch) | |
| tree | 9265a7f93946aa1536e79cb7c42bba9a5e138480 /src/test | |
| parent | b1b4f50678ecd6aaeed9991b860c272be010fc9f (diff) | |
| download | rust-7eb7c56bd43b2ae12ef8b92e7258d520099a5347.tar.gz rust-7eb7c56bd43b2ae12ef8b92e7258d520099a5347.zip | |
add indexing with RangeInclusive in libcore and libcollections
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/range_inclusive.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/run-pass/range_inclusive.rs b/src/test/run-pass/range_inclusive.rs index c1bc6adf7b8..52c8353d00e 100644 --- a/src/test/run-pass/range_inclusive.rs +++ b/src/test/run-pass/range_inclusive.rs @@ -55,6 +55,24 @@ pub fn main() { let _ = x...&y; } + // test collection indexing + let vec = (0...10).collect::<Vec<_>>(); + let slice: &[_] = &*vec; + let string = String::from("hello world"); + let stir = "hello world"; + + assert_eq!(&vec[3...6], &[3, 4, 5, 6]); + assert_eq!(&vec[ ...6], &[0, 1, 2, 3, 4, 5, 6]); + + assert_eq!(&slice[3...6], &[3, 4, 5, 6]); + assert_eq!(&slice[ ...6], &[0, 1, 2, 3, 4, 5, 6]); + + assert_eq!(&string[3...6], "lo w"); + assert_eq!(&string[ ...6], "hello w"); + + assert_eq!(&stir[3...6], "lo w"); + assert_eq!(&stir[ ...6], "hello w"); + // test the size hints and emptying let mut long = 0...255u8; let mut short = 42...42; |
