summaryrefslogtreecommitdiff
path: root/internal/text/formatter_test.go
diff options
context:
space:
mode:
authorLibravatar Autumn! <86073772+autumnull@users.noreply.github.com>2023-02-03 10:58:58 +0000
committerLibravatar GitHub <noreply@github.com>2023-02-03 11:58:58 +0100
commit49beb17a8fbdbf3517c103a477a5459a3bba404d (patch)
tree364c82d4089c75d3b95a5d78fd31b33d91b30b59 /internal/text/formatter_test.go
parent[bugfix] Read Bookwyrm Articles more thoroughly (#1410) (diff)
downloadgotosocial-49beb17a8fbdbf3517c103a477a5459a3bba404d.tar.xz
[chore] Text formatting overhaul (#1406)
* Implement goldmark debug print for hashtags and mentions * Minify HTML in FromPlain * Convert plaintext status parser to goldmark * Move mention/tag/emoji finding logic into formatter * Combine mention and hashtag boundary characters * Normalize unicode when rendering hashtags
Diffstat (limited to 'internal/text/formatter_test.go')
-rw-r--r--internal/text/formatter_test.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/internal/text/formatter_test.go b/internal/text/formatter_test.go
index 438a69c78..32ae74488 100644
--- a/internal/text/formatter_test.go
+++ b/internal/text/formatter_test.go
@@ -19,9 +19,13 @@
package text_test
import (
+ "context"
"github.com/stretchr/testify/suite"
+ "github.com/superseriousbusiness/gotosocial/internal/concurrency"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
+ "github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/text"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -29,7 +33,8 @@ import (
type TextStandardTestSuite struct {
// standard suite interfaces
suite.Suite
- db db.DB
+ db db.DB
+ parseMention gtsmodel.ParseMentionFunc
// standard suite models
testTokens map[string]*gtsmodel.Token
@@ -41,6 +46,7 @@ type TextStandardTestSuite struct {
testStatuses map[string]*gtsmodel.Status
testTags map[string]*gtsmodel.Tag
testMentions map[string]*gtsmodel.Mention
+ testEmojis map[string]*gtsmodel.Emoji
// module being tested
formatter text.Formatter
@@ -56,6 +62,7 @@ func (suite *TextStandardTestSuite) SetupSuite() {
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
+ suite.testEmojis = testrig.NewTestEmojis()
}
func (suite *TextStandardTestSuite) SetupTest() {
@@ -63,6 +70,11 @@ func (suite *TextStandardTestSuite) SetupTest() {
testrig.InitTestConfig()
suite.db = testrig.NewTestDB()
+
+ fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
+ federator := testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../testrig/media"), suite.db, fedWorker), nil, nil, fedWorker)
+ suite.parseMention = processing.GetParseMentionFunc(suite.db, federator)
+
suite.formatter = text.NewFormatter(suite.db)
testrig.StandardDBSetup(suite.db, nil)
@@ -71,3 +83,11 @@ func (suite *TextStandardTestSuite) SetupTest() {
func (suite *TextStandardTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}
+
+func (suite *TextStandardTestSuite) FromMarkdown(text string) *text.FormatResult {
+ return suite.formatter.FromMarkdown(context.Background(), suite.parseMention, suite.testAccounts["local_account_1"].ID, "status_ID", text)
+}
+
+func (suite *TextStandardTestSuite) FromPlain(text string) *text.FormatResult {
+ return suite.formatter.FromPlain(context.Background(), suite.parseMention, suite.testAccounts["local_account_1"].ID, "status_ID", text)
+}