]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-2904.rs
auto merge of #19514 : jbranchaud/rust/add-btree-set-bitor, r=Gankro
[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 use square::{bot, wall, rock, lambda, closed_lift, open_lift, earth, empty};
18
19 enum square {
20     bot,
21     wall,
22     rock,
23     lambda,
24     closed_lift,
25     open_lift,
26     earth,
27     empty
28 }
29
30 impl fmt::Show for square {
31     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32         write!(f, "{}", match *self {
33           bot => { "R".to_string() }
34           wall => { "#".to_string() }
35           rock => { "*".to_string() }
36           lambda => { "\\".to_string() }
37           closed_lift => { "L".to_string() }
38           open_lift => { "O".to_string() }
39           earth => { ".".to_string() }
40           empty => { " ".to_string() }
41         })
42     }
43 }
44
45 fn square_from_char(c: char) -> square {
46     match c  {
47       'R'  => { bot }
48       '#'  => { wall }
49       '*'  => { rock }
50       '\\' => { lambda }
51       'L'  => { closed_lift }
52       'O'  => { open_lift }
53       '.'  => { earth }
54       ' '  => { empty }
55       _ => {
56         println!("invalid square: {}", c);
57         panic!()
58       }
59     }
60 }
61
62 fn read_board_grid<rdr:'static + io::Reader>(mut input: rdr)
63                    -> 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(&mut 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_string() {
81         assert!(lambda.to_string() == "\\")
82     }
83 }
84
85 pub fn main() {}