Add interactive Markdown checklist toggles in the ticket preview.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Skruecken
2026-10-19 14:37:14 +02:00
co-authored by Cursor
parent 7666715f6c
commit f08084d5e1
8 changed files with 366 additions and 21 deletions
+65
View File
@@ -0,0 +1,65 @@
package ticket
import (
"testing"
)
func TestListCheckboxes(t *testing.T) {
src := `# Steps
- [ ] one
- [x] two
* [X] three
- [ ] nested
Not a box: [ ] plain
`
got := ListCheckboxes(src)
if len(got) != 4 {
t.Fatalf("len=%d want 4: %+v", len(got), got)
}
if got[0].Text != "one" || got[0].Checked || got[0].Line != 2 {
t.Fatalf("first: %+v", got[0])
}
if !got[1].Checked || got[1].Text != "two" {
t.Fatalf("second: %+v", got[1])
}
if !got[2].Checked || got[2].Text != "three" {
t.Fatalf("third: %+v", got[2])
}
if got[3].Text != "nested" || got[3].Checked || got[3].Line != 5 {
t.Fatalf("nested: %+v", got[3])
}
}
func TestToggleCheckbox(t *testing.T) {
src := "- [ ] a\n- [x] b\n"
out, err := ToggleCheckbox(src, 0)
if err != nil {
t.Fatal(err)
}
if out != "- [x] a\n- [x] b\n" {
t.Fatalf("toggle 0: %q", out)
}
out, err = ToggleCheckbox(out, 1)
if err != nil {
t.Fatal(err)
}
if out != "- [x] a\n- [ ] b\n" {
t.Fatalf("toggle 1: %q", out)
}
if _, err := ToggleCheckbox(src, 9); err == nil {
t.Fatal("expected error for bad index")
}
}
func TestToggleCheckboxPreservesIndentAndBullet(t *testing.T) {
src := " * [X] deep"
out, err := ToggleCheckbox(src, 0)
if err != nil {
t.Fatal(err)
}
if out != " * [ ] deep" {
t.Fatalf("got %q", out)
}
}