ending functions
This commit is contained in:
parent
e86625bbc8
commit
b9fecbe8fa
|
@ -22,13 +22,13 @@ a library for parsing Bitsy game data.
|
|||
* item to
|
||||
* exit from
|
||||
* exit to
|
||||
* ending from
|
||||
* ending to
|
||||
|
||||
## todo
|
||||
|
||||
### functions
|
||||
|
||||
* ending from
|
||||
* ending to
|
||||
* dialogue from
|
||||
* dialogue to
|
||||
* room from
|
||||
|
|
33
src/main.rs
33
src/main.rs
|
@ -79,7 +79,8 @@ struct Exit {
|
|||
// same as a dialogue basically
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
struct Ending {
|
||||
contents: String,
|
||||
id: String,
|
||||
dialogue: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
|
@ -599,11 +600,37 @@ fn test_exit_to_string() {
|
|||
}
|
||||
|
||||
fn ending_from_string(string: String) -> Ending {
|
||||
Ending { contents: "".to_string() }
|
||||
let string = string.replace("END ", "");
|
||||
let id_dialogue: Vec<&str> = string.split('\n').collect();
|
||||
let id = id_dialogue[0].to_string();
|
||||
let dialogue = id_dialogue[1].to_string();
|
||||
|
||||
Ending { id, dialogue }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ending_from_string() {
|
||||
assert_eq!(
|
||||
ending_from_string("END a\nThis is a long line of dialogue. Blah blah blah".to_string()),
|
||||
Ending { id: "a".to_string(), dialogue: "This is a long line of dialogue. Blah blah blah".to_string() }
|
||||
);
|
||||
}
|
||||
|
||||
fn ending_to_string(ending: Ending) -> String {
|
||||
"".to_string()
|
||||
format!("END {}\n{}", ending.id, ending.dialogue)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ending_to_string() {
|
||||
assert_eq!(
|
||||
ending_to_string(
|
||||
Ending {
|
||||
id: "7".to_string(),
|
||||
dialogue: "This is another long ending. So long, farewell, etc.".to_string()
|
||||
}
|
||||
),
|
||||
"END 7\nThis is another long ending. So long, farewell, etc.".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
fn room_from_string(string: String) -> Room {
|
||||
|
|
Loading…
Reference in New Issue