1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test slicing expressions on slices and Vecs.
14 let x: &[int] = &[1, 2, 3, 4, 5];
15 let cmp: &[int] = &[1, 2, 3, 4, 5];
17 let cmp: &[int] = &[3, 4, 5];
18 assert!(&x[2..] == cmp);
19 let cmp: &[int] = &[1, 2, 3];
20 assert!(&x[..3] == cmp);
21 let cmp: &[int] = &[2, 3, 4];
22 assert!(&x[1..4] == cmp);
24 let x: Vec<int> = vec![1, 2, 3, 4, 5];
25 let cmp: &[int] = &[1, 2, 3, 4, 5];
27 let cmp: &[int] = &[3, 4, 5];
28 assert!(&x[2..] == cmp);
29 let cmp: &[int] = &[1, 2, 3];
30 assert!(&x[..3] == cmp);
31 let cmp: &[int] = &[2, 3, 4];
32 assert!(&x[1..4] == cmp);
34 let x: &mut [int] = &mut [1, 2, 3, 4, 5];
36 let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
37 assert!(&mut x[] == cmp);
40 let cmp: &mut [int] = &mut [3, 4, 5];
41 assert!(&mut x[2..] == cmp);
44 let cmp: &mut [int] = &mut [1, 2, 3];
45 assert!(&mut x[..3] == cmp);
48 let cmp: &mut [int] = &mut [2, 3, 4];
49 assert!(&mut x[1..4] == cmp);
52 let mut x: Vec<int> = vec![1, 2, 3, 4, 5];
54 let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
55 assert!(&mut x[] == cmp);
58 let cmp: &mut [int] = &mut [3, 4, 5];
59 assert!(&mut x[2..] == cmp);
62 let cmp: &mut [int] = &mut [1, 2, 3];
63 assert!(&mut x[..3] == cmp);
66 let cmp: &mut [int] = &mut [2, 3, 4];
67 assert!(&mut x[1..4] == cmp);