Files
byre/internal/todo/todo_test.go
T

59 lines
1.5 KiB
Go
Raw Normal View History

package todo_test
import (
"reflect"
"testing"
"g.fc.run/misc/byre/internal/api"
"g.fc.run/misc/byre/internal/todo"
)
func TestParse(t *testing.T) {
src := "# TODO\n\n" +
"Notes before the list are not items.\n\n" +
"- Public key pinning\n" +
" When libcurl4-openssl-dev >= 7.39.0, add support to the C client via the\n" +
" options struct for public key pinning.\n" +
"\n" +
" ```\n" +
" - not an item\n" +
" ```\n" +
"- [ ] Client ID rotation\n" +
" - JS client\n" +
" - C client\n" +
"- [x] Already done\n" +
" with a body\n" +
"\n" +
"## Web\n\n" +
"1. Double-click zoom in\n" +
"2. Pinch to zoom\n" +
"\n" +
"A trailing paragraph.\n"
want := []api.TodoItem{
{Title: "Public key pinning", Section: "TODO", Body: "When libcurl4-openssl-dev >= 7.39.0, add support to the C client via the\noptions struct for public key pinning.\n\n```\n- not an item\n```"},
{Title: "Client ID rotation", Section: "TODO", Body: "- JS client\n- C client"},
{Title: "Double-click zoom in", Section: "Web"},
{Title: "Pinch to zoom", Section: "Web"},
}
got := todo.Parse(src)
if !reflect.DeepEqual(got, want) {
t.Fatalf("parse:\n got %#v\nwant %#v", got, want)
}
item, ok := todo.Find(got, "Client ID rotation")
if !ok {
t.Fatalf("find: no item")
}
if md := todo.Markdown(item); md != "- Client ID rotation\n - JS client\n - C client" {
t.Fatalf("markdown: %q", md)
}
}
func TestParseEmpty(t *testing.T) {
if got := todo.Parse(""); len(got) != 0 {
t.Fatalf("parse empty: %#v", got)
}
}