(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestGetStringMaxWidth(t *testing.T) { |
| 62 | tests := []struct { |
| 63 | name string |
| 64 | input string |
| 65 | expected int |
| 66 | }{ |
| 67 | { |
| 68 | name: "Plain text", |
| 69 | input: "hello", |
| 70 | expected: 5, |
| 71 | }, |
| 72 | { |
| 73 | name: "Text with OSC 8 hyperlink", |
| 74 | input: fmt.Sprintf("\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\", "https://example.com", "link"), |
| 75 | expected: 4, // Only "link" should be counted |
| 76 | }, |
| 77 | { |
| 78 | name: "Text with OSC 8 hyperlink using BEL", |
| 79 | input: "\x1b]8;;https://example.com\x07link text\x1b]8;;\x07", |
| 80 | expected: 9, // Only "link text" should be counted |
| 81 | }, |
| 82 | { |
| 83 | name: "Multiple lines with hyperlinks", |
| 84 | input: "plain\n\x1b]8;;https://example.com\x1b\\link\x1b]8;;\x1b\\", |
| 85 | expected: 5, // "plain" is longer than "link" |
| 86 | }, |
| 87 | { |
| 88 | name: "Hyperlink longer than plain text", |
| 89 | input: "hi\n\x1b]8;;https://example.com\x1b\\longer link\x1b]8;;\x1b\\", |
| 90 | expected: 11, // "longer link" is the longest |
| 91 | }, |
| 92 | { |
| 93 | name: "Empty string", |
| 94 | input: "", |
| 95 | expected: 0, |
| 96 | }, |
| 97 | { |
| 98 | name: "Hyperlink with ANSI color codes", |
| 99 | input: "\x1b]8;;https://example.com\x1b\\\x1b[31mred link\x1b[0m\x1b]8;;\x1b\\", |
| 100 | expected: 8, // "red link" without color codes |
| 101 | }, |
| 102 | } |
| 103 | |
| 104 | for _, tt := range tests { |
| 105 | t.Run(tt.name, func(t *testing.T) { |
| 106 | result := GetStringMaxWidth(tt.input) |
| 107 | if result != tt.expected { |
| 108 | t.Errorf("GetStringMaxWidth() = %d, want %d", result, tt.expected) |
| 109 | } |
| 110 | }) |
| 111 | } |
| 112 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…