Refactor changes and test functions

Remove change type in favor of explicit change function.
Using change function makes it more difficult to unnecessarily
add to the change interface.

Update test apply functions to use an interface rather
than a function type.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan
2017-02-02 17:30:11 -08:00
parent 65e8c07847
commit d96e6e3952
5 changed files with 172 additions and 193 deletions

View File

@@ -15,42 +15,27 @@ type currentPath struct {
fullPath string
}
func pathChange(lower, upper *currentPath) Change {
func pathChange(lower, upper *currentPath) (ChangeKind, string) {
if lower == nil {
if upper == nil {
panic("cannot compare nil paths")
}
return Change{
Kind: ChangeKindAdd,
Path: upper.path,
}
return ChangeKindAdd, upper.path
}
if upper == nil {
return Change{
Kind: ChangeKindDelete,
Path: lower.path,
}
return ChangeKindDelete, lower.path
}
// TODO: compare by directory
switch i := strings.Compare(lower.path, upper.path); {
case i < 0:
// File in lower that is not in upper
return Change{
Kind: ChangeKindDelete,
Path: lower.path,
}
return ChangeKindDelete, lower.path
case i > 0:
// File in upper that is not in lower
return Change{
Kind: ChangeKindAdd,
Path: upper.path,
}
return ChangeKindAdd, upper.path
default:
return Change{
Kind: ChangeKindModify,
Path: upper.path,
}
return ChangeKindModify, upper.path
}
}