]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/slice-2.rs
rollup merge of #17355 : gamazeps/issue17210
[rust.git] / src / test / run-pass / slice-2.rs
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.
4 //
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.
10
11 // Test slicing expressions on slices and Vecs.
12
13 fn main() {
14     let x: &[int] = &[1, 2, 3, 4, 5];
15     let cmp: &[int] = &[1, 2, 3, 4, 5];
16     assert!(x[] == cmp)
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)
23
24     let x: Vec<int> = vec![1, 2, 3, 4, 5];
25     let cmp: &[int] = &[1, 2, 3, 4, 5];
26     assert!(x[] == cmp)
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)
33
34     let x: &mut [int] = &mut [1, 2, 3, 4, 5];
35     {
36         let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
37         assert!(x[mut] == cmp)
38     }
39     {
40         let cmp: &mut [int] = &mut [3, 4, 5];
41         assert!(x[mut 2..] == cmp)
42     }
43     {
44         let cmp: &mut [int] = &mut [1, 2, 3];
45         assert!(x[mut ..3] == cmp)
46     }
47     {
48         let cmp: &mut [int] = &mut [2, 3, 4];
49         assert!(x[mut 1..4] == cmp)
50     }
51
52     let mut x: Vec<int> = vec![1, 2, 3, 4, 5];
53     {
54         let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
55         assert!(x[mut] == cmp)
56     }
57     {
58         let cmp: &mut [int] = &mut [3, 4, 5];
59         assert!(x[mut 2..] == cmp)
60     }
61     {
62         let cmp: &mut [int] = &mut [1, 2, 3];
63         assert!(x[mut ..3] == cmp)
64     }
65     {
66         let cmp: &mut [int] = &mut [2, 3, 4];
67         assert!(x[mut 1..4] == cmp)
68     }
69 }