47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
|
// same as a dialogue basically
|
||
|
#[derive(Debug, Eq, PartialEq)]
|
||
|
pub struct Ending {
|
||
|
id: String,
|
||
|
dialogue: String,
|
||
|
}
|
||
|
|
||
|
impl From<String> for Ending {
|
||
|
fn from(string: String) -> Ending {
|
||
|
let string = string.replace("END ", "");
|
||
|
let id_dialogue: Vec<&str> = string.lines().collect();
|
||
|
let id = id_dialogue[0].to_string();
|
||
|
let dialogue = id_dialogue[1].to_string();
|
||
|
|
||
|
Ending { id, dialogue }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl ToString for Ending {
|
||
|
#[inline]
|
||
|
fn to_string(&self) -> String {
|
||
|
format!("END {}\n{}", self.id, self.dialogue)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
fn test_ending_from_string() {
|
||
|
assert_eq!(
|
||
|
Ending::from(include_str!("../test/resources/ending").to_string()),
|
||
|
Ending {
|
||
|
id: "a".to_string(),
|
||
|
dialogue: "This is a long line of dialogue. Blah blah blah".to_string()
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
fn test_ending_to_string() {
|
||
|
assert_eq!(
|
||
|
Ending {
|
||
|
id: "7".to_string(),
|
||
|
dialogue: "This is another long ending. So long, farewell, etc.".to_string()
|
||
|
}.to_string(),
|
||
|
"END 7\nThis is another long ending. So long, farewell, etc.".to_string()
|
||
|
);
|
||
|
}
|