test configurations
This commit is contained in:
parent
d0614b6de2
commit
76e6c2477c
|
@ -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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,27 +24,20 @@ impl ToString for Colour {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_colour_from_string() {
|
mod test {
|
||||||
|
use crate::colour::Colour;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_colour_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Colour::from("0,255,0".to_string()),
|
Colour::from("0,255,0".to_string()),
|
||||||
Colour {
|
Colour { red: 0, green: 255, blue: 0 }
|
||||||
red: 0,
|
|
||||||
green: 255,
|
|
||||||
blue: 0
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_colour_to_string() {
|
fn test_colour_to_string() {
|
||||||
assert_eq!(
|
assert_eq!(Colour { red: 22, green: 33, blue: 44, }.to_string(), "22,33,44".to_string());
|
||||||
Colour {
|
|
||||||
red: 22,
|
|
||||||
green: 33,
|
|
||||||
blue: 44
|
|
||||||
}
|
}
|
||||||
.to_string(),
|
|
||||||
"22,33,44".to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,25 +21,25 @@ impl ToString for Dialogue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_dialogue_from_string() {
|
mod test {
|
||||||
|
use crate::dialogue::Dialogue;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dialogue_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Dialogue::from("DLG h\nhello\ngoodbye".to_string()),
|
Dialogue::from("DLG h\nhello\ngoodbye".to_string()),
|
||||||
Dialogue {
|
Dialogue { id: "h".to_string(), contents: "hello\ngoodbye".to_string()}
|
||||||
id: "h".to_string(),
|
|
||||||
contents: "hello\ngoodbye".to_string()
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dialogue_to_string() {
|
fn test_dialogue_to_string() {
|
||||||
assert_eq!(
|
let output = Dialogue {
|
||||||
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();
|
||||||
|
let expected = "DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string();
|
||||||
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
.to_string(),
|
|
||||||
"DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,12 @@ impl ToString for Ending {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_ending_from_string() {
|
mod test {
|
||||||
|
use crate::ending::Ending;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ending_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Ending::from(include_str!("test-resources/ending").to_string()),
|
Ending::from(include_str!("test-resources/ending").to_string()),
|
||||||
Ending {
|
Ending {
|
||||||
|
@ -39,16 +43,16 @@ fn test_ending_from_string() {
|
||||||
dialogue: "This is a long line of dialogue. Blah blah blah".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_to_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Ending {
|
Ending {
|
||||||
id: "7".to_string(),
|
id: "7".to_string(),
|
||||||
dialogue: "This is another long ending. So long, farewell, etc.".to_string()
|
dialogue: "This is another long ending. So long, farewell, etc.".to_string()
|
||||||
}
|
}.to_string(),
|
||||||
.to_string(),
|
|
||||||
"END 7\nThis is another long ending. So long, farewell, etc.".to_string()
|
"END 7\nThis is another long ending. So long, farewell, etc.".to_string()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
28
src/exit.rs
28
src/exit.rs
|
@ -87,8 +87,13 @@ impl ToString for Exit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_exit_from_string() {
|
mod test {
|
||||||
|
use crate::exit::{Transition, Exit};
|
||||||
|
use crate::position::Position;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_exit_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Exit::from("a 12,13".to_string()),
|
Exit::from("a 12,13".to_string()),
|
||||||
Exit {
|
Exit {
|
||||||
|
@ -97,10 +102,10 @@ fn test_exit_from_string() {
|
||||||
effect: Transition::None
|
effect: Transition::None
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exit_from_string_with_fx() {
|
fn test_exit_from_string_with_fx() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Exit::from("a 12,13 FX slide_u".to_string()),
|
Exit::from("a 12,13 FX slide_u".to_string()),
|
||||||
Exit {
|
Exit {
|
||||||
|
@ -109,10 +114,10 @@ fn test_exit_from_string_with_fx() {
|
||||||
effect: Transition::SlideUp
|
effect: Transition::SlideUp
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exit_to_string() {
|
fn test_exit_to_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Exit {
|
Exit {
|
||||||
room_id: 8,
|
room_id: 8,
|
||||||
|
@ -122,10 +127,10 @@ fn test_exit_to_string() {
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"8 5,6".to_string()
|
"8 5,6".to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exit_to_string_with_fx() {
|
fn test_exit_to_string_with_fx() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Exit {
|
Exit {
|
||||||
room_id: 8,
|
room_id: 8,
|
||||||
|
@ -135,4 +140,5 @@ fn test_exit_to_string_with_fx() {
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"8 5,6 FX fade_w".to_string()
|
"8 5,6 FX fade_w".to_string()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
54
src/game.rs
54
src/game.rs
|
@ -300,29 +300,34 @@ 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;
|
||||||
|
|
||||||
|
#[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();
|
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);
|
||||||
|
|
||||||
|
@ -348,10 +353,10 @@ fn test_new_tile_id() {
|
||||||
game.tiles.push(new_tile);
|
game.tiles.push(new_tile);
|
||||||
|
|
||||||
assert_eq!(game.new_tile_id(), 10);
|
assert_eq!(game.new_tile_id(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_add_tile() {
|
fn test_add_tile() {
|
||||||
let mut game = crate::mock::game_default();
|
let mut game = crate::mock::game_default();
|
||||||
let new_id = game.add_tile(crate::mock::tile_default());
|
let new_id = game.add_tile(crate::mock::tile_default());
|
||||||
assert_eq!(new_id, 0);
|
assert_eq!(new_id, 0);
|
||||||
|
@ -359,10 +364,10 @@ fn test_add_tile() {
|
||||||
let new_id = game.add_tile(crate::mock::tile_default());
|
let new_id = game.add_tile(crate::mock::tile_default());
|
||||||
assert_eq!(new_id, 1);
|
assert_eq!(new_id, 1);
|
||||||
assert_eq!(game.tiles.len(), 3);
|
assert_eq!(game.tiles.len(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bitsy_omnibus() {
|
fn test_bitsy_omnibus() {
|
||||||
let acceptable_failures: Vec<String> = vec![
|
let acceptable_failures: Vec<String> = vec![
|
||||||
// fails because of sprite colours but also because a tile contains "NaN"
|
// fails because of sprite colours but also because a tile contains "NaN"
|
||||||
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
|
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
|
||||||
|
@ -421,19 +426,20 @@ fn test_bitsy_omnibus() {
|
||||||
passes += 1;
|
passes += 1;
|
||||||
println!("Success! {} passes, {} skips.", passes, skips);
|
println!("Success! {} passes, {} skips.", passes, skips);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_arabic() {
|
fn test_arabic() {
|
||||||
let game = Game::from(include_str!("test-resources/arabic.bitsy").to_string()).unwrap();
|
let game = Game::from(include_str!("test-resources/arabic.bitsy").to_string()).unwrap();
|
||||||
|
|
||||||
assert_eq!(game.font, Font::Arabic);
|
assert_eq!(game.font, Font::Arabic);
|
||||||
assert_eq!(game.text_direction, TextDirection::RightToLeft);
|
assert_eq!(game.text_direction, TextDirection::RightToLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_version_formatting() {
|
fn test_version_formatting() {
|
||||||
let mut game = crate::mock::game_default();
|
let mut game = crate::mock::game_default();
|
||||||
game.version = Version { major: 5, minor: 0 };
|
game.version = Version { major: 5, minor: 0 };
|
||||||
assert!(game.to_string().contains("# BITSY VERSION 5.0"))
|
assert!(game.to_string().contains("# BITSY VERSION 5.0"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
28
src/image.rs
28
src/image.rs
|
@ -38,24 +38,34 @@ impl ToString for Image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_image_from_string() {
|
mod test {
|
||||||
|
use crate::image::Image;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_image_from_string() {
|
||||||
let output = Image::from(include_str!("test-resources/image").to_string());
|
let output = Image::from(include_str!("test-resources/image").to_string());
|
||||||
|
|
||||||
let expected = Image {
|
let expected = Image {
|
||||||
pixels: vec![
|
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, 1, 1,
|
1, 1, 0, 0, 1, 1, 1, 1,
|
||||||
1, 1, 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)
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_image_to_string() {
|
fn test_image_to_string() {
|
||||||
let output = crate::mock::image::chequers_1().to_string();
|
let output = crate::mock::image::chequers_1().to_string();
|
||||||
let expected = include_str!("test-resources/image-chequers-1").to_string();
|
let expected = include_str!("test-resources/image-chequers-1").to_string();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
24
src/item.rs
24
src/item.rs
|
@ -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 = 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();
|
let expected = include_str!("test-resources/item").to_string();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
33
src/lib.rs
33
src/lib.rs
|
@ -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 {
|
||||||
|
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);
|
let output = optional_data_line("NAME", mock::item().name);
|
||||||
assert_eq!(output, "\nNAME door".to_string());
|
assert_eq!(output, "\nNAME door".to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,13 @@ impl ToString for Palette {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_palette_from_string() {
|
mod test {
|
||||||
|
use crate::colour::Colour;
|
||||||
|
use crate::palette::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());
|
let output = Palette::from("PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string());
|
||||||
|
|
||||||
let expected = Palette {
|
let expected = Palette {
|
||||||
|
@ -76,10 +81,10 @@ fn test_palette_from_string() {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_palette_from_string_no_name() {
|
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 output = Palette::from("PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string());
|
||||||
|
|
||||||
let expected = Palette {
|
let expected = Palette {
|
||||||
|
@ -105,10 +110,10 @@ fn test_palette_from_string_no_name() {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_palette_to_string() {
|
fn test_palette_to_string() {
|
||||||
let output = Palette {
|
let output = Palette {
|
||||||
id: 16,
|
id: 16,
|
||||||
name: Some("moss".to_string()),
|
name: Some("moss".to_string()),
|
||||||
|
@ -133,4 +138,5 @@ fn test_palette_to_string() {
|
||||||
.to_string();
|
.to_string();
|
||||||
let expected = "PAL g\nNAME moss\n1,2,3\n255,254,253\n126,127,128".to_string();
|
let expected = "PAL g\nNAME moss\n1,2,3\n255,254,253\n126,127,128".to_string();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,15 +29,20 @@ impl ToString for Position {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_position_from_string() {
|
mod test {
|
||||||
|
use crate::position::Position;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_position_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Position::from("4,12".to_string()).unwrap(),
|
Position::from("4,12".to_string()).unwrap(),
|
||||||
Position { x: 4, y: 12 }
|
Position { x: 4, y: 12 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_position_to_string() {
|
fn test_position_to_string() {
|
||||||
assert_eq!(Position { x: 4, y: 12 }.to_string(), "4,12".to_string())
|
assert_eq!(Position { x: 4, y: 12 }.to_string(), "4,12".to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
31
src/room.rs
31
src/room.rs
|
@ -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 {
|
||||||
|
use crate::room::Room;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_room_from_string() {
|
||||||
|
assert_eq!(
|
||||||
|
Room::from(include_str!("test-resources/room").to_string()),
|
||||||
|
crate::mock::room()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_room_to_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::mock::room().to_string(),
|
crate::mock::room().to_string(),
|
||||||
include_str!("test-resources/room").to_string()
|
include_str!("test-resources/room").to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_room_walls_array() {
|
fn test_room_walls_array() {
|
||||||
let output = Room::from(include_str!("test-resources/room-with-walls").to_string());
|
let output = Room::from(include_str!("test-resources/room-with-walls").to_string());
|
||||||
|
|
||||||
assert_eq!(output.walls, vec![10, 15]);
|
assert_eq!(output.walls, vec![10, 15]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
16
src/tile.rs
16
src/tile.rs
|
@ -88,8 +88,13 @@ impl ToString for Tile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_tile_from_string() {
|
mod test {
|
||||||
|
use crate::tile::Tile;
|
||||||
|
use crate::image::Image;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tile_from_string() {
|
||||||
let output = Tile::from(include_str!("test-resources/tile").to_string());
|
let output = Tile::from(include_str!("test-resources/tile").to_string());
|
||||||
|
|
||||||
let expected = Tile {
|
let expected = Tile {
|
||||||
|
@ -103,10 +108,10 @@ fn test_tile_from_string() {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tile_to_string() {
|
fn test_tile_to_string() {
|
||||||
let output = Tile {
|
let output = Tile {
|
||||||
id: 262,
|
id: 262,
|
||||||
name: Some("chequers".to_string()),
|
name: Some("chequers".to_string()),
|
||||||
|
@ -122,4 +127,5 @@ fn test_tile_to_string() {
|
||||||
let expected = include_str!("test-resources/tile-chequers").to_string();
|
let expected = include_str!("test-resources/tile-chequers").to_string();
|
||||||
|
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,12 @@ impl ToString for Variable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_variable_from_string() {
|
mod test {
|
||||||
|
use crate::variable::Variable;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_variable_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Variable::from("VAR a\n42".to_string()),
|
Variable::from("VAR a\n42".to_string()),
|
||||||
Variable {
|
Variable {
|
||||||
|
@ -30,10 +34,10 @@ fn test_variable_from_string() {
|
||||||
initial_value: "42".to_string()
|
initial_value: "42".to_string()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_variable_to_string() {
|
fn test_variable_to_string() {
|
||||||
let output = Variable {
|
let output = Variable {
|
||||||
id: "c".to_string(),
|
id: "c".to_string(),
|
||||||
initial_value: "57".to_string(),
|
initial_value: "57".to_string(),
|
||||||
|
@ -41,4 +45,5 @@ fn test_variable_to_string() {
|
||||||
.to_string();
|
.to_string();
|
||||||
let expected = "VAR c\n57".to_string();
|
let expected = "VAR c\n57".to_string();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue