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();
|
||||||
|
|
||||||
|
assert_eq!(output, mock::avatar());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_avatar_to_string() {
|
fn avatar_to_string() {
|
||||||
assert_eq!(
|
assert_eq!(mock::avatar().to_string(), include_str!("test-resources/avatar"));
|
||||||
crate::mock::avatar().to_string(),
|
}
|
||||||
include_str!("test-resources/avatar")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,27 +24,20 @@ impl ToString for Colour {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::colour::Colour;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_colour_from_string() {
|
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 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::dialogue::Dialogue;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dialogue_from_string() {
|
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,6 +30,10 @@ impl ToString for Ending {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::ending::Ending;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ending_from_string() {
|
fn test_ending_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -47,8 +51,8 @@ fn test_ending_to_string() {
|
||||||
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()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -87,6 +87,11 @@ impl ToString for Exit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::exit::{Transition, Exit};
|
||||||
|
use crate::position::Position;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exit_from_string() {
|
fn test_exit_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -136,3 +141,4 @@ fn test_exit_to_string_with_fx() {
|
||||||
"8 5,6 FX fade_w".to_string()
|
"8 5,6 FX fade_w".to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -300,10 +300,15 @@ impl Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::game::{Version, Game};
|
||||||
|
use crate::text::{TextDirection, Font};
|
||||||
|
use crate::tile::Tile;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_game_from_string() {
|
fn test_game_from_string() {
|
||||||
let output = Game::from(include_str!["test-resources/default.bitsy"].to_string()).unwrap();
|
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);
|
||||||
|
@ -437,3 +442,4 @@ fn test_version_formatting() {
|
||||||
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"))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
18
src/image.rs
18
src/image.rs
|
@ -38,19 +38,28 @@ impl ToString for Image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::image::Image;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_image_from_string() {
|
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]
|
||||||
|
@ -59,3 +68,4 @@ fn test_image_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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
10
src/item.rs
10
src/item.rs
|
@ -79,16 +79,22 @@ impl ToString for Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::item::Item;
|
||||||
|
use crate::mock;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_item_from_string() {
|
fn test_item_from_string() {
|
||||||
let output = Item::from(include_str!("test-resources/item").to_string());
|
let output = Item::from(include_str!("test-resources/item").to_string());
|
||||||
let expected = crate::mock::item();
|
let expected = mock::item();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_item_to_string() {
|
fn test_item_to_string() {
|
||||||
let output = crate::mock::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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
29
src/lib.rs
29
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 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[test]
|
||||||
fn test_optional_data_line() {
|
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,6 +49,11 @@ impl ToString for Palette {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::colour::Colour;
|
||||||
|
use crate::palette::Palette;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_palette_from_string() {
|
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());
|
||||||
|
@ -134,3 +139,4 @@ fn test_palette_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,6 +29,10 @@ impl ToString for Position {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::position::Position;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_position_from_string() {
|
fn test_position_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -41,3 +45,4 @@ fn test_position_from_string() {
|
||||||
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())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
21
src/room.rs
21
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,6 +183,18 @@ impl ToString for Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
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]
|
#[test]
|
||||||
fn test_room_to_string() {
|
fn test_room_to_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -205,3 +209,4 @@ fn test_room_walls_array() {
|
||||||
|
|
||||||
assert_eq!(output.walls, vec![10, 15]);
|
assert_eq!(output.walls, vec![10, 15]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -108,19 +108,21 @@ impl ToString for Sprite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::mock;
|
||||||
|
use crate::sprite::Sprite;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sprite_from_string() {
|
fn test_sprite_from_string() {
|
||||||
let output = Sprite::from(include_str!("test-resources/sprite").to_string());
|
let output = Sprite::from(include_str!("test-resources/sprite").to_string());
|
||||||
|
let expected = mock::sprite();
|
||||||
let expected = crate::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()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,11 @@ impl ToString for Tile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::tile::Tile;
|
||||||
|
use crate::image::Image;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tile_from_string() {
|
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());
|
||||||
|
@ -123,3 +128,4 @@ fn test_tile_to_string() {
|
||||||
|
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ impl ToString for Variable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::variable::Variable;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_variable_from_string() {
|
fn test_variable_from_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -42,3 +46,4 @@ fn test_variable_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