@@ -2,6 +2,7 @@ package gitdiff
2
2
3
3
import (
4
4
"io"
5
+ "reflect"
5
6
"testing"
6
7
)
7
8
@@ -35,7 +36,7 @@ func TestParseBinaryMarker(t *testing.T) {
35
36
36
37
isBinary , hasData , err := p .ParseBinaryMarker ()
37
38
if test .Err {
38
- if err ! = nil || err == io .EOF {
39
+ if err = = nil || err == io .EOF {
39
40
t .Fatalf ("expected error parsing binary marker, but got %v" , err )
40
41
}
41
42
return
@@ -52,3 +53,58 @@ func TestParseBinaryMarker(t *testing.T) {
52
53
})
53
54
}
54
55
}
56
+
57
+ func TestParseBinaryFragmentHeader (t * testing.T ) {
58
+ tests := map [string ]struct {
59
+ Input string
60
+ Output * BinaryFragment
61
+ Err bool
62
+ }{
63
+ "delta" : {
64
+ Input : "delta 1234\n " ,
65
+ Output : & BinaryFragment {
66
+ Method : BinaryPatchDelta ,
67
+ Size : 1234 ,
68
+ },
69
+ },
70
+ "literal" : {
71
+ Input : "literal 1234\n " ,
72
+ Output : & BinaryFragment {
73
+ Method : BinaryPatchLiteral ,
74
+ Size : 1234 ,
75
+ },
76
+ },
77
+ "unknownMethod" : {
78
+ Input : "compressed 1234\n " ,
79
+ Output : nil ,
80
+ },
81
+ "notAHeader" : {
82
+ Input : "Binary files differ\n " ,
83
+ Output : nil ,
84
+ },
85
+ "invalidSize" : {
86
+ Input : "delta 123abc\n " ,
87
+ Err : true ,
88
+ },
89
+ }
90
+
91
+ for name , test := range tests {
92
+ t .Run (name , func (t * testing.T ) {
93
+ p := newTestParser (test .Input , true )
94
+
95
+ frag , err := p .ParseBinaryFragmentHeader ()
96
+ if test .Err {
97
+ if err == nil || err == io .EOF {
98
+ t .Fatalf ("expected error parsing binary header, but got %v" , err )
99
+ }
100
+ return
101
+ }
102
+ if err != nil {
103
+ t .Fatalf ("unexpected error parsing binary header: %v" , err )
104
+ }
105
+ if ! reflect .DeepEqual (test .Output , frag ) {
106
+ t .Errorf ("incorrect binary fragment\n expected: %+v\n actual: %+v" , test .Output , frag )
107
+ }
108
+ })
109
+ }
110
+ }
0 commit comments