package web
import (
"strings"
"testing"
)
func TestAReplyIsMarkdownWithItsMathsLeftForKaTeX(t *testing.T) {
got := string(renderReply("Here is **bold** and `code`.\n\n" +
"The sum $a_1 * b_2$ and \\(x_i^2\\), then\n\n$$\\sum_{i=1}^n i$$\n\n" +
"```go\nfmt.Println(\"$5\")\n```\n\nIt costs $5 and $10."))
for _, want := range []string{
"bold", "code",
// Untouched by emphasis, and marked for KaTeX with its delimiters
// taken off.
`data-display="0" data-src="$a_1 * b_2$">a_1 * b_2`,
`>x_i^2`, `data-display="1" data-src="$$\sum_{i=1}^n i$$">\sum_{i=1}^n i`,
`
`,
"It costs $5 and $10.",
} {
if !strings.Contains(got, want) {
t.Errorf("missing %q in %s", want, got)
}
}
if strings.Contains(got, "llmgwmath") {
t.Errorf("a placeholder was left behind: %s", got)
}
}
func TestAReplyCannotRunAnything(t *testing.T) {
got := string(renderReply("\n\n[x](javascript:alert(1))\n\n" +
"$
$"))
for _, bad := range []string{"