Skip to content

Commit 3398cfa

Browse files
committed
Add additional parser advancement tests
1 parent 69e4444 commit 3398cfa

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

gitdiff/parser_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestLineOperations(t *testing.T) {
8080
})
8181
}
8282

83-
func TestParserAdvancment(t *testing.T) {
83+
func TestParserInvariant_Advancement(t *testing.T) {
8484
tests := map[string]struct {
8585
Input string
8686
Parse func(p *parser) error
@@ -122,6 +122,48 @@ context line
122122
},
123123
EndLine: "context line\n",
124124
},
125+
"ParseTextChunk": {
126+
Input: ` context line
127+
-old line
128+
+new line
129+
context line
130+
@@ -1 +1 @@
131+
`,
132+
Parse: func(p *parser) error {
133+
return p.ParseTextChunk(&Fragment{OldLines: 3, NewLines: 3})
134+
},
135+
EndLine: "@@ -1 +1 @@\n",
136+
},
137+
"ParseTextFragments": {
138+
Input: `@@ -1,2 +1,2 @@
139+
context line
140+
-old line
141+
+new line
142+
@@ -1,2 +1,2 @@
143+
-old line
144+
+new line
145+
context line
146+
diff --git a/file.txt b/file.txt
147+
`,
148+
Parse: func(p *parser) error {
149+
_, err := p.ParseTextFragments(&File{})
150+
return err
151+
},
152+
EndLine: "diff --git a/file.txt b/file.txt\n",
153+
},
154+
"ParseNextFileHeader": {
155+
Input: `not a header
156+
diff --git a/file.txt b/file.txt
157+
--- a/file.txt
158+
+++ b/file.txt
159+
@@ -1,2 +1,2 @@
160+
`,
161+
Parse: func(p *parser) error {
162+
_, _, err := p.ParseNextFileHeader()
163+
return err
164+
},
165+
EndLine: "@@ -1,2 +1,2 @@\n",
166+
},
125167
}
126168

127169
for name, test := range tests {

0 commit comments

Comments
 (0)