]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/rec-tup.rs
Add a doctest for the std::string::as_string method.
[rust.git] / src / test / run-pass / rec-tup.rs
1 // Copyright 2012 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 struct Point {x: int, y: int}
12
13 type rect = (Point, Point);
14
15 fn fst(r: rect) -> Point { let (fst, _) = r; return fst; }
16 fn snd(r: rect) -> Point { let (_, snd) = r; return snd; }
17
18 fn f(r: rect, x1: int, y1: int, x2: int, y2: int) {
19     assert_eq!(fst(r).x, x1);
20     assert_eq!(fst(r).y, y1);
21     assert_eq!(snd(r).x, x2);
22     assert_eq!(snd(r).y, y2);
23 }
24
25 pub fn main() {
26     let r: rect = (Point {x: 10, y: 20}, Point {x: 11, y: 22});
27     assert_eq!(fst(r).x, 10);
28     assert_eq!(fst(r).y, 20);
29     assert_eq!(snd(r).x, 11);
30     assert_eq!(snd(r).y, 22);
31     let r2 = r;
32     let x: int = fst(r2).x;
33     assert_eq!(x, 10);
34     f(r, 10, 20, 11, 22);
35     f(r2, 10, 20, 11, 22);
36 }