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:
Billy Keyes
2019-03-31 21:16:34 -07:00
parent 4e8b7b5088
commit 8753644cc0
5 changed files with 289 additions and 31 deletions
+16
View File
@@ -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)