From 96317393721830a65999763d2f8992a116612658 Mon Sep 17 00:00:00 2001 From: mgros Date: Fri, 25 Sep 2026 04:14:22 +0200 Subject: [PATCH 1/3] replace buggy Display implementation for Pronounce with Debug trait --- src/tts.rs | 57 +++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/tts.rs b/src/tts.rs index c2f951b39..441fc70bd 100644 --- a/src/tts.rs +++ b/src/tts.rs @@ -118,32 +118,6 @@ pub struct Pronounce { } -impl fmt::Display for Pronounce { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut comma = ""; // comma separator so it looks right - write!(f, "pronounce: [")?; - if !self.text.is_empty() { - write!(f, "text: '{}'", self.text)?; - comma = ","; - } - write!(f, "pronounce: [")?; - if !self.ipa.is_empty() { - write!(f, "{}ipa: '{}'", comma, self.ipa)?; - comma = ","; - } - write!(f, "pronounce: [")?; - if !self.sapi5.is_empty() { - write!(f, "{}sapi5: '{}'", comma, self.sapi5)?; - comma = ","; - } - write!(f, "pronounce: [")?; - if !self.eloquence.is_empty() { - write!(f, "{}eloquence: '{}'", comma, self.eloquence)?; - } - return writeln!(f, "]"); - } -} - impl Pronounce { fn build(values: &Yaml) -> Result { use crate::speech::{as_str_checked, yaml_to_type}; @@ -232,7 +206,7 @@ impl fmt::Display for TTSCommandRule { TTSCommandValue::String(s) => s.to_string(), TTSCommandValue::Number(f) => f.to_string(), TTSCommandValue::XPath(p) => p.to_string(), - TTSCommandValue::Pronounce(p) => p.to_string(), + TTSCommandValue::Pronounce(p) => format!("{p:?}"), }; if self.command == TTSCommand::Pause { return write!(f, "pause: {value}"); @@ -789,10 +763,31 @@ mod tests { let rule = TTS::build("pronounce", values).unwrap(); let rendered = format!("{rule}"); - assert!(rendered.contains("text: 'alpha'")); - assert!(rendered.contains("ipa: 'a'")); - assert!(rendered.contains("sapi5: 'b'")); - assert!(rendered.contains("eloquence: 'c'")); + assert!(rendered.contains("text: \"alpha\"")); + assert!(rendered.contains("ipa: \"a\"")); + assert!(rendered.contains("sapi5: \"b\"")); + assert!(rendered.contains("eloquence: \"c\"")); + } + + /// Shows the derived pronunciation details when displaying a TTS rule. + #[test] + fn pronounce_rule_display_uses_debug_fields() { + let pronounce = Pronounce { + text: "bli bla blub".to_string(), + ipa: "a".to_string(), + sapi5: "b".to_string(), + eloquence: "c".to_string(), + }; + let rule = TTSCommandRule::new( + TTSCommand::Pronounce, + TTSCommandValue::Pronounce(Box::new(pronounce)), + ReplacementArray::build_empty(), + ); + + assert_eq!( + rule.to_string(), + "pronounce: Pronounce { text: \"bli bla blub\", ipa: \"a\", sapi5: \"b\", eloquence: \"c\" }\n" + ); } #[test] From cb59fad226b2411b6ca681ea20216a3fd0a922c2 Mon Sep 17 00:00:00 2001 From: mgros Date: Sat, 26 Sep 2026 03:16:03 +0200 Subject: [PATCH 2/3] remove unused `eloquence` field and related code from `Pronounce` struct --- src/tts.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/tts.rs b/src/tts.rs index 441fc70bd..fa96f61af 100644 --- a/src/tts.rs +++ b/src/tts.rs @@ -114,7 +114,7 @@ pub struct Pronounce { text: String, // plain text ipa: String, // ipa sapi5: String, - eloquence: String, + // eloquence: String, } @@ -126,7 +126,6 @@ impl Pronounce { let mut text = ""; let mut ipa = ""; let mut sapi5 = ""; - let mut eloquence = ""; // values should be an array with potential values for Pronounce let values = values.as_vec().ok_or_else(|| anyhow!("'pronounce' value '{}' is not an array", yaml_to_type(values)))?; @@ -142,7 +141,7 @@ impl Pronounce { "text" => text = as_str_checked(value)?, "ipa" => ipa = as_str_checked(value)?, "sapi5" => sapi5 = as_str_checked(value)?, - "eloquence" => eloquence = as_str_checked(value)?, + "eloquence" => { as_str_checked(value)?; }, _ => bail!("unknown pronounce type: {} with value {}", yaml_to_string(key, 0), yaml_to_string(value, 0)), } } @@ -154,7 +153,7 @@ impl Pronounce { text: text.to_string(), ipa: ipa.to_string(), sapi5: sapi5.to_string(), - eloquence: eloquence.to_string() + // eloquence: eloquence.to_string() } ); @@ -766,7 +765,7 @@ mod tests { assert!(rendered.contains("text: \"alpha\"")); assert!(rendered.contains("ipa: \"a\"")); assert!(rendered.contains("sapi5: \"b\"")); - assert!(rendered.contains("eloquence: \"c\"")); + assert!(!rendered.contains("eloquence")); } /// Shows the derived pronunciation details when displaying a TTS rule. @@ -776,7 +775,6 @@ mod tests { text: "bli bla blub".to_string(), ipa: "a".to_string(), sapi5: "b".to_string(), - eloquence: "c".to_string(), }; let rule = TTSCommandRule::new( TTSCommand::Pronounce, @@ -786,7 +784,7 @@ mod tests { assert_eq!( rule.to_string(), - "pronounce: Pronounce { text: \"bli bla blub\", ipa: \"a\", sapi5: \"b\", eloquence: \"c\" }\n" + "pronounce: Pronounce { text: \"bli bla blub\", ipa: \"a\", sapi5: \"b\" }\n" ); } From 17d3f04afc1aa563a17050ce0935dc68d1bfac53 Mon Sep 17 00:00:00 2001 From: mgros Date: Sat, 26 Sep 2026 03:27:22 +0200 Subject: [PATCH 3/3] fix outdated syntax --- src/tts.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tts.rs b/src/tts.rs index 6ab8e6485..0c26e52c7 100644 --- a/src/tts.rs +++ b/src/tts.rs @@ -770,11 +770,11 @@ mod tests { ipa: "a".to_string(), sapi5: "b".to_string(), }; - let rule = TTSCommandRule::new( - TTSCommand::Pronounce, - TTSCommandValue::Pronounce(Box::new(pronounce)), - ReplacementArray::build_empty(), - ); + let rule = TTSCommandRule { + command: TTSCommand::Pronounce, + value: TTSCommandValue::Pronounce(Box::new(pronounce)), + replacements: ReplacementArray::build_empty(), + }; assert_eq!( rule.to_string(),