From 49beb17a8fbdbf3517c103a477a5459a3bba404d Mon Sep 17 00:00:00 2001
From: Autumn! <86073772+autumnull@users.noreply.github.com>
Date: Fri, 3 Feb 2023 10:58:58 +0000
Subject: [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
---
internal/text/common_test.go | 106 -------------------------------------------
1 file changed, 106 deletions(-)
delete mode 100644 internal/text/common_test.go
(limited to 'internal/text/common_test.go')
diff --git a/internal/text/common_test.go b/internal/text/common_test.go
deleted file mode 100644
index 3949226ca..000000000
--- a/internal/text/common_test.go
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
-*/
-
-package text_test
-
-import (
- "context"
- "testing"
- "time"
-
- "github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-const (
- replaceMentionsString = "Another test @foss_satan@fossbros-anonymous.io\n\n#Hashtag\n\nText"
- replaceMentionsExpected = "Another test @foss_satan\n\n#Hashtag\n\nText"
- replaceHashtagsExpected = "Another test @foss_satan@fossbros-anonymous.io\n\n#Hashtag\n\nText"
- replaceHashtagsAfterMentionsExpected = "Another test @foss_satan\n\n#Hashtag\n\nText"
- replaceMentionsWithLinkString = "Another test @foss_satan@fossbros-anonymous.io\n\nhttp://fossbros-anonymous.io/@foss_satan/statuses/6675ee73-fccc-4562-a46a-3e8cd9798060"
- replaceMentionsWithLinkStringExpected = "Another test @foss_satan\n\nhttp://fossbros-anonymous.io/@foss_satan/statuses/6675ee73-fccc-4562-a46a-3e8cd9798060"
- replaceMentionsWithLinkSelfString = "Mentioning myself: @the_mighty_zork\n\nand linking to my own status: https://localhost:8080/@the_mighty_zork/statuses/01FGXKJRX2PMERJQ9EQF8Y6HCR"
- replaceMemtionsWithLinkSelfExpected = "Mentioning myself: @the_mighty_zork\n\nand linking to my own status: https://localhost:8080/@the_mighty_zork/statuses/01FGXKJRX2PMERJQ9EQF8Y6HCR"
-)
-
-type CommonTestSuite struct {
- TextStandardTestSuite
-}
-
-func (suite *CommonTestSuite) TestReplaceMentions() {
- foundMentions := []*gtsmodel.Mention{
- suite.testMentions["zork_mention_foss_satan"],
- }
-
- f := suite.formatter.ReplaceMentions(context.Background(), replaceMentionsString, foundMentions)
- suite.Equal(replaceMentionsExpected, f)
-}
-
-func (suite *CommonTestSuite) TestReplaceHashtags() {
- foundTags := []*gtsmodel.Tag{
- suite.testTags["Hashtag"],
- }
-
- f := suite.formatter.ReplaceTags(context.Background(), replaceMentionsString, foundTags)
-
- suite.Equal(replaceHashtagsExpected, f)
-}
-
-func (suite *CommonTestSuite) TestReplaceHashtagsAfterReplaceMentions() {
- foundTags := []*gtsmodel.Tag{
- suite.testTags["Hashtag"],
- }
-
- f := suite.formatter.ReplaceTags(context.Background(), replaceMentionsExpected, foundTags)
-
- suite.Equal(replaceHashtagsAfterMentionsExpected, f)
-}
-
-func (suite *CommonTestSuite) TestReplaceMentionsWithLink() {
- foundMentions := []*gtsmodel.Mention{
- suite.testMentions["zork_mention_foss_satan"],
- }
-
- f := suite.formatter.ReplaceMentions(context.Background(), replaceMentionsWithLinkString, foundMentions)
- suite.Equal(replaceMentionsWithLinkStringExpected, f)
-}
-
-func (suite *CommonTestSuite) TestReplaceMentionsWithLinkSelf() {
- mentioningAccount := suite.testAccounts["local_account_1"]
-
- foundMentions := []*gtsmodel.Mention{
- {
- ID: "01FGXKN5F815DVFVD53PN9NYM6",
- CreatedAt: time.Now(),
- UpdatedAt: time.Now(),
- StatusID: "01FGXKP0S5THQXFC1D9R141DDR",
- OriginAccountID: mentioningAccount.ID,
- TargetAccountID: mentioningAccount.ID,
- NameString: "@the_mighty_zork",
- TargetAccountURI: mentioningAccount.URI,
- TargetAccountURL: mentioningAccount.URL,
- },
- }
-
- f := suite.formatter.ReplaceMentions(context.Background(), replaceMentionsWithLinkSelfString, foundMentions)
- suite.Equal(replaceMemtionsWithLinkSelfExpected, f)
-}
-
-func TestCommonTestSuite(t *testing.T) {
- suite.Run(t, new(CommonTestSuite))
-}
--
cgit v1.2.3