rust/tests/ui/issues/issue-2904.rs

80 lines
1.7 KiB
Rust
Raw Normal View History

// build-pass
#![allow(unused_must_use)]
#![allow(dead_code)]
#![allow(unused_mut)]
#![allow(non_camel_case_types)]
2013-10-23 08:49:18 +00:00
// Map representation
use std::fmt;
2015-04-10 18:12:43 +00:00
use std::io::prelude::*;
use square::{bot, wall, rock, lambda, closed_lift, open_lift, earth, empty};
2013-03-27 04:17:29 +00:00
enum square {
bot,
wall,
rock,
lambda,
closed_lift,
open_lift,
earth,
empty
}
2015-01-28 13:34:18 +00:00
impl fmt::Debug for square {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", match *self {
2014-05-25 10:10:11 +00:00
bot => { "R".to_string() }
wall => { "#".to_string() }
rock => { "*".to_string() }
lambda => { "\\".to_string() }
closed_lift => { "L".to_string() }
open_lift => { "O".to_string() }
earth => { ".".to_string() }
empty => { " ".to_string() }
})
}
}
fn square_from_char(c: char) -> square {
2012-08-06 19:34:08 +00:00
match c {
2012-08-04 02:59:04 +00:00
'R' => { bot }
'#' => { wall }
'*' => { rock }
'\\' => { lambda }
'L' => { closed_lift }
'O' => { open_lift }
'.' => { earth }
' ' => { empty }
_ => {
2014-10-15 01:07:11 +00:00
println!("invalid square: {}", c);
panic!()
}
}
}
2015-04-10 18:12:43 +00:00
fn read_board_grid<rdr:'static + Read>(mut input: rdr)
-> Vec<Vec<square>> {
2019-05-28 18:46:13 +00:00
let mut input: &mut dyn Read = &mut input;
let mut grid = Vec::new();
let mut line = [0; 10];
2014-11-17 08:39:01 +00:00
input.read(&mut line);
let mut row = Vec::new();
2015-01-31 17:20:46 +00:00
for c in &line {
row.push(square_from_char(*c as char))
}
grid.push(row);
let width = grid[0].len();
for row in &grid { assert_eq!(row.len(), width) }
grid
}
mod test {
#[test]
pub fn trivial_to_string() {
assert_eq!(lambda.to_string(), "\\")
}
}
pub fn main() {}