mirror of
https://github.com/bluekeyes/go-gitdiff
synced 2026-06-08 13:18:30 +00:00
Add tests for single fragment parsing
To make output better, also add some (temporary?) String() functions and fix an assumption about the smallest fragment header I discovered was wrong while looking at sample patches.
This commit is contained in:
@@ -51,6 +51,10 @@ type FragmentLine struct {
|
||||
Line string
|
||||
}
|
||||
|
||||
func (fl FragmentLine) String() string {
|
||||
return fl.Op.String() + fl.Line
|
||||
}
|
||||
|
||||
// LineOp describes the type of a fragment line: context, added, or removed.
|
||||
type LineOp int
|
||||
|
||||
@@ -63,6 +67,18 @@ const (
|
||||
OpAdd
|
||||
)
|
||||
|
||||
func (op LineOp) String() string {
|
||||
switch op {
|
||||
case OpContext:
|
||||
return " "
|
||||
case OpDelete:
|
||||
return "-"
|
||||
case OpAdd:
|
||||
return "+"
|
||||
}
|
||||
return "?"
|
||||
}
|
||||
|
||||
// Header returns the cannonical header of this fragment.
|
||||
func (f *Fragment) Header() string {
|
||||
return fmt.Sprintf("@@ -%d,%d +%d,%d @@ %s", f.OldPosition, f.OldLines, f.NewPosition, f.NewLines, f.Comment)
|
||||
|
||||
Reference in New Issue
Block a user