]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-2904.rs
9ffe4bc4d7e5d67b86cb011d2edf967c23fb7bc0
[rust.git] / src / test / run-pass / issue-2904.rs
1 // ignore-fast
2
3 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4 // file at the top-level directory of this distribution and at
5 // http://rust-lang.org/COPYRIGHT.
6 //
7 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 // option. This file may not be copied, modified, or distributed
11 // except according to those terms.
12
13 #[feature(managed_boxes)];
14
15 /// Map representation
16
17 use std::io;
18 use std::fmt;
19
20 enum square {
21     bot,
22     wall,
23     rock,
24     lambda,
25     closed_lift,
26     open_lift,
27     earth,
28     empty
29 }
30
31 impl fmt::Show for square {
32     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33         write!(f.buf, "{}", match *self {
34           bot => { ~"R" }
35           wall => { ~"#" }
36           rock => { ~"*" }
37           lambda => { ~"\\" }
38           closed_lift => { ~"L" }
39           open_lift => { ~"O" }
40           earth => { ~"." }
41           empty => { ~" " }
42         })
43     }
44 }
45
46 fn square_from_char(c: char) -> square {
47     match c  {
48       'R'  => { bot }
49       '#'  => { wall }
50       '*'  => { rock }
51       '\\' => { lambda }
52       'L'  => { closed_lift }
53       'O'  => { open_lift }
54       '.'  => { earth }
55       ' '  => { empty }
56       _ => {
57         println!("invalid square: {:?}", c);
58         fail!()
59       }
60     }
61 }
62
63 fn read_board_grid<rdr:'static + io::Reader>(mut input: rdr) -> vec!(vec!(square)) {
64     let mut input: &mut io::Reader = &mut input;
65     let mut grid = Vec::new();
66     let mut line = [0, ..10];
67     input.read(line);
68     let mut row = Vec::new();
69     for c in line.iter() {
70         row.push(square_from_char(*c as char))
71     }
72     grid.push(row);
73     let width = grid[0].len();
74     for row in grid.iter() { assert!(row.len() == width) }
75     grid
76 }
77
78 mod test {
79     #[test]
80     pub fn trivial_to_str() {
81         assert!(lambda.to_str() == "\\")
82     }
83 }
84
85 pub fn main() {}