Additional edge case tests
(t *testing.T)
| 176 | // Additional edge case tests |
| 177 | |
| 178 | func TestTruncate_Unicode(t *testing.T) { |
| 179 | tests := []struct { |
| 180 | name string |
| 181 | s string |
| 182 | maxLen int |
| 183 | expected string |
| 184 | }{ |
| 185 | { |
| 186 | name: "emoji truncation", |
| 187 | s: "Hello 👋 World 🌍", |
| 188 | maxLen: 10, |
| 189 | expected: "Hello \xf0...", // Truncates in middle of emoji byte sequence |
| 190 | }, |
| 191 | { |
| 192 | name: "unicode characters", |
| 193 | s: "Café España México", |
| 194 | maxLen: 12, |
| 195 | expected: "Café Esp...", // Actual behavior |
| 196 | }, |
| 197 | { |
| 198 | name: "mixed unicode and ascii", |
| 199 | s: "Test-测试-テスト", |
| 200 | maxLen: 8, |
| 201 | expected: "Test-...", |
| 202 | }, |
| 203 | } |
| 204 | |
| 205 | for _, tt := range tests { |
| 206 | t.Run(tt.name, func(t *testing.T) { |
| 207 | result := Truncate(tt.s, tt.maxLen) |
| 208 | assert.Equal(t, tt.expected, result, "Truncate(%q, %d) should handle unicode input as expected", tt.s, tt.maxLen) |
| 209 | }) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | func TestNormalizeWhitespace_OnlyWhitespace(t *testing.T) { |
| 214 | tests := []struct { |