2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/ *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   GoToSocial 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-20 18:42:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   Copyright  ( C )  2021 - 2022  GoToSocial  Authors  admin @ gotosocial . org 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   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  < http : //www.gnu.org/licenses/>. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* /  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								package  text_test  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2021-08-25 15:34:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"testing" 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-01 14:10:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"time" 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/stretchr/testify/suite" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  (  
						 
					
						
							
								
									
										
										
										
											2022-07-19 15:21:17 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									replaceMentionsString                  =  "Another test @foss_satan@fossbros-anonymous.io\n\n#Hashtag\n\nText" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									replaceMentionsExpected                =  "Another test <span class=\"h-card\"><a href=\"http://fossbros-anonymous.io/@foss_satan\" class=\"u-url mention\">@<span>foss_satan</span></a></span>\n\n#Hashtag\n\nText" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									replaceHashtagsExpected                =  "Another test @foss_satan@fossbros-anonymous.io\n\n<a href=\"http://localhost:8080/tags/Hashtag\" class=\"mention hashtag\" rel=\"tag\">#<span>Hashtag</span></a>\n\nText" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									replaceHashtagsAfterMentionsExpected   =  "Another test <span class=\"h-card\"><a href=\"http://fossbros-anonymous.io/@foss_satan\" class=\"u-url mention\">@<span>foss_satan</span></a></span>\n\n<a href=\"http://localhost:8080/tags/Hashtag\" class=\"mention hashtag\" rel=\"tag\">#<span>Hashtag</span></a>\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 <span class=\"h-card\"><a href=\"http://fossbros-anonymous.io/@foss_satan\" class=\"u-url mention\">@<span>foss_satan</span></a></span>\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: <span class=\"h-card\"><a href=\"http://localhost:8080/@the_mighty_zork\" class=\"u-url mention\">@<span>the_mighty_zork</span></a></span>\n\nand linking to my own status: https://localhost:8080/@the_mighty_zork/statuses/01FGXKJRX2PMERJQ9EQF8Y6HCR" 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  CommonTestSuite  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									TextStandardTestSuite 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( suite  * CommonTestSuite )  TestReplaceMentions ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									foundMentions  :=  [ ] * gtsmodel . Mention { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										suite . testMentions [ "zork_mention_foss_satan" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-25 15:34:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									f  :=  suite . formatter . ReplaceMentions ( context . Background ( ) ,  replaceMentionsString ,  foundMentions ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-01 14:10:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									suite . Equal ( replaceMentionsExpected ,  f ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( suite  * CommonTestSuite )  TestReplaceHashtags ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									foundTags  :=  [ ] * gtsmodel . Tag { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										suite . testTags [ "Hashtag" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-25 15:34:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									f  :=  suite . formatter . ReplaceTags ( context . Background ( ) ,  replaceMentionsString ,  foundTags ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-10-01 14:10:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									suite . Equal ( replaceHashtagsExpected ,  f ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( suite  * CommonTestSuite )  TestReplaceHashtagsAfterReplaceMentions ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									foundTags  :=  [ ] * gtsmodel . Tag { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										suite . testTags [ "Hashtag" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-25 15:34:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									f  :=  suite . formatter . ReplaceTags ( context . Background ( ) ,  replaceMentionsExpected ,  foundTags ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-10-01 14:10:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									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 ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-11 16:54:54 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  TestCommonTestSuite ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									suite . Run ( t ,  new ( CommonTestSuite ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}