package zitcli
import (
"context"
"testing"
)
// Each line is credited to the check-in that brought it, with a line
// that later commits left alone keeping its first author's check-in.
// A path that is not tracked answers not-ok, not an error.
func TestAnnotateCreditsEachLine(t *testing.T) {
repo := testRepo(t, 0)
commitFileZ(t, repo, "f.txt", "one\ntwo\n", "first")
commitFileZ(t, repo, "f.txt", "one\ntwo\nthree\n", "second")
z := New(repo)
lines, cut, ok, err := z.Annotate(context.Background(), "trunk", "f.txt")
if err != nil || !ok || cut {
t.Fatalf("annotate: ok %v cut %v err %v", ok, cut, err)
}
if len(lines) != 3 {
t.Fatalf("FAIL: %d lines, want 3: %+v", len(lines), lines)
}
if lines[0].Hash != lines[1].Hash || lines[2].Hash == lines[0].Hash {
t.Errorf("FAIL: lines one and two share the first check-in and three the second: %+v", lines)
}
if lines[2].N != 3 || lines[2].Text != "three" || len(lines[0].Hash) < 40 {
t.Errorf("FAIL: line three reads %+v", lines[2])
}
if _, _, ok, err := z.Annotate(context.Background(), "trunk", "missing.txt"); ok || err != nil {
t.Errorf("FAIL: an untracked path answered ok %v, err %v", ok, err)
}
}