[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.
This commit is contained in:
ahrav 2022-08-25 10:45:35 -07:00 committed by GitHub
parent 098d4a9e7d
commit 20cdcbc970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View file

@ -218,7 +218,7 @@ func isModeLine(line []byte) bool {
// --- a/internal/addrs/move_endpoint_module.go
func isMinusFileLine(line []byte) bool {
if len(line) > 3 && bytes.Equal(line[:3], []byte("---")) {
if len(line) >= 6 && bytes.Equal(line[:3], []byte("---")) {
return true
}
return false
@ -226,7 +226,7 @@ func isMinusFileLine(line []byte) bool {
// +++ b/internal/addrs/move_endpoint_module.go
func isPlusFileLine(line []byte) bool {
if len(line) > 3 && bytes.Equal(line[:3], []byte("+++")) {
if len(line) >= 6 && bytes.Equal(line[:3], []byte("+++")) {
return true
}
return false

View file

@ -6,7 +6,7 @@ import (
type testCase struct {
pass []byte
fail []byte
fails [][]byte
function func([]byte) bool
}
@ -14,47 +14,46 @@ func TestIsIndexLine(t *testing.T) {
tests := map[string]testCase{
"indexLine": {
pass: []byte("index 1ed6fbee1..aea1e643a 100644"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect")},
function: isIndexLine,
},
"modeLine": {
pass: []byte("new file mode 100644"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect")},
function: isModeLine,
},
"minusFileLine": {
pass: []byte("--- a/internal/addrs/move_endpoint_module.go"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect"), []byte("--- s"), []byte("short")},
function: isMinusFileLine,
},
"plusFileLine": {
pass: []byte("+++ b/internal/addrs/move_endpoint_module.go"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect"), []byte("+++ s"), []byte("short")},
function: isPlusFileLine,
},
"plusDiffLine": {
pass: []byte("+fmt.Println"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect")},
function: isPlusDiffLine,
},
"minusDiffLine": {
pass: []byte("-fmt.Println"),
fail: []byte("notcorrect"),
function: isMinusDiffLine,
},
"messageLine": {
pass: []byte(" committed"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect")},
function: isMessageLine,
},
"binaryLine": {
pass: []byte("Binary files /dev/null and b/plugin.sig differ"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect")},
function: isBinaryLine,
},
"lineNumberLine": {
pass: []byte("@@ -298 +298 @@ func maxRetryErrorHandler(resp *http.Response, err error, numTries int)"),
fail: []byte("notcorrect"),
fails: [][]byte{[]byte("notcorrect")},
function: isLineNumberDiffLine,
},
}
@ -63,8 +62,10 @@ func TestIsIndexLine(t *testing.T) {
if !test.function(test.pass) {
t.Errorf("%s: Parser did not recognize correct line.", name)
}
if test.function(test.fail) {
t.Errorf("%s: Parser matched an incorrect line.", name)
for _, fail := range test.fails {
if test.function(fail) {
t.Errorf("%s: Parser did not recognize incorrect line.", name)
}
}
}
}