From fb8f2d10984bcfa2585dc272b4c85d285b722792 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Mon, 28 Nov 2022 23:41:36 -0500 Subject: Hashtags --- tests/activities/models/test_hashtag.py | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/activities/models/test_hashtag.py (limited to 'tests/activities/models/test_hashtag.py') diff --git a/tests/activities/models/test_hashtag.py b/tests/activities/models/test_hashtag.py new file mode 100644 index 0000000..32742d6 --- /dev/null +++ b/tests/activities/models/test_hashtag.py @@ -0,0 +1,41 @@ +from activities.models import Hashtag + + +def test_hashtag_from_content(): + assert Hashtag.hashtags_from_content("#hashtag") == ["hashtag"] + assert Hashtag.hashtags_from_content("a#hashtag") == [] + assert Hashtag.hashtags_from_content("Text #with #hashtag in it") == [ + "hashtag", + "with", + ] + assert Hashtag.hashtags_from_content("#hashtag.") == ["hashtag"] + assert Hashtag.hashtags_from_content("More text\n#one # two ##three #hashtag;") == [ + "hashtag", + "one", + "three", + ] + + +def test_linkify_hashtag(): + linkify = Hashtag.linkify_hashtags + + assert linkify("# hashtag") == "# hashtag" + assert ( + linkify('Text') + == 'Text' + ) + assert ( + linkify("#HashTag") == '#HashTag' + ) + assert ( + linkify( + """A longer text #bigContent +with #tags, linebreaks, and +maybe a few links +#allTheTags #AllTheTags #ALLTHETAGS""" + ) + == """A longer text #bigContent +with #tags, linebreaks, and +maybe a few links +#allTheTags #AllTheTags #ALLTHETAGS""" + ) -- cgit v1.2.3