test configurations

This commit is contained in:
Max Bradbury 2020-04-19 08:13:55 +01:00
parent d0614b6de2
commit 76e6c2477c
15 changed files with 515 additions and 451 deletions

View File

@ -91,17 +91,22 @@ impl ToString for Avatar {
} }
} }
#[test] #[cfg(test)]
fn test_avatar_from_string() { mod test {
let output = Avatar::from(include_str!("test-resources/avatar").to_string()).unwrap(); use crate::avatar::Avatar;
use crate::mock;
assert_eq!(output, crate::mock::avatar()); #[test]
} fn avatar_from_string() {
let output = Avatar::from(
include_str!("test-resources/avatar").to_string()
).unwrap();
#[test] assert_eq!(output, mock::avatar());
fn test_avatar_to_string() { }
assert_eq!(
crate::mock::avatar().to_string(), #[test]
include_str!("test-resources/avatar") fn avatar_to_string() {
); assert_eq!(mock::avatar().to_string(), include_str!("test-resources/avatar"));
}
} }

View File

@ -24,27 +24,20 @@ impl ToString for Colour {
} }
} }
#[test] #[cfg(test)]
fn test_colour_from_string() { mod test {
assert_eq!( use crate::colour::Colour;
Colour::from("0,255,0".to_string()),
Colour {
red: 0,
green: 255,
blue: 0
}
);
}
#[test] #[test]
fn test_colour_to_string() { fn test_colour_from_string() {
assert_eq!( assert_eq!(
Colour { Colour::from("0,255,0".to_string()),
red: 22, Colour { red: 0, green: 255, blue: 0 }
green: 33, );
blue: 44 }
}
.to_string(), #[test]
"22,33,44".to_string() fn test_colour_to_string() {
); assert_eq!(Colour { red: 22, green: 33, blue: 44, }.to_string(), "22,33,44".to_string());
}
} }

View File

@ -21,25 +21,25 @@ impl ToString for Dialogue {
} }
} }
#[test] #[cfg(test)]
fn test_dialogue_from_string() { mod test {
assert_eq!( use crate::dialogue::Dialogue;
Dialogue::from("DLG h\nhello\ngoodbye".to_string()),
Dialogue {
id: "h".to_string(),
contents: "hello\ngoodbye".to_string()
}
)
}
#[test] #[test]
fn test_dialogue_to_string() { fn test_dialogue_from_string() {
assert_eq!( assert_eq!(
Dialogue { Dialogue::from("DLG h\nhello\ngoodbye".to_string()),
Dialogue { id: "h".to_string(), contents: "hello\ngoodbye".to_string()}
)
}
#[test]
fn test_dialogue_to_string() {
let output = Dialogue {
id: "y".to_string(), id: "y".to_string(),
contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string() contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string()
} }.to_string();
.to_string(), let expected = "DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string();
"DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string() assert_eq!(output, expected);
); }
} }

View File

@ -30,25 +30,29 @@ impl ToString for Ending {
} }
} }
#[test] #[cfg(test)]
fn test_ending_from_string() { mod test {
assert_eq!( use crate::ending::Ending;
Ending::from(include_str!("test-resources/ending").to_string()),
Ending {
id: "a".to_string(),
dialogue: "This is a long line of dialogue. Blah blah blah".to_string()
}
);
}
#[test] #[test]
fn test_ending_to_string() { fn test_ending_from_string() {
assert_eq!( assert_eq!(
Ending { Ending::from(include_str!("test-resources/ending").to_string()),
id: "7".to_string(), Ending {
dialogue: "This is another long ending. So long, farewell, etc.".to_string() id: "a".to_string(),
} dialogue: "This is a long line of dialogue. Blah blah blah".to_string()
.to_string(), }
"END 7\nThis is another long ending. So long, farewell, etc.".to_string() );
); }
#[test]
fn test_ending_to_string() {
assert_eq!(
Ending {
id: "7".to_string(),
dialogue: "This is another long ending. So long, farewell, etc.".to_string()
}.to_string(),
"END 7\nThis is another long ending. So long, farewell, etc.".to_string()
);
}
} }

View File

