mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 04:52:24 -05:00
Text duplication fix (#137)
* start testing text duplication * tests * fixes + tests
This commit is contained in:
parent
8330263965
commit
329a5e8144
13 changed files with 696 additions and 42 deletions
|
|
@ -46,7 +46,7 @@ func DeriveHashtagsFromStatus(status string) []string {
|
|||
for _, m := range HashtagFinderRegex.FindAllStringSubmatch(status, -1) {
|
||||
tags = append(tags, strings.TrimPrefix(m[1], "#"))
|
||||
}
|
||||
return uniqueLower(tags)
|
||||
return unique(tags)
|
||||
}
|
||||
|
||||
// DeriveEmojisFromStatus takes a plaintext (ie., not html-formatted) status,
|
||||
|
|
@ -92,17 +92,3 @@ func unique(s []string) []string {
|
|||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// uniqueLower returns a deduplicated version of a given string slice, with all entries converted to lowercase
|
||||
func uniqueLower(s []string) []string {
|
||||
keys := make(map[string]bool)
|
||||
list := []string{}
|
||||
for _, entry := range s {
|
||||
eLower := strings.ToLower(entry)
|
||||
if _, value := keys[eLower]; !value {
|
||||
keys[eLower] = true
|
||||
list = append(list, eLower)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ func (suite *StatusTestSuite) TestDeriveHashtagsOK() {
|
|||
assert.Equal(suite.T(), "testing123", tags[0])
|
||||
assert.Equal(suite.T(), "also", tags[1])
|
||||
assert.Equal(suite.T(), "thisshouldwork", tags[2])
|
||||
assert.Equal(suite.T(), "thisshouldalsowork", tags[3])
|
||||
assert.Equal(suite.T(), "ThisShouldAlsoWork", tags[3])
|
||||
assert.Equal(suite.T(), "111111", tags[4])
|
||||
}
|
||||
|
||||
|
|
@ -108,6 +108,26 @@ Here's some normal text with an :emoji: at the end
|
|||
assert.Equal(suite.T(), "underscores_ok_too", tags[6])
|
||||
}
|
||||
|
||||
func (suite *StatusTestSuite) TestDeriveMultiple() {
|
||||
statusText := `Another test @foss_satan@fossbros-anonymous.io
|
||||
|
||||
#Hashtag
|
||||
|
||||
Text`
|
||||
|
||||
ms := util.DeriveMentionsFromStatus(statusText)
|
||||
hs := util.DeriveHashtagsFromStatus(statusText)
|
||||
es := util.DeriveEmojisFromStatus(statusText)
|
||||
|
||||
assert.Len(suite.T(), ms, 1)
|
||||
assert.Equal(suite.T(), "@foss_satan@fossbros-anonymous.io", ms[0])
|
||||
|
||||
assert.Len(suite.T(), hs, 1)
|
||||
assert.Equal(suite.T(), "Hashtag", hs[0])
|
||||
|
||||
assert.Len(suite.T(), es, 0)
|
||||
}
|
||||
|
||||
func TestStatusTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(StatusTestSuite))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue