function for optional lines of game data
This commit is contained in:
16
src/lib.rs
16
src/lib.rs
@@ -30,6 +30,7 @@ use room::Room;
|
||||
use sprite::Sprite;
|
||||
use tile::Tile;
|
||||
use variable::Variable;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Instance {
|
||||
@@ -95,3 +96,18 @@ impl ToBase36 for u64 {
|
||||
fn test_to_base36() {
|
||||
assert_eq!((37 as u64).to_base36(), "11");
|
||||
}
|
||||
|
||||
/// e.g. `\nNAME DLG_0`
|
||||
fn optional_data_line<T: Display>(label: &str, item: Option<T>) -> String {
|
||||
if item.is_some() {
|
||||
format!("\n{} {}", label, item.unwrap())
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optional_data_line() {
|
||||
let output = optional_data_line("NAME", mock::item().name);
|
||||
assert_eq!(output, "\nNAME door".to_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user