@ -87,52 +87,58 @@ impl ToString for Exit {
} }
} }
#[test] #[cfg(test)]
fn test_exit_from_string() { mod test {
assert_eq!( use crate::exit::{Transition, Exit};
Exit::from("a 12,13".to_string()), use crate::position::Position;
Exit {
room_id: 10,
position: Position { x: 12, y: 13 },
effect: Transition::None
}
);
}
#[test] #[test]
fn test_exit_from_string_with_fx() { fn test_exit_from_string() {
assert_eq!( assert_eq!(
Exit::from("a 12,13 FX slide_u".to_string()), Exit::from("a 12,13".to_string()),
Exit { Exit {
room_id: 10, room_id: 10,
position: Position { x: 12, y: 13 }, position: Position { x: 12, y: 13 },
effect: Transition::SlideUp effect: Transition::None
} }
); );
} }
#[test] #[test]
fn test_exit_to_string() { fn test_exit_from_string_with_fx() {
assert_eq!( assert_eq!(
Exit { Exit::from("a 12,13 FX slide_u".to_string()),
room_id: 8, Exit {
position: Position { x: 5, y: 6 }, room_id: 10,
effect: Transition::None position: Position { x: 12, y: 13 },
} effect: Transition::SlideUp
.to_string(), }
"8 5,6".to_string() );
); }
}
#[test] #[test]
fn test_exit_to_string_with_fx() { fn test_exit_to_string() {
assert_eq!( assert_eq!(
Exit { Exit {
room_id: 8, room_id: 8,
position: Position { x: 5, y: 6 }, position: Position { x: 5, y: 6 },
effect: Transition::FadeToWhite effect: Transition::None
} }
.to_string(), .to_string(),
"8 5,6 FX fade_w".to_string() "8 5,6".to_string()
); );
}
#[test]
fn test_exit_to_string_with_fx() {
assert_eq!(
Exit {
room_id: 8,
position: Position { x: 5, y: 6 },
effect: Transition::FadeToWhite
}
.to_string(),
"8 5,6 FX fade_w".to_string()
);
}
} }

View File

