fluid-telegram/internal/adapter/render_test.go

41 lines
1 KiB
Go
Raw Normal View History

package adapter
import "testing"
func TestRenderHTML(t *testing.T) {
cases := []struct {
name string
in string
want string
}{
{"heading", "# Title\nbody", "<b>Title</b>\nbody"},
{"bold", "this is **bold** text", "this is <b>bold</b> text"},
{"italic", "this is _italic_ text", "this is <i>italic</i> text"},
{"link", "see [the entry](https://example.com/e/1)", `see <a href="https://example.com/e/1">the entry</a>`},
{"code", "```go\nfmt.Println(1)\n```", "<pre>fmt.Println(1)</pre>"},
{
"table",
"| a | b |\n|---|---|\n| 1 | 2 |",
"a — b\n\n1 — 2",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := RenderHTML(tc.in)
if err != nil {
t.Fatalf("RenderHTML(%q): %v", tc.in, err)
}
if got != tc.want {
t.Errorf("RenderHTML(%q) = %q, want %q", tc.in, got, tc.want)
}
})
}
}
func TestRenderHTMLRejectsRawAngleBrackets(t *testing.T) {
_, err := RenderHTML("a <script> tag")
if err == nil {
t.Fatal("expected an error for raw angle brackets")
}
}