ref: 5dccb5b06dda55efa1ceab2fb260eb895fd8e809
dir: /renderer_test.go/
package main
import (
"testing"
mastodon "codeberg.org/penny64/hellclient-go-mastodon"
)
func TestStatusFormatterStatus(t *testing.T) {
parameters := []struct {
post, expected string
}{
{"hello world", "hello world"},
{"<p>hello world</p>", "hello world"},
{"<p>hello <a href=\"https://example.com\">world</a></p>", "hello (world) [1]"},
{"<p>hello <a href=\"https://example.com\">world</a> and <a href=\"https://example.org\">universe</a></p>", "hello (world) [1] and (universe) [2]"},
{"<p>hello & world</p>", "hello & world"},
{"<p>hello<br>world</p>", "hello\r\nworld"},
{"<p>hello<br/>world</p>", "hello\r\nworld"},
{"<p>hello<br />world</p>", "hello\r\nworld"},
// consequetive NBSP shouldn't be collapsed
{"<p>hello world</p>", "hello\u00a0world"},
{"<p>hello world</p>", "hello\u00a0\u00a0world"},
{"<p>hello world</p>", "hello\u00a0\u00a0\u00a0world"},
{"<p>hello<br> world</p>", "hello\r\n\u00a0world"},
{"<p>hello<br> world</p>", "hello\r\n\u00a0\u00a0world"},
{"<p>hello<br> world</p>", "hello\r\n\u00a0\u00a0\u00a0world"},
// <pre> tests
{"<pre>hello world</pre>", "hello world"},
{"<pre>hello\nworld</pre>", "hello\nworld"},
{"<pre>hello <a href=\"https://example.com\">world</a></pre>", "hello (world) [1]"},
{"<pre>hello & world</pre>", "hello & world"},
// Mentions
{"<p>hello <a href=\"https://example.com\" class=\"mention\">username</a> world</p>", "hello username world"},
// a without href
{"<p>hello<a>world</a></p>", "hello"},
}
for _, param := range parameters {
sf := &StatusFormatter{
status: &mastodon.Status{
Content: param.post,
},
postContext: &postref{ref: "1", urlmap: make(map[string][]string)},
}
rendered := sf.statusContent(sf.status)
if rendered != param.expected {
t.Errorf("Expected rendered content to be '%s', got '%s'", param.expected, rendered)
}
}
}