From 8b05645c6b422b420c92a36a22f5cea01425017c Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sat, 18 Apr 2020 16:32:50 +0100 Subject: [PATCH] allow trailing spaces in dialogues --- src/game.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/game.rs b/src/game.rs index 0e8a442..5d3fb0f 100644 --- a/src/game.rs +++ b/src/game.rs @@ -35,7 +35,7 @@ pub struct Game { impl From 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 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); }