From 5511c420162a1a5f25a3ef6ef38ebbfae727a1b1 Mon Sep 17 00:00:00 2001 From: "Mike JS. Choi" Date: Thu, 31 May 2018 21:35:50 -0500 Subject: [PATCH] Appease go report card --- conflict/conflict.go | 3 +++ conflict/conflict_test.go | 2 +- conflict/file_test.go | 2 +- conflict/parse.go | 8 ++++++-- conflict/parse_test.go | 2 +- testhelper/testhelper.go | 1 - 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/conflict/conflict.go b/conflict/conflict.go index a86d10b..facc8ad 100644 --- a/conflict/conflict.go +++ b/conflict/conflict.go @@ -36,11 +36,14 @@ type Conflict struct { BottomPeek int } +// Represents user's conflict resolution decision const ( Local = 1 Incoming = 2 ) +// ErrInvalidManualInput is thrown when the manual code editing session +// results in deletion of the conflict markers in the text var ErrInvalidManualInput = errors.New("Newly edited code is invalid") // Valid checks if the parsed conflict has corresponding begin, separator, diff --git a/conflict/conflict_test.go b/conflict/conflict_test.go index cb64bb1..1fb26dd 100644 --- a/conflict/conflict_test.go +++ b/conflict/conflict_test.go @@ -137,7 +137,7 @@ func TestHighlight(t *testing.T) { err := f.Read() testhelper.Ok(t, err) - conflicts, err := ExtractConflictsIn(f) + conflicts, err := ExtractConflicts(f) if test.shouldPass { testhelper.Ok(t, err) } else { diff --git a/conflict/file_test.go b/conflict/file_test.go index 02a8c2d..daa0218 100644 --- a/conflict/file_test.go +++ b/conflict/file_test.go @@ -30,7 +30,7 @@ func TestWriteChanges(t *testing.T) { } // Exract conflicts and resolve them - conflicts, err := ExtractConflictsIn(f) + conflicts, err := ExtractConflicts(f) testhelper.Ok(t, err) for i := range test.resolveDecision { conflicts[i].Choice = test.resolveDecision[i] diff --git a/conflict/parse.go b/conflict/parse.go index 234e4d4..7a105db 100644 --- a/conflict/parse.go +++ b/conflict/parse.go @@ -75,7 +75,11 @@ func GroupConflictMarkers(lines []string) (conflicts []Conflict, err error) { return conflicts, nil } -func ExtractConflictsIn(f File) (conflicts []Conflict, err error) { +// ExtractConflicts extracts all conflicts from the provided `File` +// It returns an error if it fails to parse the conflict markers +// and if syntax highlighting fatally fails +// TODO: Prevent crashes from syntax highlighting +func ExtractConflicts(f File) (conflicts []Conflict, err error) { conflicts, err = GroupConflictMarkers(f.Lines) if err != nil { return @@ -119,7 +123,7 @@ func Find(cwd string) (files []File, err error) { return } - conflicts, err := ExtractConflictsIn(file) + conflicts, err := ExtractConflicts(file) if err != nil { return nil, err } diff --git a/conflict/parse_test.go b/conflict/parse_test.go index c7f69c6..07b7254 100644 --- a/conflict/parse_test.go +++ b/conflict/parse_test.go @@ -44,7 +44,7 @@ func TestParseConflictsIn(t *testing.T) { t.Error("ParseConflicts/Read failed") } - _, err := ExtractConflictsIn(f) + _, err := ExtractConflicts(f) if test.shouldPass { testhelper.Assert(t, err == nil, "function should have succeeded") } else { diff --git a/testhelper/testhelper.go b/testhelper/testhelper.go index 9adfc3d..beb3bfa 100644 --- a/testhelper/testhelper.go +++ b/testhelper/testhelper.go @@ -34,4 +34,3 @@ func Equals(tb testing.TB, exp, act interface{}) { tb.FailNow() } } -