Skip to content

Commit 0cfd720

Browse files
committed
Add test for binary marker parsing
1 parent 5a521ed commit 0cfd720

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

gitdiff/parser_binary_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package gitdiff
2+
3+
import (
4+
"io"
5+
"testing"
6+
)
7+
8+
func TestParseBinaryMarker(t *testing.T) {
9+
tests := map[string]struct {
10+
Input string
11+
IsBinary bool
12+
HasData bool
13+
Err bool
14+
}{
15+
"binaryPatch": {
16+
Input: "GIT binary patch\n",
17+
IsBinary: true,
18+
HasData: true,
19+
},
20+
"binaryFileNoPatch": {
21+
Input: "Binary files differ\n",
22+
IsBinary: true,
23+
HasData: false,
24+
},
25+
"textFile": {
26+
Input: "@@ -10,14 +22,31 @@\n",
27+
IsBinary: false,
28+
HasData: false,
29+
},
30+
}
31+
32+
for name, test := range tests {
33+
t.Run(name, func(t *testing.T) {
34+
p := newTestParser(test.Input, true)
35+
36+
isBinary, hasData, err := p.ParseBinaryMarker()
37+
if test.Err {
38+
if err != nil || err == io.EOF {
39+
t.Fatalf("expected error parsing binary marker, but got %v", err)
40+
}
41+
return
42+
}
43+
if err != nil {
44+
t.Fatalf("unexpected error parsing binary marker: %v", err)
45+
}
46+
if test.IsBinary != isBinary {
47+
t.Errorf("incorrect isBinary value: expected %t, actual %t", test.IsBinary, isBinary)
48+
}
49+
if test.HasData != hasData {
50+
t.Errorf("incorrect hasData value: expected %t, actual %t", test.HasData, hasData)
51+
}
52+
})
53+
}
54+
}

0 commit comments

Comments
 (0)