Skip to content

Commit 19411fa

Browse files
committed
Restore original test_truncate_description test
- Restore ASCII text test cases that were accidentally removed - Keep both original and new CJK-specific tests for comprehensive coverage - Ensures backward compatibility verification
1 parent e914ffb commit 19411fa

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

crates/chat-cli/src/cli/chat/cli/prompts.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,12 +2522,35 @@ mod tests {
25222522
}
25232523

25242524
#[test]
2525-
fn test_truncate_description_ascii() {
2526-
// Test with ASCII text
2527-
assert_eq!(truncate_description("Hello World", 20), "Hello World");
2528-
assert_eq!(truncate_description("Hello World", 11), "Hello World");
2529-
assert_eq!(truncate_description("Hello World", 8), "Hello...");
2530-
assert_eq!(truncate_description("Hello World", 5), "He...");
2525+
fn test_truncate_description() {
2526+
// Test normal length
2527+
let short = "Short description";
2528+
assert_eq!(truncate_description(short, 40), "Short description");
2529+
2530+
// Test truncation
2531+
let long =
2532+
"This is a very long description that should be truncated because it exceeds the maximum length limit";
2533+
let result = truncate_description(long, 40);
2534+
assert!(result.len() <= 40);
2535+
assert!(result.ends_with("..."));
2536+
// Length may be less than 40 due to trim_end() removing trailing spaces
2537+
assert!(result.len() >= 37); // At least max_length - 3 chars
2538+
2539+
// Test exact length
2540+
let exact = "A".repeat(40);
2541+
assert_eq!(truncate_description(&exact, 40), exact);
2542+
2543+
// Test very short max length
2544+
let result = truncate_description("Hello world", 5);
2545+
assert_eq!(result, "He...");
2546+
assert_eq!(result.len(), 5);
2547+
2548+
// Test space trimming before ellipsis
2549+
let with_space = "Prompt to explain available tools and how";
2550+
let result = truncate_description(with_space, 40);
2551+
assert!(!result.contains(" ..."));
2552+
assert!(result.ends_with("..."));
2553+
assert_eq!(result, "Prompt to explain available tools and...");
25312554
}
25322555

25332556
#[test]

0 commit comments

Comments
 (0)