Tests for calculate_display_width function.
| 10 | |
| 11 | |
| 12 | class TestCalculateDisplayWidth: |
| 13 | """Tests for calculate_display_width function.""" |
| 14 | |
| 15 | def test_ascii_text(self): |
| 16 | """Test ASCII text width calculation.""" |
| 17 | assert calculate_display_width("Hello") == 5 |
| 18 | assert calculate_display_width("World") == 5 |
| 19 | assert calculate_display_width("Test 123") == 8 |
| 20 | |
| 21 | def test_empty_string(self): |
| 22 | """Test empty string.""" |
| 23 | assert calculate_display_width("") == 0 |
| 24 | |
| 25 | def test_emoji(self): |
| 26 | """Test emoji width (should count as 2).""" |
| 27 | assert calculate_display_width("🤖") == 2 |
| 28 | assert calculate_display_width("💭") == 2 |
| 29 | assert calculate_display_width("🤖 Agent") == 8 # 2 + 1 + 5 |
| 30 | |
| 31 | def test_chinese_characters(self): |
| 32 | """Test Chinese characters (each counts as 2).""" |
| 33 | assert calculate_display_width("你好") == 4 |
| 34 | assert calculate_display_width("你好世界") == 8 |
| 35 | assert calculate_display_width("中文") == 4 |
| 36 | |
| 37 | def test_japanese_characters(self): |
| 38 | """Test Japanese characters.""" |
| 39 | assert calculate_display_width("日本語") == 6 # 3 chars * 2 |
| 40 | |
| 41 | def test_mixed_content(self): |
| 42 | """Test mixed ASCII and wide characters.""" |
| 43 | assert calculate_display_width("Hello 你好") == 10 # 5 + 1 + 4 |
| 44 | assert calculate_display_width("Test 🤖") == 7 # 4 + 1 + 2 |
| 45 | |
| 46 | def test_ansi_codes_ignored(self): |
| 47 | """Test that ANSI escape codes are not counted.""" |
| 48 | colored = "\033[31mRed\033[0m" |
| 49 | assert calculate_display_width(colored) == 3 |
| 50 | |
| 51 | colored_emoji = "\033[31m🤖\033[0m" |
| 52 | assert calculate_display_width(colored_emoji) == 2 |
| 53 | |
| 54 | def test_combining_characters(self): |
| 55 | """Test combining characters (should not add width).""" |
| 56 | # é = e + combining acute accent |
| 57 | e_with_accent = "e\u0301" |
| 58 | assert calculate_display_width(e_with_accent) == 1 |
| 59 | |
| 60 | def test_complex_ansi_sequences(self): |
| 61 | """Test complex ANSI sequences.""" |
| 62 | text = "\033[1m\033[36mBold Cyan\033[0m" |
| 63 | assert calculate_display_width(text) == 9 # "Bold Cyan" |
| 64 | |
| 65 | |
| 66 | class TestTruncateWithEllipsis: |
nothing calls this directly
no outgoing calls
no test coverage detected