@ -300,140 +300,146 @@ impl Game {
} }
} }
#[test] #[cfg(test)]
fn test_game_from_string() { mod test {
let output = Game::from(include_str!["test-resources/default.bitsy"].to_string()).unwrap(); use crate::game::{Version, Game};
use crate::text::{TextDirection, Font};
use crate::tile::Tile;
let expected = crate::mock::game_default(); #[test]
fn test_game_from_string() {
let output = Game::from(include_str!["test-resources/default.bitsy"].to_string()).unwrap();
let expected = crate::mock::game_default();
assert_eq!(output, expected); assert_eq!(output, expected);
} }
#[test] #[test]
fn test_game_to_string() { fn test_game_to_string() {
let output = crate::mock::game_default().to_string(); let output = crate::mock::game_default().to_string();
let expected = include_str!["test-resources/default.bitsy"].to_string(); let expected = include_str!["test-resources/default.bitsy"].to_string();
assert_eq!(output, expected); assert_eq!(output, expected);
} }
#[test] #[test]
fn test_tile_ids() { fn test_tile_ids() {
assert_eq!(crate::mock::game_default().tile_ids(), vec![10]); assert_eq!(crate::mock::game_default().tile_ids(), vec![10]);
} }
#[test] #[test]
fn test_new_tile_id() { fn test_new_tile_id() {
// default tile has an id of 10 ("a"), so 0 is available // default tile has an id of 10 ("a"), so 0 is available
assert_eq!(crate::mock::game_default().new_tile_id(), 0); assert_eq!(crate::mock::game_default().new_tile_id(), 0);
let mut game = crate::mock::game_default(); let mut game = crate::mock::game_default();
let mut tiles: Vec<Tile> = Vec::new(); let mut tiles: Vec<Tile> = Vec::new();
for n in 0..9 { for n in 0..9 {
if n != 4 { if n != 4 {
let mut new_tile = crate::mock::tile_default(); let mut new_tile = crate::mock::tile_default();
new_tile.id = n; new_tile.id = n;
tiles.push(new_tile); tiles.push(new_tile);
}
}
game.tiles = tiles;
assert_eq!(game.new_tile_id(), 4);
// fill in the space created above, and test that tile IDs get sorted
let mut new_tile = crate::mock::tile_default();
new_tile.id = 4;
game.tiles.push(new_tile);
assert_eq!(game.new_tile_id(), 10);
}
#[test]
fn test_add_tile() {
let mut game = crate::mock::game_default();
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 0);
assert_eq!(game.tiles.len(), 2);
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 1);
assert_eq!(game.tiles.len(), 3);
}
#[test]
fn test_bitsy_omnibus() {
let acceptable_failures: Vec<String> = vec![
// fails because of sprite colours but also because a tile contains "NaN"
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
// SET instead of ROOM? todo investigate
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
"src/test-resources/omnibus/046871F8.bitsy.txt".to_string(),
// not sure about this one but it uses room wall array
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
// bad game data
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/013B3CDE.bitsy.txt".to_string(), // NaN in image
// this one has font data appended to the end of the game data - is this valid?
"src/test-resources/omnibus/4B4EB988.bitsy.txt".to_string(),
// has an ending position of -1
"src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(),
// extra line between dialogues
"src/test-resources/omnibus/DB59A848.bitsy.txt".to_string(),
// something going on with dialogues? todo investigate
"src/test-resources/omnibus/807805CC.bitsy.txt".to_string(),
"src/test-resources/omnibus/C36E27E5.bitsy.txt".to_string(),
"src/test-resources/omnibus/354DA56F.bitsy.txt".to_string(),
// this avatar has `ITM 0 1` - can the player start with an item? todo investigate
"src/test-resources/omnibus/CC5085BE.bitsy.txt".to_string(),
"src/test-resources/omnibus/20D06BD1.bitsy.txt".to_string(),
];
let mut passes = 0;
let mut skips = 0;
let files = std::fs::read_dir("src/test-resources/omnibus");
if !files.is_ok() {
return;
}
for file in files.unwrap() {
let path = file.unwrap().path();
let nice_name = format!("{}", path.display());
if !nice_name.contains("bitsy") || acceptable_failures.contains(&nice_name) {
skips += 1;
// println!("Skipping: {}", nice_name);
println!("Skipped. {} passes, {} skips.", passes, skips);
continue;
}
println!("Testing: {}...", path.display());
let game_data = std::fs::read_to_string(path).unwrap();
let game = Game::from(game_data.clone()).unwrap();
assert_eq!(
game.to_string().trim_matches('\n'),
game_data.trim_matches('\n')
);
passes += 1;
println!("Success! {} passes, {} skips.", passes, skips);
} }
} }
game.tiles = tiles; #[test]
fn test_arabic() {
let game = Game::from(include_str!("test-resources/arabic.bitsy").to_string()).unwrap();
assert_eq!(game.new_tile_id(), 4); assert_eq!(game.font, Font::Arabic);
assert_eq!(game.text_direction, TextDirection::RightToLeft);
// fill in the space created above, and test that tile IDs get sorted
let mut new_tile = crate::mock::tile_default();
new_tile.id = 4;
game.tiles.push(new_tile);
assert_eq!(game.new_tile_id(), 10);
}
#[test]
fn test_add_tile() {
let mut game = crate::mock::game_default();
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 0);
assert_eq!(game.tiles.len(), 2);
let new_id = game.add_tile(crate::mock::tile_default());
assert_eq!(new_id, 1);
assert_eq!(game.tiles.len(), 3);
}
#[test]
fn test_bitsy_omnibus() {
let acceptable_failures: Vec<String> = vec![
// fails because of sprite colours but also because a tile contains "NaN"
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
// SET instead of ROOM? todo investigate
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
"src/test-resources/omnibus/046871F8.bitsy.txt".to_string(),
// not sure about this one but it uses room wall array
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
// bad game data
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/013B3CDE.bitsy.txt".to_string(), // NaN in image
// this one has font data appended to the end of the game data - is this valid?
"src/test-resources/omnibus/4B4EB988.bitsy.txt".to_string(),
// has an ending position of -1
"src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(),
// extra line between dialogues
"src/test-resources/omnibus/DB59A848.bitsy.txt".to_string(),
// something going on with dialogues? todo investigate
"src/test-resources/omnibus/807805CC.bitsy.txt".to_string(),
"src/test-resources/omnibus/C36E27E5.bitsy.txt".to_string(),
"src/test-resources/omnibus/354DA56F.bitsy.txt".to_string(),
// this avatar has `ITM 0 1` - can the player start with an item? todo investigate
"src/test-resources/omnibus/CC5085BE.bitsy.txt".to_string(),
"src/test-resources/omnibus/20D06BD1.bitsy.txt".to_string(),
];
let mut passes = 0;
let mut skips = 0;
let files = std::fs::read_dir("src/test-resources/omnibus");
if !files.is_ok() {
return;
} }
for file in files.unwrap() { #[test]
let path = file.unwrap().path(); fn test_version_formatting() {
let nice_name = format!("{}", path.display()); let mut game = crate::mock::game_default();
game.version = Version { major: 5, minor: 0 };
if !nice_name.contains("bitsy") || acceptable_failures.contains(&nice_name) { assert!(game.to_string().contains("# BITSY VERSION 5.0"))
skips += 1;
// println!("Skipping: {}", nice_name);
println!("Skipped. {} passes, {} skips.", passes, skips);
continue;
}
println!("Testing: {}...", path.display());
let game_data = std::fs::read_to_string(path).unwrap();
let game = Game::from(game_data.clone()).unwrap();
assert_eq!(
game.to_string().trim_matches('\n'),
game_data.trim_matches('\n')
);
passes += 1;
println!("Success! {} passes, {} skips.", passes, skips);
} }
} }
#[test]
fn test_arabic() {
let game = Game::from(include_str!("test-resources/arabic.bitsy").to_string()).unwrap();
assert_eq!(game.font, Font::Arabic);
assert_eq!(game.text_direction, TextDirection::RightToLeft);
}
#[test]
fn test_version_formatting() {
let mut game = crate::mock::game_default();
game.version = Version { major: 5, minor: 0 };
assert!(game.to_string().contains("# BITSY VERSION 5.0"))
}

