package web
import (
"testing"
)
func TestTextToHtml(t *testing.T) {
testCases := []struct {
input, want string
}{
{
input: "html",
want: "html",
},
// Check it escapes.
{
input: "",
want: "<html>",
},
// Check for linebreaks.
{
input: "line\nbreak",
want: "line
\nbreak",
},
{
input: "line\r\nbreak",
want: "line
\nbreak",
},
{
input: "line\rbreak",
want: "line
\nbreak",
},
// Check URL detection.
{
input: "http://google.com/",
want: "http://google.com/",
},
{
input: "http://a.com/?q=a&n=v",
want: "http://a.com/?q=a&n=v",
},
{
input: "(http://a.com/?q=a&n=v)",
want: "(http://a.com/?q=a&n=v)",
},
}
for _, tc := range testCases {
t.Run(tc.input, func(t *testing.T) {
got := TextToHTML(tc.input)
if got != tc.want {
t.Errorf("TextToHTML(%q)\ngot : %q\nwant: %q", tc.input, got, tc.want)
}
})
}
}