PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/src/test/run-pass/rec-tup.rs

http://github.com/jruderman/rust
Rust | 27 lines | 22 code | 4 blank | 1 comment | 9 complexity | 036ee3d86294631e7c7ac53e350e8c17 MD5 | raw file
 1// -*- rust -*-
 2type point = {x: int, y: int};
 3
 4type rect = (point, point);
 5
 6fn fst(r: rect) -> point { let (fst, _) = r; return fst; }
 7fn snd(r: rect) -> point { let (_, snd) = r; return snd; }
 8
 9fn f(r: rect, x1: int, y1: int, x2: int, y2: int) {
10    assert (fst(r).x == x1);
11    assert (fst(r).y == y1);
12    assert (snd(r).x == x2);
13    assert (snd(r).y == y2);
14}
15
16fn main() {
17    let r: rect = ({x: 10, y: 20}, {x: 11, y: 22});
18    assert (fst(r).x == 10);
19    assert (fst(r).y == 20);
20    assert (snd(r).x == 11);
21    assert (snd(r).y == 22);
22    let r2 = r;
23    let x: int = fst(r2).x;
24    assert (x == 10);
25    f(r, 10, 20, 11, 22);
26    f(r2, 10, 20, 11, 22);
27}