this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add test for multiple files in one patch

For simplicity, use the same fragments in both of these files and in the
single file test.

+129 -47
+2
gitdiff/parser.go
··· 20 20 return nil, err 21 21 } 22 22 23 + // TODO(bkeyes): capture non-file lines in between files 24 + 23 25 var files []*File 24 26 for { 25 27 file, err := p.ParseNextFileHeader()
+67 -44
gitdiff/parser_test.go
··· 225 225 } 226 226 227 227 func TestParse(t *testing.T) { 228 + expectedFragments := []*Fragment{ 229 + { 230 + OldPosition: 3, 231 + OldLines: 6, 232 + NewPosition: 3, 233 + NewLines: 8, 234 + Comment: "fragment 1", 235 + Lines: []FragmentLine{ 236 + {OpContext, "context line\n"}, 237 + {OpDelete, "old line 1\n"}, 238 + {OpDelete, "old line 2\n"}, 239 + {OpContext, "context line\n"}, 240 + {OpAdd, "new line 1\n"}, 241 + {OpAdd, "new line 2\n"}, 242 + {OpAdd, "new line 3\n"}, 243 + {OpContext, "context line\n"}, 244 + {OpDelete, "old line 3\n"}, 245 + {OpAdd, "new line 4\n"}, 246 + {OpAdd, "new line 5\n"}, 247 + }, 248 + LinesAdded: 5, 249 + LinesDeleted: 3, 250 + LeadingContext: 1, 251 + }, 252 + { 253 + OldPosition: 31, 254 + OldLines: 2, 255 + NewPosition: 33, 256 + NewLines: 2, 257 + Comment: "fragment 2", 258 + Lines: []FragmentLine{ 259 + {OpContext, "context line\n"}, 260 + {OpDelete, "old line 4\n"}, 261 + {OpAdd, "new line 6\n"}, 262 + }, 263 + LinesAdded: 1, 264 + LinesDeleted: 1, 265 + LeadingContext: 1, 266 + }, 267 + } 268 + 228 269 tests := map[string]struct { 229 270 InputFile string 230 271 Output []*File 231 272 Err bool 232 273 }{ 233 - "singleFile": { 234 - InputFile: "testdata/single_file.patch", 274 + "oneFile": { 275 + InputFile: "testdata/one_file.patch", 276 + Output: []*File{ 277 + { 278 + OldName: "dir/file1.txt", 279 + NewName: "dir/file1.txt", 280 + OldMode: os.FileMode(0100644), 281 + OldOIDPrefix: "ebe9fa54", 282 + NewOIDPrefix: "fe103e1d", 283 + Fragments: expectedFragments, 284 + }, 285 + }, 286 + }, 287 + "twoFiles": { 288 + InputFile: "testdata/two_files.patch", 235 289 Output: []*File{ 236 290 { 237 - OldName: "dir/file.txt", 238 - NewName: "dir/file.txt", 291 + OldName: "dir/file1.txt", 292 + NewName: "dir/file1.txt", 239 293 OldMode: os.FileMode(0100644), 240 294 OldOIDPrefix: "ebe9fa54", 241 295 NewOIDPrefix: "fe103e1d", 242 - Fragments: []*Fragment{ 243 - { 244 - OldPosition: 3, 245 - OldLines: 6, 246 - NewPosition: 3, 247 - NewLines: 8, 248 - Comment: "fragment 1", 249 - Lines: []FragmentLine{ 250 - {OpContext, "context line\n"}, 251 - {OpDelete, "old line 1\n"}, 252 - {OpDelete, "old line 2\n"}, 253 - {OpContext, "context line\n"}, 254 - {OpAdd, "new line 1\n"}, 255 - {OpAdd, "new line 2\n"}, 256 - {OpAdd, "new line 3\n"}, 257 - {OpContext, "context line\n"}, 258 - {OpDelete, "old line 3\n"}, 259 - {OpAdd, "new line 4\n"}, 260 - {OpAdd, "new line 5\n"}, 261 - }, 262 - LinesAdded: 5, 263 - LinesDeleted: 3, 264 - LeadingContext: 1, 265 - }, 266 - { 267 - OldPosition: 31, 268 - OldLines: 2, 269 - NewPosition: 33, 270 - NewLines: 2, 271 - Comment: "fragment 2", 272 - Lines: []FragmentLine{ 273 - {OpContext, "context line\n"}, 274 - {OpDelete, "old line 4\n"}, 275 - {OpAdd, "new line 6\n"}, 276 - }, 277 - LinesAdded: 1, 278 - LinesDeleted: 1, 279 - LeadingContext: 1, 280 - }, 281 - }, 296 + Fragments: expectedFragments, 297 + }, 298 + { 299 + OldName: "dir/file2.txt", 300 + NewName: "dir/file2.txt", 301 + OldMode: os.FileMode(0100644), 302 + OldOIDPrefix: "417ebc70", 303 + NewOIDPrefix: "67514b7f", 304 + Fragments: expectedFragments, 282 305 }, 283 306 }, 284 307 },
+3 -3
gitdiff/testdata/single_file.patch gitdiff/testdata/one_file.patch
··· 6 6 7 7 The content is arbitrary. 8 8 9 - diff --git a/dir/file.txt b/dir/file.txt 9 + diff --git a/dir/file1.txt b/dir/file1.txt 10 10 index ebe9fa54..fe103e1d 100644 11 - --- a/dir/file.txt 12 - +++ b/dir/file.txt 11 + --- a/dir/file1.txt 12 + +++ b/dir/file1.txt 13 13 @@ -3,6 +3,8 @@ fragment 1 14 14 context line 15 15 -old line 1
+57
gitdiff/testdata/two_files.patch
··· 1 + commit 5d9790fec7d95aa223f3d20936340bf55ff3dcbe 2 + Author: Morton Haypenny <mhaypenny@example.com> 3 + Date: Tue Apr 2 22:55:40 2019 -0700 4 + 5 + A file with multiple fragments. 6 + 7 + The content is arbitrary. 8 + 9 + diff --git a/dir/file1.txt b/dir/file1.txt 10 + index ebe9fa54..fe103e1d 100644 11 + --- a/dir/file1.txt 12 + +++ b/dir/file1.txt 13 + @@ -3,6 +3,8 @@ fragment 1 14 + context line 15 + -old line 1 16 + -old line 2 17 + context line 18 + +new line 1 19 + +new line 2 20 + +new line 3 21 + context line 22 + -old line 3 23 + +new line 4 24 + +new line 5 25 + @@ -31,2 +33,2 @@ fragment 2 26 + context line 27 + -old line 4 28 + +new line 6 29 + 30 + commit a84b8652757d3114875388ad6d6de782f179d82a 31 + Author: Morton Haypenny <mhaypenny@example.com> 32 + Date: Wed Apr 3 20:45:10 2019 -0700 33 + 34 + Another file with multiple fragments. 35 + 36 + The content is arbitrary. 37 + 38 + diff --git a/dir/file2.txt b/dir/file2.txt 39 + index 417ebc70..67514b7f 100644 40 + --- a/dir/file2.txt 41 + +++ b/dir/file2.txt 42 + @@ -3,6 +3,8 @@ fragment 1 43 + context line 44 + -old line 1 45 + -old line 2 46 + context line 47 + +new line 1 48 + +new line 2 49 + +new line 3 50 + context line 51 + -old line 3 52 + +new line 4 53 + +new line 5 54 + @@ -31,2 +33,2 @@ fragment 2 55 + context line 56 + -old line 4 57 + +new line 6