twitter: add hashtag normalization test.

Add test for #4243. Also fix warning from bootsnap:

    iseq.rb:18: warning: nested repeat operator '+' and '?' was replaced with '*' in regular expression: /(?<!\A)生誕祭(?:\d+)?\z/
This commit is contained in:
evazion
2020-01-05 17:36:04 -06:00
parent 692e5957a2
commit faeec18efc
2 changed files with 16 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ module Sources::Strategies
# The regexes will not match if there is nothing preceding
# the pattern to avoid creating empty strings.
COMMON_TAG_REGEXES = [
/(?<!\A)生誕祭(?:\d+)?\z/,
/(?<!\A)生誕祭(?:\d*)\z/,
/(?<!\A)版もうひとつの深夜の真剣お絵描き60分一本勝負(?:_\d+)?\z/,
/(?<!\A)版深夜の真剣お絵描き60分一本勝負(?:_\d+)?\z/,
/(?<!\A)深夜の真剣お絵描き60分一本勝負(?:_\d+)?\z/,

View File

@@ -259,5 +259,20 @@ module Sources
assert_nil(site.image_url)
end
end
context "A tweet with hashtags" do
should "ignore common suffixes when translating hashtags" do
as(create(:user)) do
create(:tag, name: "nishizumi_miho", post_count: 1)
create(:wiki_page, title: "nishizumi_miho", other_names: "西住みほ")
end
site = Sources::Strategies.find("https://twitter.com/kasaishin100/status/1186658635226607616")
assert_includes(site.tags.map(&:first), "西住みほ生誕祭2019")
assert_includes(site.normalized_tags, "西住みほ")
assert_includes(site.translated_tags.map(&:name), "nishizumi_miho")
end
end
end
end