View File

@ -38,24 +38,34 @@ impl ToString for Image {
} }
} }
#[test] #[cfg(test)]
fn test_image_from_string() { mod test {
let output = Image::from(include_str!("test-resources/image").to_string()); use crate::image::Image;
let expected = Image { #[test]
pixels: vec![ fn test_image_from_string() {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, let output = Image::from(include_str!("test-resources/image").to_string());
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,
],
};
assert_eq!(output, expected) let expected = Image {
} pixels: vec![
1, 1, 1, 1, 1, 1, 1, 1,
#[test] 1, 1, 0, 0, 1, 1, 1, 1,
fn test_image_to_string() { 1, 0, 1, 1, 1, 1, 1, 1,
let output = crate::mock::image::chequers_1().to_string(); 1, 1, 1, 1, 1, 1, 1, 1,
let expected = include_str!("test-resources/image-chequers-1").to_string(); 1, 1, 1, 1, 1, 1, 1, 1,
assert_eq!(output, expected); 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
],
};
assert_eq!(output, expected);
}
#[test]
fn test_image_to_string() {
let output = crate::mock::image::chequers_1().to_string();
let expected = include_str!("test-resources/image-chequers-1").to_string();
assert_eq!(output, expected);
}
} }

View File

@ -79,16 +79,22 @@ impl ToString for Item {
} }
} }
#[test] #[cfg(test)]
fn test_item_from_string() { mod test {
let output = Item::from(include_str!("test-resources/item").to_string()); use crate::item::Item;
let expected = crate::mock::item(); use crate::mock;
assert_eq!(output, expected);
}
#[test] #[test]
fn test_item_to_string() { fn test_item_from_string() {
let output = crate::mock::item().to_string(); let output = Item::from(include_str!("test-resources/item").to_string());
let expected = include_str!("test-resources/item").to_string(); let expected = mock::item();
assert_eq!(output, expected); assert_eq!(output, expected);
}
#[test]
fn test_item_to_string() {
let output = mock::item().to_string();
let expected = include_str!("test-resources/item").to_string();
assert_eq!(output, expected);
}
} }

View File

