2020-04-12 12:52:36 +00:00
|
|
|
// same as a dialogue basically
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub struct Ending {
|
|
|
|
id: String,
|
|
|
|
dialogue: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for Ending {
|
2020-04-28 17:00:31 +00:00
|
|
|
#[inline]
|
2020-04-12 12:52:36 +00:00
|
|
|
fn from(string: String) -> Ending {
|
2020-04-23 05:50:38 +00:00
|
|
|
let lines: Vec<&str> = string.lines().collect();
|
|
|
|
let id = lines[0].replace("END ", "").to_string();
|
2020-04-23 05:57:07 +00:00
|
|
|
let dialogue = lines[1..].join("\n");
|
2020-04-12 12:52:36 +00:00
|
|
|
|
|
|
|
Ending { id, dialogue }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for Ending {
|
|
|
|
#[inline]
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
format!("END {}\n{}", self.id, self.dialogue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 07:13:55 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use crate::ending::Ending;
|
2020-04-12 12:52:36 +00:00
|
|
|
|
2020-04-19 07:13:55 +00:00
|
|
|
#[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()
|
|
|
|
);
|
|
|
|
}
|
2020-04-12 12:52:36 +00:00
|
|
|
}
|