Artifact 3883bcc2e4e2f04f9b6945c14593ed22021c5869603012d21ab8a1c340aac89d:
- File
internal/api/poll_test.go
— part of check-in
[e674e718a8]
at
2026-08-21 19:34:28
on branch quarry-forum
— forum polls: fenced-block definition, OLTP ballots, no-script widget
The block syncs as markdown (fossil peers render it readably); option range and close date re-read from the body at cast time, never the form. (user: dmestas, size: 1240) [annotate] [blame] [check-ins using] [more...]
package api import ( "strings" "testing" "time" ) func TestParsePoll(t *testing.T) { body := "Voting time!\n\n```poll\nquestion: Which default?\n- trunk\n- main\ncloses: 2026-09-01\n```\n\nDiscuss below.\n" def, rest := parsePoll(body) if def == nil { t.Fatal("well-formed poll not parsed") } if def.Question != "Which default?" || len(def.Options) != 2 || def.Options[1] != "main" || def.Closes != "2026-09-01" { t.Fatalf("def = %+v", def) } if strings.Contains(rest, "```") || !strings.Contains(rest, "Discuss below.") { t.Fatalf("rest = %q", rest) } // Ballots accepted through the close day, frozen after it. if def.closed(time.Date(2026, 9, 1, 23, 0, 0, 0, time.UTC)) { t.Fatal("closed during its final day") } if !def.closed(time.Date(2026, 9, 2, 1, 0, 0, 0, time.UTC)) { t.Fatal("open past its close") } // Malformed polls degrade to plain markdown: body untouched. for _, bad := range []string{ "```poll\nquestion: x\n- only one option\n```", "```poll\n- a\n- b\n```", // no question "```poll\nquestion: x\n- a\n- b\n", // unterminated "no poll here", } { if def, rest := parsePoll(bad); def != nil || rest != bad { t.Fatalf("malformed %q parsed as %+v", bad, def) } } }