Skip to content

Commit

Permalink
chore(#55): case
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Aug 9, 2023
1 parent 3a25b51 commit 0dcf086
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions cmd/srctx/diff/core_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package diff

import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"testing"
)

func TestCollectLineMap(t *testing.T) {
impactLineMap, err := collectLineMap(&Options{
Src: ".",
Before: "HEAD~1",
After: "HEAD",
})
assert.Nil(t, err)
log.Debugf("map: %v", impactLineMap)
}
6 changes: 3 additions & 3 deletions diff/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func Unified2Impact(patch []byte) (ImpactLineMap, error) {
}
impactLineMap[each.NewName] = make([]int, 0)
fragments := each.TextFragments
for _, eachF := range fragments {
left := int(eachF.NewPosition)
for _, eachFragment := range fragments {
left := int(eachFragment.NewPosition)

for i, eachLine := range eachF.Lines {
for i, eachLine := range eachFragment.Lines {
if eachLine.New() && eachLine.Op == gitdiff.OpAdd {
impactLineMap[each.NewName] = append(impactLineMap[each.NewName], left+i-1)
}
Expand Down

0 comments on commit 0dcf086

Please sign in to comment.