package cli import ( "strings" "testing" "github.com/humdrum-tiv/dots-cli/internal/day" ) func sp(s string) *string { return &s } func TestFormatChanges(t *testing.T) { names := map[string]string{"t1": "archer", "t2": "foofaraw"} changes := []day.Change{ {Index: 29, FromID: sp("t1"), ToID: sp("t2")}, {Index: 30, FromID: sp("t1"), ToID: nil}, } out := FormatChanges(changes, names, 30) if !strings.Contains(out, "14:30") || !strings.Contains(out, "archer → foofaraw") { t.Fatalf("out %q", out) } if !strings.Contains(out, "15:00") || !strings.Contains(out, "archer → (cleared)") { t.Fatalf("out %q", out) } } func TestConfirm(t *testing.T) { // --yes bypasses everything ok, err := Confirm("overwrite?", true, strings.NewReader(""), &strings.Builder{}, false) if err != nil || !ok { t.Fatalf("yes flag: ok=%v err=%v", ok, err) } // non-TTY without --yes = hard error if _, err := Confirm("overwrite?", false, strings.NewReader("y\n"), &strings.Builder{}, false); err == nil { t.Fatal("non-TTY without --yes must error") } // TTY: y accepts, anything else declines ok, _ = Confirm("overwrite?", false, strings.NewReader("y\n"), &strings.Builder{}, true) if !ok { t.Fatal("y should accept") } ok, _ = Confirm("overwrite?", false, strings.NewReader("n\n"), &strings.Builder{}, true) if ok { t.Fatal("n should decline") } ok, _ = Confirm("overwrite?", false, strings.NewReader("\n"), &strings.Builder{}, true) if ok { t.Fatal("empty should decline (default N)") } // y without newline (EOF) should accept ok, _ = Confirm("overwrite?", false, strings.NewReader("y"), &strings.Builder{}, true) if !ok { t.Fatal("y without newline should accept") } // immediate EOF (empty input) should decline ok, _ = Confirm("overwrite?", false, strings.NewReader(""), &strings.Builder{}, true) if ok { t.Fatal("immediate EOF should decline") } }