ref: eeb17798b4624cdc32de8003ac1f937d7fc865c5
parent: 7b7138ad1a1f701a0b7831bb3efd8f31120eff65
parent: 7bafd6ddf7249311dff411162a9a36bd1c6add9a
author: penny64 <penny64@noreply.codeberg.org>
date: Wed Oct 8 16:21:49 EDT 2025
Merge pull request 'Implement initial unit test' (#8) from fops/hellclient:maintenance/initial-unittests into main Reviewed-on: https://codeberg.org/penny64/hellclient/pulls/8
--- a/config.go
+++ b/config.go
@@ -3,7 +3,6 @@
import (
"bytes"
"fmt"
- "io/ioutil"
"os"
"strings"
"time"
@@ -151,7 +150,7 @@
return nil, "", fmt.Errorf("error marshalling config: %w", err)}
- err = ioutil.WriteFile(configpath, b.Bytes(), 0644)
+ err = os.WriteFile(configpath, b.Bytes(), 0644)
if err != nil { return nil, "", fmt.Errorf("error writing config file: %w", err)}
--- a/filehandler.go
+++ b/filehandler.go
@@ -163,7 +163,7 @@
path = expandDir(path)
file, err := os.Open(path)
if err != nil {- return nil, fmt.Errorf("error opening file: %s", path, err)+ return nil, fmt.Errorf("error opening %s: %s", path, err)}
return file, nil
}
--- a/references.go
+++ b/references.go
@@ -57,7 +57,7 @@
}
func saveRef(statusMap map[string]*mastodon.Status, post *mastodon.Status, index *postref) {- (statusMap)[index.prefix + index.ref] = post
+ (statusMap)[index.prefix+index.ref] = post
}
func IncrementSequence(r rune) (rune, bool) {--- a/renderer.go
+++ b/renderer.go
@@ -17,13 +17,13 @@
postContext *postref
notif *mastodon.Notification
// Index for posts that aren't using the ref in postref
- localindex string
+ localindex string
}
// Returns the rendered content of a status's rt
func (st *StatusFormatter) reblogContent() string {currentpost := st.status
- defer func(){st.status = currentpost}()+ defer func() { st.status = currentpost }()return st.statusContent(st.status.Reblog)
}
@@ -82,6 +82,7 @@
}
return sb.String()
}
+
// Stringer for current index
type indexString struct {*StatusFormatter
@@ -157,7 +158,7 @@
return dl.detailLine()
}
-//Boosted username stringer
+// Boosted username stringer
type boostedusername struct {*StatusFormatter
}
--- /dev/null
+++ b/renderer_test.go
@@ -1,0 +1,53 @@
+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\">username</a> world</p>", "hello username world"},+ // a without href
+ {"<p>hello <a>world</a></p>", "hello [1]"}, // TODO: this is probably wrong+ }
+ 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)+ }
+ }
+}
--
⑨