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]
fn test_avatar_from_string() {
let output = Avatar::from(include_str!("test-resources/avatar").to_string()).unwrap();
#[cfg(test)]
mod test {
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]
fn test_avatar_to_string() {
assert_eq!(
crate::mock::avatar().to_string(),
include_str!("test-resources/avatar")
);
assert_eq!(output, mock::avatar());
}
#[test]
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]
fn test_colour_from_string() {
assert_eq!(
Colour::from("0,255,0".to_string()),
Colour {
red: 0,
green: 255,
blue: 0
}
);
}
#[cfg(test)]
mod test {
use crate::colour::Colour;
#[test]
fn test_colour_to_string() {
assert_eq!(
Colour {
red: 22,
green: 33,
blue: 44
}
.to_string(),
"22,33,44".to_string()
);
#[test]
fn test_colour_from_string() {
assert_eq!(
Colour::from("0,255,0".to_string()),
Colour { red: 0, green: 255, blue: 0 }
);
}
#[test]
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]
fn test_dialogue_from_string() {
assert_eq!(
Dialogue::from("DLG h\nhello\ngoodbye".to_string()),
Dialogue {
id: "h".to_string(),
contents: "hello\ngoodbye".to_string()
}
)
}
#[cfg(test)]
mod test {
use crate::dialogue::Dialogue;
#[test]
fn test_dialogue_to_string() {
assert_eq!(
Dialogue {
#[test]
fn test_dialogue_from_string() {
assert_eq!(
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(),
contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string()
}
.to_string(),
"DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string()
);
}.to_string();
let expected = "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]
fn test_ending_from_string() {
assert_eq!(
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()
}
);
}
#[cfg(test)]
mod test {
use crate::ending::Ending;
#[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()
);
#[test]
fn test_ending_from_string() {
assert_eq!(
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]
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]
fn test_exit_from_string() {
assert_eq!(
Exit::from("a 12,13".to_string()),
Exit {
room_id: 10,
position: Position { x: 12, y: 13 },
effect: Transition::None
}
);
}
#[cfg(test)]
mod test {
use crate::exit::{Transition, Exit};
use crate::position::Position;
#[test]
fn test_exit_from_string_with_fx() {
assert_eq!(
Exit::from("a 12,13 FX slide_u".to_string()),
Exit {
room_id: 10,
position: Position { x: 12, y: 13 },
effect: Transition::SlideUp
}
);
}
#[test]
fn test_exit_from_string() {
assert_eq!(
Exit::from("a 12,13".to_string()),
Exit {
room_id: 10,
position: Position { x: 12, y: 13 },
effect: Transition::None
}
);
}
#[test]
fn test_exit_to_string() {
assert_eq!(
Exit {
room_id: 8,
position: Position { x: 5, y: 6 },
effect: Transition::None
}
.to_string(),
"8 5,6".to_string()
);
}
#[test]
fn test_exit_from_string_with_fx() {
assert_eq!(
Exit::from("a 12,13 FX slide_u".to_string()),
Exit {
room_id: 10,
position: Position { x: 12, y: 13 },
effect: Transition::SlideUp
}
);
}
#[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()
);
#[test]
fn test_exit_to_string() {
assert_eq!(
Exit {
room_id: 8,
position: Position { x: 5, y: 6 },
effect: Transition::None
}
.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]
fn test_game_from_string() {
let output = Game::from(include_str!["test-resources/default.bitsy"].to_string()).unwrap();
#[cfg(test)]
mod test {
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]
fn test_game_to_string() {
let output = crate::mock::game_default().to_string();
let expected = include_str!["test-resources/default.bitsy"].to_string();
assert_eq!(output, expected);
}
#[test]
fn test_game_to_string() {
let output = crate::mock::game_default().to_string();
let expected = include_str!["test-resources/default.bitsy"].to_string();
assert_eq!(output, expected);
}
#[test]
fn test_tile_ids() {
assert_eq!(crate::mock::game_default().tile_ids(), vec![10]);
}
#[test]
fn test_tile_ids() {
assert_eq!(crate::mock::game_default().tile_ids(), vec![10]);
}
#[test]
fn test_new_tile_id() {
// default tile has an id of 10 ("a"), so 0 is available
assert_eq!(crate::mock::game_default().new_tile_id(), 0);
#[test]
fn test_new_tile_id() {
// default tile has an id of 10 ("a"), so 0 is available
assert_eq!(crate::mock::game_default().new_tile_id(), 0);
let mut game = crate::mock::game_default();
let mut tiles: Vec<Tile> = Vec::new();
let mut game = crate::mock::game_default();
let mut tiles: Vec<Tile> = Vec::new();
for n in 0..9 {
if n != 4 {
let mut new_tile = crate::mock::tile_default();
new_tile.id = n;
tiles.push(new_tile);
for n in 0..9 {
if n != 4 {
let mut new_tile = crate::mock::tile_default();
new_tile.id = n;
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);
// 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;
assert_eq!(game.font, Font::Arabic);
assert_eq!(game.text_direction, TextDirection::RightToLeft);
}
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);
#[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"))
}
}
#[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]
fn test_image_from_string() {
let output = Image::from(include_str!("test-resources/image").to_string());
#[cfg(test)]
mod test {
use crate::image::Image;
let expected = Image {
pixels: vec![
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,
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,
],
};
#[test]
fn test_image_from_string() {
let output = Image::from(include_str!("test-resources/image").to_string());
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);
let expected = Image {
pixels: vec![
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, 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);
}
#[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]
fn test_item_from_string() {
let output = Item::from(include_str!("test-resources/item").to_string());
let expected = crate::mock::item();
assert_eq!(output, expected);
}
#[cfg(test)]
mod test {
use crate::item::Item;
use crate::mock;
#[test]
fn test_item_to_string() {
let output = crate::mock::item().to_string();
let expected = include_str!("test-resources/item").to_string();
assert_eq!(output, expected);
#[test]
fn test_item_from_string() {
let output = Item::from(include_str!("test-resources/item").to_string());
let expected = mock::item();
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()
}
#[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
fn to_base36(int: u64) -> String {
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`
fn optional_data_line<T: Display>(label: &str, item: Option<T>) -> String {
if item.is_some() {
@ -108,8 +96,25 @@ fn optional_data_line<T: Display>(label: &str, item: Option<T>) -> String {
}
}
#[test]
fn test_optional_data_line() {
let output = optional_data_line("NAME", mock::item().name);
assert_eq!(output, "\nNAME door".to_string());
#[cfg(test)]
mod test {
use crate::{from_base36, ToBase36, optional_data_line, mock};
#[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]
fn test_palette_from_string() {
let output = Palette::from("PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string());
#[cfg(test)]
mod test {
use crate::colour::Colour;
use crate::palette::Palette;
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]
fn test_palette_from_string() {
let output = Palette::from("PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string());
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]
fn test_palette_from_string_no_name() {
let output = Palette::from("PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string());
let expected = Palette {
id: 9,
name: None,
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);
}
#[test]
fn test_palette_to_string() {
let output = Palette {
id: 16,
name: Some("moss".to_string()),
colours: vec![
Colour {
red: 1,
green: 2,
blue: 3,
},
Colour {
red: 255,
green: 254,
blue: 253,
},
Colour {
red: 126,
green: 127,
blue: 128,
},
],
assert_eq!(output, expected);
}
#[test]
fn test_palette_from_string_no_name() {
let output = Palette::from("PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string());
let expected = Palette {
id: 9,
name: None,
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);
}
#[test]
fn test_palette_to_string() {
let output = Palette {
id: 16,
name: Some("moss".to_string()),
colours: vec![
Colour {
red: 1,
green: 2,
blue: 3,
},
Colour {
red: 255,
green: 254,
blue: 253,
},
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]
fn test_position_from_string() {
assert_eq!(
Position::from("4,12".to_string()).unwrap(),
Position { x: 4, y: 12 }
);
}
#[cfg(test)]
mod test {
use crate::position::Position;
#[test]
fn test_position_to_string() {
assert_eq!(Position { x: 4, y: 12 }.to_string(), "4,12".to_string())
#[test]
fn test_position_from_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 {
fn to_string(&self) -> String {
let mut tiles = String::new();
@ -191,17 +183,30 @@ impl ToString for Room {
}
}
#[test]
fn test_room_to_string() {
assert_eq!(
crate::mock::room().to_string(),
include_str!("test-resources/room").to_string()
);
}
#[cfg(test)]
mod test {
use crate::room::Room;
#[test]
fn test_room_walls_array() {
let output = Room::from(include_str!("test-resources/room-with-walls").to_string());
#[test]
fn test_room_from_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]
fn test_sprite_from_string() {
let output = Sprite::from(include_str!("test-resources/sprite").to_string());
#[cfg(test)]
mod test {
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);
}
#[test]
fn test_sprite_to_string() {
assert_eq!(
crate::mock::sprite().to_string(),
include_str!("test-resources/sprite").to_string()
);
assert_eq!(output, expected);
}
#[test]
fn test_sprite_to_string() {
assert_eq!(mock::sprite().to_string(), include_str!("test-resources/sprite").to_string());
}
}

View File

@ -88,38 +88,44 @@ impl ToString for Tile {
}
}
#[test]
fn test_tile_from_string() {
let output = Tile::from(include_str!("test-resources/tile").to_string());
#[cfg(test)]
mod test {
use crate::tile::Tile;
use crate::image::Image;
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]
fn test_tile_from_string() {
let output = Tile::from(include_str!("test-resources/tile").to_string());
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]
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,
assert_eq!(output, expected);
}
.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]
fn test_variable_from_string() {
assert_eq!(
Variable::from("VAR a\n42".to_string()),
Variable {
id: "a".to_string(),
initial_value: "42".to_string()
}
);
}
#[cfg(test)]
mod test {
use crate::variable::Variable;
#[test]
fn test_variable_to_string() {
let output = Variable {
id: "c".to_string(),
initial_value: "57".to_string(),
#[test]
fn test_variable_from_string() {
assert_eq!(
Variable::from("VAR a\n42".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);
}