allow trailing spaces in dialogues

This commit is contained in:
Max Bradbury 2020-04-18 16:32:50 +01:00
parent 2e5d063371
commit 8b05645c6b
1 changed files with 7 additions and 9 deletions

View File

@ -35,7 +35,7 @@ pub struct Game {
impl From<String> for Game {
fn from(string: String) -> Game {
let mut string = format!("{}\n\n", string.trim());
let mut string = format!("{}\n\n", string.trim_matches('\n'));
if string.starts_with("# BITSY VERSION") {
string = format!("\n\n{}", string);
@ -76,7 +76,11 @@ impl From<String> for Game {
}
}
let dialogue_segments = format!("\n\nDLG {}", dialogues_endings_variables.trim());
let dialogue_segments = format!(
"\n\nDLG{}",
dialogues_endings_variables.trim_matches('\n')
);
let dialogue_segments: Vec<&str> = dialogue_segments.split("\n\nDLG").collect();
for segment in dialogue_segments[1..].to_owned() {
let segment = format!("DLG{}", segment);
@ -369,12 +373,6 @@ fn test_bitsy_omnibus() {
// 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(),
// one of the dialogues has a trailing space - todo this should be allowed I think
"src/test-resources/omnibus/11018B25.bitsy.txt".to_string(),
"src/test-resources/omnibus/FEC6E602.bitsy.txt".to_string(),
"src/test-resources/omnibus/3E8C3022.bitsy.txt".to_string(),
"src/test-resources/omnibus/F08D7D88.bitsy.txt".to_string(),
// has an ending position of -1
"src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(),
@ -410,7 +408,7 @@ fn test_bitsy_omnibus() {
println!("Testing: {}...", path.display());
let game_data = std::fs::read_to_string(path).unwrap();
let game = Game::from(game_data.clone());
assert_eq!(game.to_string().trim(), game_data.trim());
assert_eq!(game.to_string().trim_matches('\n'), game_data.trim_matches('\n'));
passes += 1;
println!("Success! {} passes, {} skips.", passes, skips);
}