Skip to content

Commit 4065436

Browse files
committed
test: add edge case tests for truncate_description
Add comprehensive test coverage for edge cases: - Very small max_length values - CJK characters that don't fit in target length - Emoji (4-byte UTF-8 characters) - Mixed ASCII and CJK text - Single CJK character within limit All tests verify UTF-8 safe truncation behavior.
1 parent 8cc4ed0 commit 4065436

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,34 @@ mod tests {
22792279

22802280
// Test empty string
22812281
assert_eq!(truncate_description("", 10), "");
2282+
2283+
// Edge case: max_length very small (result will be just "...")
2284+
let result = truncate_description("한국어", 5);
2285+
assert_eq!(result, "...");
2286+
2287+
let result = truncate_description("ABCDEF", 5);
2288+
assert_eq!(result, "AB...");
2289+
2290+
// Edge case: first CJK character (3 bytes) + "..." = 6 bytes minimum
2291+
let result = truncate_description("한국어", 6);
2292+
assert_eq!(result, "한...");
2293+
assert!(result.len() <= 6);
2294+
2295+
// Edge case: emoji (4-byte characters)
2296+
let emoji = "😀😀😀😀😀";
2297+
let result = truncate_description(emoji, 15);
2298+
assert!(result.len() <= 15);
2299+
assert!(result.ends_with("..."));
2300+
2301+
// Edge case: mixed ASCII and CJK
2302+
let mixed = "Hello世界こんにちは";
2303+
let result = truncate_description(mixed, 15);
2304+
assert!(result.len() <= 15);
2305+
assert!(result.ends_with("..."));
2306+
2307+
// Edge case: single CJK character that fits
2308+
let result = truncate_description("한", 10);
2309+
assert_eq!(result, "한");
22822310
}
22832311

22842312
#[test]

0 commit comments

Comments
 (0)