Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diffparser.go: add to DiffFile struct Additions and Deletions fields. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions diffparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ type diffHunk struct {
}

type DiffFile struct {
Mode FileMode
OrigName string
NewName string
Hunks []*diffHunk
Mode FileMode
OrigName string
NewName string
Additions int
Deletions int
Hunks []*diffHunk
}

type Diff struct {
Expand Down Expand Up @@ -211,11 +213,13 @@ func Parse(diffString string) (*Diff, error) {
newLine.Number = ADDEDCount
hunk.NewRange.Lines = append(hunk.NewRange.Lines, &newLine)
ADDEDCount++
file.Additions++

case REMOVED:
origLine.Number = REMOVEDCount
hunk.OrigRange.Lines = append(hunk.OrigRange.Lines, &origLine)
REMOVEDCount++
file.Deletions++

case UNCHANGED:
newLine.Number = ADDEDCount
Expand Down
50 changes: 32 additions & 18 deletions diffparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,55 @@ func (s *suite) TestFileModeAndNaming(c *gc.C) {
c.Assert(diff.Files, gc.HasLen, 5)

for i, expected := range []struct {
mode diffparser.FileMode
origName string
newName string
mode diffparser.FileMode
origName string
newName string
Additions int
Deletions int
}{
{
mode: diffparser.MODIFIED,
origName: "file1",
newName: "file1",
mode: diffparser.MODIFIED,
origName: "file1",
newName: "file1",
Additions: 1,
Deletions: 1,
},
{
mode: diffparser.DELETED,
origName: "file2",
newName: "",
mode: diffparser.DELETED,
origName: "file2",
newName: "",
Additions: 0,
Deletions: 4,
},
{
mode: diffparser.DELETED,
origName: "file3",
newName: "",
mode: diffparser.DELETED,
origName: "file3",
newName: "",
Additions: 0,
Deletions: 4,
},
{
mode: diffparser.NEW,
origName: "",
newName: "file4",
mode: diffparser.NEW,
origName: "",
newName: "file4",
Additions: 1,
Deletions: 0,
},
{
mode: diffparser.NEW,
origName: "",
newName: "newname",
mode: diffparser.NEW,
origName: "",
newName: "newname",
Additions: 4,
Deletions: 0,
},
} {
file := diff.Files[i]
c.Logf("testing file: %v", file)
c.Assert(file.Mode, gc.Equals, expected.mode)
c.Assert(file.OrigName, gc.Equals, expected.origName)
c.Assert(file.NewName, gc.Equals, expected.newName)
c.Assert(file.Additions, gc.Equals, expected.Additions)
c.Assert(file.Deletions, gc.Equals, expected.Deletions)
}
}

Expand Down