aboutsummaryrefslogtreecommitdiff
path: root/src/test/run-pass/vec-lib.rs
blob: 90a95ff9a2633d56b1095e1e244c7fd05039eb00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std;

fn test_init_elt() {
  let vec[uint] v = std._vec.init_elt[uint](5 as uint, 3 as uint);
  check (std._vec.len[uint](v) == (3 as uint));
  check (v.(0) == (5 as uint));
  check (v.(1) == (5 as uint));
  check (v.(2) == (5 as uint));
}

fn id(uint x) -> uint {
  ret x;
}
fn test_init_fn() {
  let fn(uint)->uint op = id;
  let vec[uint] v = std._vec.init_fn[uint](op, (5 as uint));
  check (std._vec.len[uint](v) == (5 as uint));
  check (v.(0) == (0 as uint));
  check (v.(1) == (1 as uint));
  check (v.(2) == (2 as uint));
  check (v.(3) == (3 as uint));
  check (v.(4) == (4 as uint));
}

fn test_slice() {
  let vec[int] v = vec(1,2,3,4,5);
  auto v2 = std._vec.slice[int](v, 2, 4);
  check (std._vec.len[int](v2) == (2 as uint));
  check (v2.(0) == 3);
  check (v2.(1) == 4);
}

fn main() {
  test_init_elt();
  //XFAIL: test_init_fn();  // Segfaults.
  test_slice();
}