package extensions
import (
"testing"
"github.com/yuin/goldmark/ast"
)
type fakeTaskNode struct {
ast.BaseInline
checked bool
}
func TestTaskListItemKind(t *testing.T) {
t.Parallel()
n := &TaskListItem{Checked: true}
if n.Kind() != KindTaskListItem {
t.Errorf("unexpected kind: %v", n.Kind())
}
}
func TestCountTasks(t *testing.T) {
t.Parallel()
cases := []struct {
name string
checked []bool
wantTotal int
wantDone int
}{
{"none", nil, 0, 0},
{"all_unchecked", []bool{false, false, false}, 3, 0},
{"all_checked", []bool{true, true}, 2, 2},
{"mixed", []bool{true, false, true, false}, 4, 2},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
doc := ast.NewDocument()
list := ast.NewList('-')
doc.AppendChild(doc, list)
for _, chk := range tc.checked {
li := ast.NewListItem(0)
tb := ast.NewTextBlock()
tb.AppendChild(tb, &TaskListItem{Checked: chk})
li.AppendChild(li, tb)
list.AppendChild(list, li)
}
total, done := CountTasks(doc)
if total != tc.wantTotal {
t.Errorf("total = %d, want %d", total, tc.wantTotal)
}
if done != tc.wantDone {
t.Errorf("done = %d, want %d", done, tc.wantDone)
}
})
}
}
func TestTriggerByte(t *testing.T) {
t.Parallel()
p := &taskParser{}
trig := p.Trigger()
if len(trig) != 1 || trig[0] != '[' {
t.Errorf("expected trigger '[', got %q", trig)
}
}