@ -72,13 +72,6 @@ fn from_base36(str: &str) -> u64 {
u64::from_str_radix(str, 36).unwrap() u64::from_str_radix(str, 36).unwrap()
} }
#[test]
fn test_from_base36() {
assert_eq!(from_base36("0"), 0);
assert_eq!(from_base36("0z"), 35);
assert_eq!(from_base36("11"), 37);
}
/// this doesn't work inside ToBase36 for some reason /// this doesn't work inside ToBase36 for some reason
fn to_base36(int: u64) -> String { fn to_base36(int: u64) -> String {
format!("{}", radix_36(int)) format!("{}", radix_36(int))
@ -94,11 +87,6 @@ impl ToBase36 for u64 {
} }
} }
#[test]
fn test_to_base36() {
assert_eq!((37 as u64).to_base36(), "11");
}
/// e.g. `\nNAME DLG_0` /// e.g. `\nNAME DLG_0`
fn optional_data_line<T: Display>(label: &str, item: Option<T>) -> String { fn optional_data_line<T: Display>(label: &str, item: Option<T>) -> String {
if item.is_some() { if item.is_some() {
@ -108,8 +96,25 @@ fn optional_data_line<T: Display>(label: &str, item: Option<T>) -> String {
} }
} }
#[test] #[cfg(test)]
fn test_optional_data_line() { mod test {
let output = optional_data_line("NAME", mock::item().name); use crate::{from_base36, ToBase36, optional_data_line, mock};
assert_eq!(output, "\nNAME door".to_string());
#[test]
fn test_from_base36() {
assert_eq!(from_base36("0"), 0);
assert_eq!(from_base36("0z"), 35);
assert_eq!(from_base36("11"), 37);
}
#[test]
fn test_to_base36() {
assert_eq!((37 as u64).to_base36(), "11");
}
#[test]
fn test_optional_data_line() {
let output = optional_data_line("NAME", mock::item().name);
assert_eq!(output, "\nNAME door".to_string());
}
} }

View File

@ -49,88 +49,94 @@ impl ToString for Palette {
} }
} }
#[test] #[cfg(test)]
fn test_palette_from_string() { mod test {
let output = Palette::from("PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string()); use crate::colour::Colour;
use crate::palette::Palette;
let expected = Palette { #[test]
id: 1, fn test_palette_from_string() {
name: Some("lamplight".to_string()), let output = Palette::from("PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string());
colours: vec![
Colour {
red: 45,
green: 45,
blue: 59,
},
Colour {
red: 66,
green: 60,
blue: 39,
},
Colour {
red: 140,
green: 94,
blue: 1,
},
],
};
assert_eq!(output, expected); let expected = Palette {
} id: 1,
name: Some("lamplight".to_string()),
colours: vec![
Colour {
red: 45,
green: 45,
blue: 59,
},
Colour {
red: 66,
green: 60,
blue: 39,
},
Colour {
red: 140,
green: 94,
blue: 1,
},
],
};
#[test] assert_eq!(output, expected);
fn test_palette_from_string_no_name() { }
let output = Palette::from("PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string());
#[test]
let expected = Palette { fn test_palette_from_string_no_name() {
id: 9, let output = Palette::from("PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string());
name: None,
colours: vec![ let expected = Palette {
Colour { id: 9,
red: 45, name: None,
green: 45, colours: vec![
blue: 59, Colour {
}, red: 45,
Colour { green: 45,
red: 66, blue: 59,
green: 60, },
blue: 39, Colour {
}, red: 66,
Colour { green: 60,
red: 140, blue: 39,
green: 94, },
blue: 1, Colour {
}, red: 140,
], green: 94,
}; blue: 1,
},
assert_eq!(output, expected); ],
} };
#[test] assert_eq!(output, expected);
fn test_palette_to_string() { }
let output = Palette {
id: 16, #[test]
name: Some("moss".to_string()), fn test_palette_to_string() {
colours: vec![ let output = Palette {
Colour { id: 16,
red: 1, name: Some("moss".to_string()),
green: 2, colours: vec![
blue: 3, Colour {
}, red: 1,
Colour { green: 2,
red: 255, blue: 3,
green: 254, },
blue: 253, Colour {
}, red: 255,
Colour { green: 254,
red: 126, blue: 253,
green: 127, },
blue: 128, Colour {
}, red: 126,
], green: 127,
blue: 128,
},
],
}
.to_string();
let expected = "PAL g\nNAME moss\n1,2,3\n255,254,253\n126,127,128".to_string();
assert_eq!(output, expected);
} }
.to_string();
let expected = "PAL g\nNAME moss\n1,2,3\n255,254,253\n126,127,128".to_string();
assert_eq!(output, expected);
} }

View File

@ -29,15 +29,20 @@ impl ToString for Position {
} }
} }
#[test] #[cfg(test)]
fn test_position_from_string() { mod test {
assert_eq!( use crate::position::Position;
Position::from("4,12".to_string()).unwrap(),
Position { x: 4, y: 12 }
);
}
#[test] #[test]
fn test_position_to_string() { fn test_position_from_string() {
assert_eq!(Position { x: 4, y: 12 }.to_string(), "4,12".to_string()) assert_eq!(
Position::from("4,12".to_string()).unwrap(),
Position { x: 4, y: 12 }
);
}
#[test]
fn test_position_to_string() {
assert_eq!(Position { x: 4, y: 12 }.to_string(), "4,12".to_string())
}
} }

View File

@ -128,14 +128,6 @@ impl From<String> for Room {
} }
} }
#[test]
fn test_room_from_string() {
assert_eq!(
Room::from(include_str!("test-resources/room").to_string()),
crate::mock::room()
);
}
impl ToString for Room { impl ToString for Room {
fn to_string(&self) -> String { fn to_string(&self) -> String {
let mut tiles = String::new(); let mut tiles = String::new();
@ -191,17 +183,30 @@ impl ToString for Room {
} }
} }
#[test] #[cfg(test)]
fn test_room_to_string() { mod test {
assert_eq!( use crate::room::Room;
crate::mock::room().to_string(),
include_str!("test-resources/room").to_string()
);
}
#[test] #[test]
fn test_room_walls_array() { fn test_room_from_string() {
let output = Room::from(include_str!("test-resources/room-with-walls").to_string()); assert_eq!(
Room::from(include_str!("test-resources/room").to_string()),
crate::mock::room()
);
}
assert_eq!(output.walls, vec![10, 15]); #[test]
fn test_room_to_string() {
assert_eq!(
crate::mock::room().to_string(),
include_str!("test-resources/room").to_string()
);
}
#[test]
fn test_room_walls_array() {
let output = Room::from(include_str!("test-resources/room-with-walls").to_string());
assert_eq!(output.walls, vec![10, 15]);
}
} }

View File

@ -108,19 +108,21 @@ impl ToString for Sprite {
} }
} }
#[test] #[cfg(test)]
fn test_sprite_from_string() { mod test {
let output = Sprite::from(include_str!("test-resources/sprite").to_string()); use crate::mock;
use crate::sprite::Sprite;
let expected = crate::mock::sprite(); #[test]
fn test_sprite_from_string() {
let output = Sprite::from(include_str!("test-resources/sprite").to_string());
let expected = mock::sprite();
assert_eq!(output, expected); assert_eq!(output, expected);
} }
#[test] #[test]
fn test_sprite_to_string() { fn test_sprite_to_string() {
assert_eq!( assert_eq!(mock::sprite().to_string(), include_str!("test-resources/sprite").to_string());
crate::mock::sprite().to_string(), }
include_str!("test-resources/sprite").to_string()
);
} }

