PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/run-pass/vec-self-append.rs

http://github.com/jruderman/rust
Rust | 49 lines | 41 code | 4 blank | 4 comment | 20 complexity | 47c25c0aef532b5c10db29db9d1b233e MD5 | raw file
 1use std;
 2import vec;
 3
 4fn test_heap_to_heap() {
 5    // a spills onto the heap
 6    let mut a = ~[0, 1, 2, 3, 4];
 7    a += a;
 8    assert (vec::len(a) == 10u);
 9    assert (a[0] == 0);
10    assert (a[1] == 1);
11    assert (a[2] == 2);
12    assert (a[3] == 3);
13    assert (a[4] == 4);
14    assert (a[5] == 0);
15    assert (a[6] == 1);
16    assert (a[7] == 2);
17    assert (a[8] == 3);
18    assert (a[9] == 4);
19}
20
21fn test_stack_to_heap() {
22    // a is entirely on the stack
23    let mut a = ~[0, 1, 2];
24    // a spills to the heap
25    a += a;
26    assert (vec::len(a) == 6u);
27    assert (a[0] == 0);
28    assert (a[1] == 1);
29    assert (a[2] == 2);
30    assert (a[3] == 0);
31    assert (a[4] == 1);
32    assert (a[5] == 2);
33}
34
35fn test_loop() {
36    // Make sure we properly handle repeated self-appends.
37    let mut a: ~[int] = ~[0];
38    let mut i = 20;
39    let mut expected_len = 1u;
40    while i > 0 {
41        log(error, vec::len(a));
42        assert (vec::len(a) == expected_len);
43        a += a;
44        i -= 1;
45        expected_len *= 2u;
46    }
47}
48
49fn main() { test_heap_to_heap(); test_stack_to_heap(); test_loop(); }