Skip to content

Commit 20cdcbc

Browse files
authored
[bug] - Fix the starting index value for plus line check. (#734)
* Fix the starting index value for plus line check. * Set the correct source type for notifications. * Reset old value. * Fix the starting index value for plus line check. * Fix len check. * Reset old value. * Add tests. * Update tests. * Update tests.
1 parent 098d4a9 commit 20cdcbc

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

pkg/gitparse/gitparse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ func isModeLine(line []byte) bool {
218218

219219
// --- a/internal/addrs/move_endpoint_module.go
220220
func isMinusFileLine(line []byte) bool {
221-
if len(line) > 3 && bytes.Equal(line[:3], []byte("---")) {
221+
if len(line) >= 6 && bytes.Equal(line[:3], []byte("---")) {
222222
return true
223223
}
224224
return false
225225
}
226226

227227
// +++ b/internal/addrs/move_endpoint_module.go
228228
func isPlusFileLine(line []byte) bool {
229-
if len(line) > 3 && bytes.Equal(line[:3], []byte("+++")) {
229+
if len(line) >= 6 && bytes.Equal(line[:3], []byte("+++")) {
230230
return true
231231
}
232232
return false

pkg/gitparse/gitparse_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,54 @@ import (
66

77
type testCase struct {
88
pass []byte
9-
fail []byte
9+
fails [][]byte
1010
function func([]byte) bool
1111
}
1212

1313
func TestIsIndexLine(t *testing.T) {
1414
tests := map[string]testCase{
1515
"indexLine": {
1616
pass: []byte("index 1ed6fbee1..aea1e643a 100644"),
17-
fail: []byte("notcorrect"),
17+
fails: [][]byte{[]byte("notcorrect")},
1818
function: isIndexLine,
1919
},
2020
"modeLine": {
2121
pass: []byte("new file mode 100644"),
22-
fail: []byte("notcorrect"),
22+
fails: [][]byte{[]byte("notcorrect")},
2323
function: isModeLine,
2424
},
2525
"minusFileLine": {
2626
pass: []byte("--- a/internal/addrs/move_endpoint_module.go"),
27-
fail: []byte("notcorrect"),
27+
fails: [][]byte{[]byte("notcorrect"), []byte("--- s"), []byte("short")},
2828
function: isMinusFileLine,
2929
},
3030
"plusFileLine": {
3131
pass: []byte("+++ b/internal/addrs/move_endpoint_module.go"),
32-
fail: []byte("notcorrect"),
32+
fails: [][]byte{[]byte("notcorrect"), []byte("+++ s"), []byte("short")},
3333
function: isPlusFileLine,
3434
},
3535
"plusDiffLine": {
3636
pass: []byte("+fmt.Println"),
37-
fail: []byte("notcorrect"),
37+
fails: [][]byte{[]byte("notcorrect")},
3838
function: isPlusDiffLine,
3939
},
4040
"minusDiffLine": {
4141
pass: []byte("-fmt.Println"),
42-
fail: []byte("notcorrect"),
4342
function: isMinusDiffLine,
4443
},
4544
"messageLine": {
4645
pass: []byte(" committed"),
47-
fail: []byte("notcorrect"),
46+
fails: [][]byte{[]byte("notcorrect")},
4847
function: isMessageLine,
4948
},
5049
"binaryLine": {
5150
pass: []byte("Binary files /dev/null and b/plugin.sig differ"),
52-
fail: []byte("notcorrect"),
51+
fails: [][]byte{[]byte("notcorrect")},
5352
function: isBinaryLine,
5453
},
5554
"lineNumberLine": {
5655
pass: []byte("@@ -298 +298 @@ func maxRetryErrorHandler(resp *http.Response, err error, numTries int)"),
57-
fail: []byte("notcorrect"),
56+
fails: [][]byte{[]byte("notcorrect")},
5857
function: isLineNumberDiffLine,
5958
},
6059
}
@@ -63,8 +62,10 @@ func TestIsIndexLine(t *testing.T) {
6362
if !test.function(test.pass) {
6463
t.Errorf("%s: Parser did not recognize correct line.", name)
6564
}
66-
if test.function(test.fail) {
67-
t.Errorf("%s: Parser matched an incorrect line.", name)
65+
for _, fail := range test.fails {
66+
if test.function(fail) {
67+
t.Errorf("%s: Parser did not recognize incorrect line.", name)
68+
}
6869
}
6970
}
7071
}

0 commit comments

Comments
 (0)