View File

@ -88,38 +88,44 @@ impl ToString for Tile {
} }
} }
#[test] #[cfg(test)]
fn test_tile_from_string() { mod test {
let output = Tile::from(include_str!("test-resources/tile").to_string()); use crate::tile::Tile;
use crate::image::Image;
let expected = Tile { #[test]
id: 35, fn test_tile_from_string() {
name: Some("concrete 1".to_string()), let output = Tile::from(include_str!("test-resources/tile").to_string());
wall: Some(true),
animation_frames: vec![Image {
pixels: vec![1; 64],
}],
colour_id: None,
};
assert_eq!(output, expected); let expected = Tile {
} id: 35,
name: Some("concrete 1".to_string()),
wall: Some(true),
animation_frames: vec![Image {
pixels: vec![1; 64],
}],
colour_id: None,
};
#[test] assert_eq!(output, expected);
fn test_tile_to_string() {
let output = Tile {
id: 262,
name: Some("chequers".to_string()),
wall: None,
animation_frames: vec![
crate::mock::image::chequers_1(),
crate::mock::image::chequers_2(),
],
colour_id: None,
} }
.to_string();
let expected = include_str!("test-resources/tile-chequers").to_string(); #[test]
fn test_tile_to_string() {
let output = Tile {
id: 262,
name: Some("chequers".to_string()),
wall: None,
animation_frames: vec![
crate::mock::image::chequers_1(),
crate::mock::image::chequers_2(),
],
colour_id: None,
}
.to_string();
assert_eq!(output, expected); let expected = include_str!("test-resources/tile-chequers").to_string();
assert_eq!(output, expected);
}
} }

View File

@ -21,24 +21,29 @@ impl ToString for Variable {
} }
} }
#[test] #[cfg(test)]
fn test_variable_from_string() { mod test {
assert_eq!( use crate::variable::Variable;
Variable::from("VAR a\n42".to_string()),
Variable {
id: "a".to_string(),
initial_value: "42".to_string()
}
);
}
#[test] #[test]
fn test_variable_to_string() { fn test_variable_from_string() {
let output = Variable { assert_eq!(
id: "c".to_string(), Variable::from("VAR a\n42".to_string()),
initial_value: "57".to_string(), Variable {
id: "a".to_string(),
initial_value: "42".to_string()
}
);
}
#[test]
fn test_variable_to_string() {
let output = Variable {
id: "c".to_string(),
initial_value: "57".to_string(),
}
.to_string();
let expected = "VAR c\n57".to_string();
assert_eq!(output, expected);
} }
.to_string();
let expected = "VAR c\n57".to_string();
assert_eq!(output, expected);
} }