38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package workflow
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow/prreview"
|
|
)
|
|
|
|
func TestForgeReviewPlacesOnlyDiffLinesInline(t *testing.T) {
|
|
files := []prreview.FileChange{{
|
|
Path: "calc/calc.go",
|
|
Hunks: []prreview.Hunk{{NewStart: 10, Lines: []string{" ctx", "+added", "-gone", " ctx2"}}},
|
|
}}
|
|
tests := []struct {
|
|
name string
|
|
file string
|
|
line int
|
|
inline bool
|
|
}{
|
|
{"added line", "calc/calc.go", 11, true},
|
|
{"context line", "calc/calc.go", 12, true},
|
|
{"outside the hunk", "calc/calc.go", 40, false},
|
|
{"file not in the diff", "README.md", 1, false},
|
|
{"no line", "calc/calc.go", 0, false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
review := forgeReview([]prreview.ScoredFinding{{File: tt.file, LineStart: tt.line, Body: "b"}}, files)
|
|
if got := len(review.Comments) == 1; got != tt.inline {
|
|
t.Fatalf("inline = %v, want %v (body %q)", got, tt.inline, review.Body)
|
|
}
|
|
if !tt.inline && review.Body == "" {
|
|
t.Fatal("finding dropped: neither inline nor in the body")
|
|
}
|
|
})
|
|
}
|
|
}
|