ref: 027d91d776b79d3a75125a191f511a2948d1b4b6
parent: 7b7138ad1a1f701a0b7831bb3efd8f31120eff65
author: fops <billgates@cock.li>
date: Wed Oct 8 09:53:03 EDT 2025
Implement initial renderer test
--- /dev/null
+++ b/renderer_test.go
@@ -1,0 +1,51 @@
+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 world"}, // TODO: Verify that this is correct+ {"<pre>hello <a href=\"https://example.com\">world</a></pre>", "hello (world) [1]"}, // TODO: Verify that this is correct+ {"<pre>hello & world</pre>", "hello & world"},+ // Mentions
+ {"<p>hello <a href=\"https://example.com\" class=\"mention\"are usernames irrelevant</a>world</p>", "hello world"}, // TODO: Verify that this is correct+ }
+ for _, param := range parameters {+ sf := &StatusFormatter{+ hc: &Hellclient{+ urlMap: make(map[string][]string), // Initialize urlMap to avoid nil map assignment
+ },
+ status: &mastodon.Status{+ Content: param.post,
+ },
+ postContext: &postref{ref: "1"},+ }
+ rendered := sf.statusContent(sf.status)
+ if rendered != param.expected {+ t.Errorf("Expected rendered content to be '%s', got '%s'", param.expected, rendered)+ }
+ }
+}
--
⑨