36 lines
1020 B
Go
36 lines
1020 B
Go
package prreview
|
|
|
|
import "testing"
|
|
|
|
func TestMapLine(t *testing.T) {
|
|
files := []FileChange{{
|
|
Path: "calc/calc.go",
|
|
Hunks: []Hunk{
|
|
{NewStart: 10, Lines: []string{" ctx", "+added", "-gone"}},
|
|
{NewStart: 30, Lines: []string{"+later"}},
|
|
},
|
|
}}
|
|
tests := []struct {
|
|
name string
|
|
path string
|
|
line int
|
|
want LineKind
|
|
}{
|
|
{"added line", "calc/calc.go", 11, LineAdded},
|
|
{"context line", "calc/calc.go", 10, LineContext},
|
|
{"added line in a later hunk", "calc/calc.go", 30, LineAdded},
|
|
{"line the hunk does not contain", "calc/calc.go", 12, LineOutside},
|
|
{"line between hunks", "calc/calc.go", 20, LineOutside},
|
|
{"line before the hunk", "calc/calc.go", 5, LineOutside},
|
|
{"file not in the diff", "README.md", 1, LineOutside},
|
|
{"no line", "calc/calc.go", 0, LineOutside},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := MapLine(files, tt.path, tt.line); got != tt.want {
|
|
t.Fatalf("MapLine(%q, %d) = %q, want %q", tt.path, tt.line, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|