2014-09-15 20:48:58 +12:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Test slicing expressions on slices and Vecs.
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x: &[int] = &[1, 2, 3, 4, 5];
|
|
|
|
let cmp: &[int] = &[1, 2, 3, 4, 5];
|
2015-02-04 23:23:12 +01:00
|
|
|
assert!(&x[..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
let cmp: &[int] = &[3, 4, 5];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&x[2..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
let cmp: &[int] = &[1, 2, 3];
|
2015-01-12 16:59:18 -05:00
|
|
|
assert!(&x[..3] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
let cmp: &[int] = &[2, 3, 4];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&x[1..4] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
|
|
|
|
let x: Vec<int> = vec![1, 2, 3, 4, 5];
|
|
|
|
let cmp: &[int] = &[1, 2, 3, 4, 5];
|
2015-02-05 17:58:30 +01:00
|
|
|
assert!(&x[..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
let cmp: &[int] = &[3, 4, 5];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&x[2..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
let cmp: &[int] = &[1, 2, 3];
|
2015-01-12 16:59:18 -05:00
|
|
|
assert!(&x[..3] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
let cmp: &[int] = &[2, 3, 4];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&x[1..4] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
|
|
|
|
let x: &mut [int] = &mut [1, 2, 3, 4, 5];
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
|
2015-02-04 23:23:12 +01:00
|
|
|
assert!(&mut x[..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [3, 4, 5];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&mut x[2..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [1, 2, 3];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&mut x[..3] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [2, 3, 4];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&mut x[1..4] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
let mut x: Vec<int> = vec![1, 2, 3, 4, 5];
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
|
2015-02-04 23:23:12 +01:00
|
|
|
assert!(&mut x[..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [3, 4, 5];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&mut x[2..] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [1, 2, 3];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&mut x[..3] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let cmp: &mut [int] = &mut [2, 3, 4];
|
2015-01-03 13:34:13 +13:00
|
|
|
assert!(&mut x[1..4] == cmp);
|
2014-09-15 20:48:58 +12:00
|
|
|
}
|
|
|
|
}
|