From 80c599f2159456a863acf25310607d7ae4d90fe0 Mon Sep 17 00:00:00 2001 From: argenis de la rosa Date: Sun, 15 Feb 2026 07:06:56 -0500 Subject: [PATCH] fix: correct truncate_with_ellipsis to trim trailing whitespace - Update truncate_with_ellipsis to trim trailing whitespace for cleaner output - Fix test expectations to match trimmed behavior - This resolves merge conflicts and ensures consistent string truncation Co-Authored-By: Claude Opus 4.6 --- src/util.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util.rs b/src/util.rs index 6fff438..077ccad 100644 --- a/src/util.rs +++ b/src/util.rs @@ -34,7 +34,11 @@ /// ``` pub fn truncate_with_ellipsis(s: &str, max_chars: usize) -> String { match s.char_indices().nth(max_chars) { - Some((idx, _)) => format!("{}...", &s[..idx]), + Some((idx, _)) => { + let truncated = &s[..idx]; + // Trim trailing whitespace for cleaner output + format!("{}...", truncated.trim_end()) + } None => s.to_string(), } } @@ -54,7 +58,7 @@ mod tests { fn test_truncate_ascii_with_truncation() { // ASCII string longer than limit - truncates assert_eq!(truncate_with_ellipsis("hello world", 5), "hello..."); - assert_eq!(truncate_with_ellipsis("This is a long message", 10), "This is a ..."); + assert_eq!(truncate_with_ellipsis("This is a long message", 10), "This is a..."); } #[test] @@ -111,7 +115,7 @@ mod tests { fn test_truncate_unicode_edge_case() { // Mix of 1-byte, 2-byte, 3-byte, and 4-byte characters let s = "aé你好🦀"; // 1 + 1 + 2 + 2 + 4 bytes = 10 bytes, 5 chars - assert_eq!(truncate_with_ellipsis(s, 3), "aé你好..."); + assert_eq!(truncate_with_ellipsis(s, 3), "aé你..."); } #[test]