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