MCPcopy Create free account
hub / github.com/antonmedv/gitmal / TestParseTextFragmentHeader

Function TestParseTextFragmentHeader

pkg/gitdiff/text_test.go:9–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestParseTextFragmentHeader(t *testing.T) {
10 tests := map[string]struct {
11 Input string
12 Output *TextFragment
13 Err bool
14 }{
15 "shortest": {
16 Input: "@@ -1 +1 @@\n",
17 Output: &TextFragment{
18 OldPosition: 1,
19 OldLines: 1,
20 NewPosition: 1,
21 NewLines: 1,
22 },
23 },
24 "standard": {
25 Input: "@@ -21,5 +28,9 @@\n",
26 Output: &TextFragment{
27 OldPosition: 21,
28 OldLines: 5,
29 NewPosition: 28,
30 NewLines: 9,
31 },
32 },
33 "trailingComment": {
34 Input: "@@ -21,5 +28,9 @@ func test(n int) {\n",
35 Output: &TextFragment{
36 Comment: "func test(n int) {",
37 OldPosition: 21,
38 OldLines: 5,
39 NewPosition: 28,
40 NewLines: 9,
41 },
42 },
43 "incomplete": {
44 Input: "@@ -12,3 +2\n",
45 Err: true,
46 },
47 "badNumbers": {
48 Input: "@@ -1a,2b +3c,4d @@\n",
49 Err: true,
50 },
51 }
52
53 for name, test := range tests {
54 t.Run(name, func(t *testing.T) {
55 p := newTestParser(test.Input, true)
56
57 frag, err := p.ParseTextFragmentHeader()
58 if test.Err {
59 if err == nil || err == io.EOF {
60 t.Fatalf("expected error parsing header, but got %v", err)
61 }
62 return
63 }
64 if err != nil {
65 t.Fatalf("error parsing header: %v", err)
66 }

Callers

nothing calls this directly

Calls 3

newTestParserFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected