valence/src/block.rs

51 lines
1.2 KiB
Rust
Raw Normal View History

2022-04-17 17:04:39 -07:00
#![allow(clippy::all)]
2022-04-19 23:41:15 -07:00
use std::fmt;
2022-04-17 17:04:39 -07:00
include!(concat!(env!("OUT_DIR"), "/block.rs"));
2022-04-19 23:41:15 -07:00
impl fmt::Debug for BlockState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let typ = self.to_type();
write!(f, "{}", typ.to_str())?;
let props = typ.props();
if !props.is_empty() {
let mut list = f.debug_list();
for &p in typ.props() {
struct KeyVal<'a>(&'a str, &'a str);
impl<'a> fmt::Debug for KeyVal<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}={}", self.0, self.1)
}
}
list.entry(&KeyVal(p.to_str(), self.get(p).unwrap().to_str()));
}
list.finish()
} else {
Ok(())
}
}
}
2022-04-17 17:04:39 -07:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_set_consistency() {
for typ in BlockType::ALL {
let block = typ.to_state();
for &prop in typ.props() {
let new_block = block.set(prop, block.get(prop).unwrap());
assert_eq!(new_block, block);
}
}
}
}