(t *testing.T)
| 149 | } |
| 150 | |
| 151 | func TestUpdateHunkHeader(t *testing.T) { |
| 152 | repo := &Repository{} |
| 153 | |
| 154 | tests := []struct { |
| 155 | name string |
| 156 | hunk *Hunk |
| 157 | expectedHeader string |
| 158 | }{ |
| 159 | { |
| 160 | name: "header with multi-line counts", |
| 161 | hunk: &Hunk{ |
| 162 | OldLine: 10, |
| 163 | OldCnt: 5, |
| 164 | NewLine: 15, |
| 165 | NewCnt: 7, |
| 166 | Text: []string{" existing content"}, |
| 167 | Display: []string{" existing content"}, |
| 168 | }, |
| 169 | expectedHeader: "@@ -10,5 +15,7 @@", |
| 170 | }, |
| 171 | { |
| 172 | name: "header with single line counts", |
| 173 | hunk: &Hunk{ |
| 174 | OldLine: 5, |
| 175 | OldCnt: 1, |
| 176 | NewLine: 8, |
| 177 | NewCnt: 1, |
| 178 | Text: []string{"+new line"}, |
| 179 | Display: []string{"+new line"}, |
| 180 | }, |
| 181 | expectedHeader: "@@ -5 +8 @@", |
| 182 | }, |
| 183 | { |
| 184 | name: "empty hunk", |
| 185 | hunk: &Hunk{ |
| 186 | OldLine: 20, |
| 187 | OldCnt: 3, |
| 188 | NewLine: 25, |
| 189 | NewCnt: 2, |
| 190 | }, |
| 191 | expectedHeader: "@@ -20,3 +25,2 @@", |
| 192 | }, |
| 193 | } |
| 194 | |
| 195 | for _, tt := range tests { |
| 196 | t.Run(tt.name, func(t *testing.T) { |
| 197 | originalTextLen := len(tt.hunk.Text) |
| 198 | originalDisplayLen := len(tt.hunk.Display) |
| 199 | |
| 200 | repo.updateHunkHeader(tt.hunk) |
| 201 | |
| 202 | // Header should be inserted at the beginning |
| 203 | if len(tt.hunk.Text) == 0 || tt.hunk.Text[0] != tt.expectedHeader { |
| 204 | t.Errorf("Expected header %s, got %v", tt.expectedHeader, tt.hunk.Text) |
| 205 | } |
| 206 | |
| 207 | // Length should increase by 1 |
| 208 | if len(tt.hunk.Text) != originalTextLen+1 { |
nothing calls this directly
no test coverage detected