]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-2904.rs
Rollup merge of #60492 - acrrd:issues/54054_chain, r=SimonSapin
[rust.git] / src / test / ui / issues / issue-2904.rs
1 // build-pass (FIXME(62277): could be check-pass?)
2 #![allow(unused_must_use)]
3 #![allow(dead_code)]
4 #![allow(unused_mut)]
5 #![allow(non_camel_case_types)]
6
7 // Map representation
8
9 use std::fmt;
10 use std::io::prelude::*;
11 use square::{bot, wall, rock, lambda, closed_lift, open_lift, earth, empty};
12
13 enum square {
14     bot,
15     wall,
16     rock,
17     lambda,
18     closed_lift,
19     open_lift,
20     earth,
21     empty
22 }
23
24 impl fmt::Debug for square {
25     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26         write!(f, "{}", match *self {
27           bot => { "R".to_string() }
28           wall => { "#".to_string() }
29           rock => { "*".to_string() }
30           lambda => { "\\".to_string() }
31           closed_lift => { "L".to_string() }
32           open_lift => { "O".to_string() }
33           earth => { ".".to_string() }
34           empty => { " ".to_string() }
35         })
36     }
37 }
38
39 fn square_from_char(c: char) -> square {
40     match c  {
41       'R'  => { bot }
42       '#'  => { wall }
43       '*'  => { rock }
44       '\\' => { lambda }
45       'L'  => { closed_lift }
46       'O'  => { open_lift }
47       '.'  => { earth }
48       ' '  => { empty }
49       _ => {
50         println!("invalid square: {}", c);
51         panic!()
52       }
53     }
54 }
55
56 fn read_board_grid<rdr:'static + Read>(mut input: rdr)
57                    -> Vec<Vec<square>> {
58     let mut input: &mut dyn Read = &mut input;
59     let mut grid = Vec::new();
60     let mut line = [0; 10];
61     input.read(&mut line);
62     let mut row = Vec::new();
63     for c in &line {
64         row.push(square_from_char(*c as char))
65     }
66     grid.push(row);
67     let width = grid[0].len();
68     for row in &grid { assert_eq!(row.len(), width) }
69     grid
70 }
71
72 mod test {
73     #[test]
74     pub fn trivial_to_string() {
75         assert_eq!(lambda.to_string(), "\\")
76     }
77 }
78
79 pub fn main() {}