package tgfmt import "testing" func TestEscapeHTML(t *testing.T) { got := EscapeHTML(``) want := HTML(`<tag attr="a&b">`) if got != want { t.Fatalf("EscapeHTML() = %q, want %q", got, want) } } func TestHTMLComposesWithoutDoubleEscaping(t *testing.T) { got := EscapeHTML("").Bold().Italic() want := HTML("<b>") if got != want { t.Fatalf("formatted HTML = %q, want %q", got, want) } } func TestHTMLFormattingMethods(t *testing.T) { tests := []struct { name string got HTML want HTML }{ {name: "bold", got: EscapeHTML("text").Bold(), want: "text"}, {name: "italic", got: EscapeHTML("text").Italic(), want: "text"}, {name: "underline", got: EscapeHTML("text").Underline(), want: "text"}, {name: "strikethrough", got: EscapeHTML("text").Strikethrough(), want: "text"}, {name: "spoiler", got: EscapeHTML("text").Spoiler(), want: "text"}, {name: "inline code", got: EscapeHTML("text").InlineCode(), want: "text"}, {name: "block code", got: EscapeHTML("text").BlockCode(), want: "
text
"}, {name: "block code language", got: EscapeHTML("text").BlockCodeLanguage(`go"`), want: `
text
`}, {name: "quote", got: EscapeHTML("text").Quote(), want: "
text
"}, {name: "expandable quote", got: EscapeHTML("text").QuoteExpandable(), want: "
text
"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if tt.got != tt.want { t.Fatalf("formatted HTML = %q, want %q", tt.got, tt.want) } }) } } func TestHTMLLinkEscapesAttributes(t *testing.T) { got := EscapeHTML("Laniakea").Link(`https://example.test/?q="a&b"`) want := HTML(`Laniakea`) if got != want { t.Fatalf("Link() = %q, want %q", got, want) } } func TestHTMLSpecialLinks(t *testing.T) { tests := []struct { name string got HTML want HTML }{ {name: "mention", got: EscapeHTML("User").Mention(123), want: `User`}, {name: "emoji", got: EscapeHTML("emoji").Emoji(`12"3`), want: `emoji`}, {name: "time", got: EscapeHTML("date").Time(1772323200), want: `date`}, {name: "time format", got: EscapeHTML("date").TimeFormat(1772323200, `MMM " yyyy`), want: `date`}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if tt.got != tt.want { t.Fatalf("formatted HTML link = %q, want %q", tt.got, tt.want) } }) } }