| 6 | ) |
| 7 | |
| 8 | func TestTextFragmentValidate(t *testing.T) { |
| 9 | tests := map[string]struct { |
| 10 | Fragment TextFragment |
| 11 | Err string |
| 12 | }{ |
| 13 | "oldLines": { |
| 14 | Fragment: TextFragment{ |
| 15 | OldPosition: 1, |
| 16 | OldLines: 3, |
| 17 | NewPosition: 1, |
| 18 | NewLines: 2, |
| 19 | LeadingContext: 1, |
| 20 | TrailingContext: 0, |
| 21 | LinesAdded: 1, |
| 22 | LinesDeleted: 1, |
| 23 | Lines: []Line{ |
| 24 | {Op: OpContext, Line: "line 1\n"}, |
| 25 | {Op: OpDelete, Line: "old line 2\n"}, |
| 26 | {Op: OpAdd, Line: "new line 2\n"}, |
| 27 | }, |
| 28 | }, |
| 29 | Err: "2 old lines", |
| 30 | }, |
| 31 | "newLines": { |
| 32 | Fragment: TextFragment{ |
| 33 | OldPosition: 1, |
| 34 | OldLines: 2, |
| 35 | NewPosition: 1, |
| 36 | NewLines: 3, |
| 37 | LeadingContext: 1, |
| 38 | TrailingContext: 0, |
| 39 | LinesAdded: 1, |
| 40 | LinesDeleted: 1, |
| 41 | Lines: []Line{ |
| 42 | {Op: OpContext, Line: "line 1\n"}, |
| 43 | {Op: OpDelete, Line: "old line 2\n"}, |
| 44 | {Op: OpAdd, Line: "new line 2\n"}, |
| 45 | }, |
| 46 | }, |
| 47 | Err: "2 new lines", |
| 48 | }, |
| 49 | "leadingContext": { |
| 50 | Fragment: TextFragment{ |
| 51 | OldPosition: 1, |
| 52 | OldLines: 2, |
| 53 | NewPosition: 1, |
| 54 | NewLines: 2, |
| 55 | LeadingContext: 0, |
| 56 | TrailingContext: 0, |
| 57 | LinesAdded: 1, |
| 58 | LinesDeleted: 1, |
| 59 | Lines: []Line{ |
| 60 | {Op: OpContext, Line: "line 1\n"}, |
| 61 | {Op: OpDelete, Line: "old line 2\n"}, |
| 62 | {Op: OpAdd, Line: "new line 2\n"}, |
| 63 | }, |
| 64 | }, |
| 65 | Err: "1 leading context lines", |