| 10 | ) |
| 11 | |
| 12 | func TestTruncate(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | s string |
| 16 | maxLen int |
| 17 | expected string |
| 18 | }{ |
| 19 | { |
| 20 | name: "string shorter than max length", |
| 21 | s: "hello", |
| 22 | maxLen: 10, |
| 23 | expected: "hello", |
| 24 | }, |
| 25 | { |
| 26 | name: "string equal to max length", |
| 27 | s: "hello", |
| 28 | maxLen: 5, |
| 29 | expected: "hello", |
| 30 | }, |
| 31 | { |
| 32 | name: "string longer than max length", |
| 33 | s: "hello world", |
| 34 | maxLen: 8, |
| 35 | expected: "hello...", |
| 36 | }, |
| 37 | { |
| 38 | name: "max length 3", |
| 39 | s: "hello", |
| 40 | maxLen: 3, |
| 41 | expected: "hel", |
| 42 | }, |
| 43 | { |
| 44 | name: "max length 2", |
| 45 | s: "hello", |
| 46 | maxLen: 2, |
| 47 | expected: "he", |
| 48 | }, |
| 49 | { |
| 50 | name: "max length 1", |
| 51 | s: "hello", |
| 52 | maxLen: 1, |
| 53 | expected: "h", |
| 54 | }, |
| 55 | { |
| 56 | name: "max length zero", |
| 57 | s: "hello", |
| 58 | maxLen: 0, |
| 59 | expected: "", |
| 60 | }, |
| 61 | { |
| 62 | name: "exactly three chars", |
| 63 | s: "abc", |
| 64 | maxLen: 3, |
| 65 | expected: "abc", |
| 66 | }, |
| 67 | { |
| 68 | name: "four chars exact length", |
| 69 | s: "abcd", |