- !post falls back to newest unposted story for the channel when the in-memory queue is empty (the steady state under round-robin). - Accept ❓️/❔️ (U+FE0F variation selector) as question reactions — the bare codepoints alone missed clients that render the colored emoji. - Rewrite Guardian i.guim.co.uk thumbnails to width=1200 so we stop rejecting real images as "tracking pixels"; relabel the size warning. - Log decrypt failures and reactions on events not in post_log so future silent drops surface instead of vanishing.
111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
package explainer
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestFormatSummary(t *testing.T) {
|
||
cases := []struct {
|
||
name string
|
||
in string
|
||
wantPlain string
|
||
wantHTML string
|
||
}{
|
||
{
|
||
name: "dash bullets",
|
||
in: "- First point.\n- Second point.\n- Third point.",
|
||
wantPlain: "• First point.\n• Second point.\n• Third point.",
|
||
wantHTML: "<ul><li>First point.</li><li>Second point.</li><li>Third point.</li></ul>",
|
||
},
|
||
{
|
||
name: "asterisk bullets",
|
||
in: "* alpha\n* beta",
|
||
wantPlain: "• alpha\n• beta",
|
||
wantHTML: "<ul><li>alpha</li><li>beta</li></ul>",
|
||
},
|
||
{
|
||
name: "unicode bullets",
|
||
in: "• one\n• two",
|
||
wantPlain: "• one\n• two",
|
||
wantHTML: "<ul><li>one</li><li>two</li></ul>",
|
||
},
|
||
{
|
||
name: "blank lines ignored",
|
||
in: "- a\n\n- b\n\n\n- c",
|
||
wantPlain: "• a\n• b\n• c",
|
||
wantHTML: "<ul><li>a</li><li>b</li><li>c</li></ul>",
|
||
},
|
||
{
|
||
name: "summary header stripped",
|
||
in: "Summary:\n- first\n- second",
|
||
wantPlain: "• first\n• second",
|
||
wantHTML: "<ul><li>first</li><li>second</li></ul>",
|
||
},
|
||
{
|
||
name: "tldr header stripped",
|
||
in: "TL;DR of the article\n- key point\n- other point",
|
||
wantPlain: "• key point\n• other point",
|
||
wantHTML: "<ul><li>key point</li><li>other point</li></ul>",
|
||
},
|
||
{
|
||
name: "single bullet",
|
||
in: "- just one",
|
||
wantPlain: "• just one",
|
||
wantHTML: "<ul><li>just one</li></ul>",
|
||
},
|
||
{
|
||
name: "html escaped in bullets",
|
||
in: `- A "quote" & <tag>`,
|
||
wantPlain: `• A "quote" & <tag>`,
|
||
wantHTML: "<ul><li>A "quote" & <tag></li></ul>",
|
||
},
|
||
{
|
||
name: "leading whitespace trimmed",
|
||
in: " - first\n - second ",
|
||
wantPlain: "• first\n• second",
|
||
wantHTML: "<ul><li>first</li><li>second</li></ul>",
|
||
},
|
||
}
|
||
for _, c := range cases {
|
||
t.Run(c.name, func(t *testing.T) {
|
||
gotPlain, gotHTML := formatSummary(c.in)
|
||
if gotPlain != c.wantPlain {
|
||
t.Errorf("plain:\n got %q\n want %q", gotPlain, c.wantPlain)
|
||
}
|
||
if gotHTML != c.wantHTML {
|
||
t.Errorf("html:\n got %q\n want %q", gotHTML, c.wantHTML)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
func TestFormatSummary_NoBulletsPassthrough(t *testing.T) {
|
||
in := "Just a single paragraph with no bullets at all."
|
||
plain, htmlBody := formatSummary(in)
|
||
if plain != in {
|
||
t.Errorf("plain should pass through raw, got %q", plain)
|
||
}
|
||
if !strings.HasPrefix(htmlBody, "<pre>") || !strings.HasSuffix(htmlBody, "</pre>") {
|
||
t.Errorf("html should wrap raw in <pre>, got %q", htmlBody)
|
||
}
|
||
if !strings.Contains(htmlBody, "single paragraph") {
|
||
t.Errorf("html should contain the body text, got %q", htmlBody)
|
||
}
|
||
}
|
||
|
||
func TestIsQuestionReaction(t *testing.T) {
|
||
want := []string{"❓", "❓️", "❔", "❔️", "⁉", "⁉️", "🤔", "?", "?"}
|
||
for _, k := range want {
|
||
if !IsQuestionReaction(k) {
|
||
t.Errorf("expected %q to trigger explain", k)
|
||
}
|
||
}
|
||
notQuestion := []string{"👍", "👎", "🔥", "", "??", "❤️"}
|
||
for _, k := range notQuestion {
|
||
if IsQuestionReaction(k) {
|
||
t.Errorf("expected %q to NOT trigger explain", k)
|
||
}
|
||
}
|
||
}
|