From b8d8f7c39b9135203bcd523d764a83d28a2a3a76 Mon Sep 17 00:00:00 2001 From: dmyTRUEk <25669613+dmyTRUEk@users.noreply.github.com> Date: Sat, 30 Mar 2024 00:13:37 +0200 Subject: [PATCH] fix: missing source for some quotes, add tests to prevent this in future fixes #6 --- data/quotes.txt | 22 +++++++++++++++ generate_quotes.py | 11 ++++++++ src/main.rs | 1 + src/quotes.rs | 66 ++++++++++++++++++++++++++++++--------------- src/quotes_tests.rs | 25 +++++++++++++++++ 5 files changed, 103 insertions(+), 22 deletions(-) create mode 100644 src/quotes_tests.rs diff --git a/data/quotes.txt b/data/quotes.txt index 2d89794..64880b4 100644 --- a/data/quotes.txt +++ b/data/quotes.txt @@ -3161,89 +3161,111 @@ Double Dealing Character Actually, ya did surprise me there when your head took off. Marisa Kirisame +Double Dealing Character whom_to: Sekibanki Do you want to see me do that again? Sekibanki +Double Dealing Character whom_to: Marisa Kirisame Wh-What's with you? You're actually strong! Sekibanki +Double Dealing Character whom_to: Marisa Kirisame 'Course I am. If I were weak, I'd be sleepin' at home. Marisa Kirisame +Double Dealing Character whom_to: Sekibanki A mermaid in the lake? Do you mean Wakasagihime? Kagerou Imaizumi +Double Dealing Character whom_to: Marisa Kirisame Yeah. Do ya know each other? Marisa Kirisame +Double Dealing Character whom_to: Kagerou Imaizumi Somewhat, thanks to the grassroots youkai network. Though I also tried to eat her once by mistake. Kagerou Imaizumi +Double Dealing Character whom_to: Marisa Kirisame Did I even once say that I was weak? But... My expectations were off. Sakuya Izayoi +Double Dealing Character whom_to: Sekibanki Wh-What do you mean? Sekibanki +Double Dealing Character whom_to: Sakuya Izayoi Because I never needed to cut off your neck at all. Sakuya Izayoi +Double Dealing Character whom_to: Sekibanki Gyah! Sekibanki +Double Dealing Character whom_to: Sakuya Izayoi Do you think you can defeat me? Kagerou Imaizumi +Double Dealing Character whom_to: Sakuya Izayoi Yes, I believe I can. Sakuya Izayoi +Double Dealing Character whom_to: Kagerou Imaizumi O-Oh, a quick answer. Kagerou Imaizumi +Double Dealing Character whom_to: Sakuya Izayoi Who should it be but a wolfman! Sakuya Izayoi +Double Dealing Character whom_to: Kagerou Imaizumi I'm a wolf-woman! Kagerou Imaizumi +Double Dealing Character whom_to: Sakuya Izayoi Well, either way. Your blood will coat my knife. Sakuya Izayoi +Double Dealing Character whom_to: Kagerou Imaizumi Eek! Kagerou Imaizumi +Double Dealing Character whom_to: Sakuya Izayoi The drummers in the outside world have a saying. \"Awaken your caveman spirit, for it doesn't need brains to beat a drum!\" Raiko Horikawa +Double Dealing Character whom_to: Reimu Hakurei Huh...The outside world seems barbaric. Reimu Hakurei +Double Dealing Character whom_to: Raiko Horikawa I don't want to go back to a life of being hit and stepped on. Raiko Horikawa +Double Dealing Character whom_to: Sakuya Izayoi You are a drum, yes? How could you not want to be hit? Sakuya Izayoi +Double Dealing Character whom_to: Raiko Horikawa diff --git a/generate_quotes.py b/generate_quotes.py index b002cc4..a97337c 100644 --- a/generate_quotes.py +++ b/generate_quotes.py @@ -1,6 +1,7 @@ # generate rust quotes file from dataclasses import dataclass +from pprint import pprint from generate_lib import * @@ -77,6 +78,7 @@ class Quote: whom_about: None | str def to_lines(self) -> list[str]: + assert self.is_ok() lines = [ "\tQuote {", f"\t\ttext: \"{self.text}\",", @@ -94,6 +96,15 @@ def to_lines(self) -> list[str]: lines.append("\t},") return lines + def is_ok(self) -> bool: + unwanted = ["text:", "char:", "src:", "whom_to", "whom_about", "\n", "\t"] + for field, value in vars(self).items(): + if value is not None: + if any(map(lambda unwanted: unwanted in value, unwanted)): + pprint(self) + return False + return True + if __name__ == "__main__": diff --git a/src/main.rs b/src/main.rs index cd8e20d..2f5d112 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod characters; mod format; mod quote; mod quotes; +mod quotes_tests; mod to_str; use crate::{ diff --git a/src/quotes.rs b/src/quotes.rs index ce57288..c2af07b 100644 --- a/src/quotes.rs +++ b/src/quotes.rs @@ -4615,85 +4615,99 @@ pub const QUOTES: &[Quote] = &[ Quote { text: "Actually, ya did surprise me there when your head took off.", char: Marisa_Kirisame, - src: "whom_to: Sekibanki", + src: "Double Dealing Character", + whom_to: Some(Sekibanki), ..Quote::default() }, Quote { text: "Do you want to see me do that again?", char: Sekibanki, - src: "whom_to: Marisa Kirisame", + src: "Double Dealing Character", + whom_to: Some(Marisa_Kirisame), ..Quote::default() }, Quote { text: "Wh-What's with you? You're actually strong!", char: Sekibanki, - src: "whom_to: Marisa Kirisame", + src: "Double Dealing Character", + whom_to: Some(Marisa_Kirisame), ..Quote::default() }, Quote { text: "'Course I am. If I were weak, I'd be sleepin' at home.", char: Marisa_Kirisame, - src: "whom_to: Sekibanki", + src: "Double Dealing Character", + whom_to: Some(Sekibanki), ..Quote::default() }, Quote { text: "A mermaid in the lake? Do you mean Wakasagihime?", char: Kagerou_Imaizumi, - src: "whom_to: Marisa Kirisame", + src: "Double Dealing Character", + whom_to: Some(Marisa_Kirisame), ..Quote::default() }, Quote { text: "Yeah. Do ya know each other?", char: Marisa_Kirisame, - src: "whom_to: Kagerou Imaizumi", + src: "Double Dealing Character", + whom_to: Some(Kagerou_Imaizumi), ..Quote::default() }, Quote { text: "Somewhat, thanks to the grassroots youkai network. Though I also tried to eat her once by mistake.", char: Kagerou_Imaizumi, - src: "whom_to: Marisa Kirisame", + src: "Double Dealing Character", + whom_to: Some(Marisa_Kirisame), ..Quote::default() }, Quote { text: "Did I even once say that I was weak? But... My expectations were off.", char: Sakuya_Izayoi, - src: "whom_to: Sekibanki", + src: "Double Dealing Character", + whom_to: Some(Sekibanki), ..Quote::default() }, Quote { text: "Wh-What do you mean?", char: Sekibanki, - src: "whom_to: Sakuya Izayoi", + src: "Double Dealing Character", + whom_to: Some(Sakuya_Izayoi), ..Quote::default() }, Quote { text: "Because I never needed to cut off your neck at all.", char: Sakuya_Izayoi, - src: "whom_to: Sekibanki", + src: "Double Dealing Character", + whom_to: Some(Sekibanki), ..Quote::default() }, Quote { text: "Gyah!", char: Sekibanki, - src: "whom_to: Sakuya Izayoi", + src: "Double Dealing Character", + whom_to: Some(Sakuya_Izayoi), ..Quote::default() }, Quote { text: "Do you think you can defeat me?", char: Kagerou_Imaizumi, - src: "whom_to: Sakuya Izayoi", + src: "Double Dealing Character", + whom_to: Some(Sakuya_Izayoi), ..Quote::default() }, Quote { text: "Yes, I believe I can.", char: Sakuya_Izayoi, - src: "whom_to: Kagerou Imaizumi", + src: "Double Dealing Character", + whom_to: Some(Kagerou_Imaizumi), ..Quote::default() }, Quote { text: "O-Oh, a quick answer.", char: Kagerou_Imaizumi, - src: "whom_to: Sakuya Izayoi", + src: "Double Dealing Character", + whom_to: Some(Sakuya_Izayoi), ..Quote::default() }, @@ -4701,49 +4715,57 @@ pub const QUOTES: &[Quote] = &[ Quote { text: "Who should it be but a wolfman!", char: Sakuya_Izayoi, - src: "whom_to: Kagerou Imaizumi", + src: "Double Dealing Character", + whom_to: Some(Kagerou_Imaizumi), ..Quote::default() }, Quote { text: "I'm a wolf-woman!", char: Kagerou_Imaizumi, - src: "whom_to: Sakuya Izayoi", + src: "Double Dealing Character", + whom_to: Some(Sakuya_Izayoi), ..Quote::default() }, Quote { text: "Well, either way. Your blood will coat my knife.", char: Sakuya_Izayoi, - src: "whom_to: Kagerou Imaizumi", + src: "Double Dealing Character", + whom_to: Some(Kagerou_Imaizumi), ..Quote::default() }, Quote { text: "Eek!", char: Kagerou_Imaizumi, - src: "whom_to: Sakuya Izayoi", + src: "Double Dealing Character", + whom_to: Some(Sakuya_Izayoi), ..Quote::default() }, Quote { text: "The drummers in the outside world have a saying. \"Awaken your caveman spirit, for it doesn't need brains to beat a drum!\"", char: Raiko_Horikawa, - src: "whom_to: Reimu Hakurei", + src: "Double Dealing Character", + whom_to: Some(Reimu_Hakurei), ..Quote::default() }, Quote { text: "Huh...The outside world seems barbaric.", char: Reimu_Hakurei, - src: "whom_to: Raiko Horikawa", + src: "Double Dealing Character", + whom_to: Some(Raiko_Horikawa), ..Quote::default() }, Quote { text: "I don't want to go back to a life of being hit and stepped on.", char: Raiko_Horikawa, - src: "whom_to: Sakuya Izayoi", + src: "Double Dealing Character", + whom_to: Some(Sakuya_Izayoi), ..Quote::default() }, Quote { text: "You are a drum, yes? How could you not want to be hit?", char: Sakuya_Izayoi, - src: "whom_to: Raiko Horikawa", + src: "Double Dealing Character", + whom_to: Some(Raiko_Horikawa), ..Quote::default() }, ]; diff --git a/src/quotes_tests.rs b/src/quotes_tests.rs new file mode 100644 index 0000000..f8ed040 --- /dev/null +++ b/src/quotes_tests.rs @@ -0,0 +1,25 @@ +//! Tests for `quotes.rs` + +#[cfg(test)] +mod tests { + use crate::{quote::Quote, quotes::QUOTES}; + + #[test] + fn dont_contain_unwanted_text() { + const UNWANTED: &[&str] = &[ + "text:", + "char:", + "src:", + "whom_to", + "whom_about", + "\n", + "\t", + ]; + for Quote { text, src, .. } in QUOTES { + for unwanted in UNWANTED { + assert!(!text.to_lowercase().contains(unwanted), "unwanted=`{unwanted}`, text=`{text}`"); + assert!(!src.to_lowercase().contains(unwanted), "unwanted=`{unwanted}`, src=`{src}`"); + } + } + } +}