File: test_hashtags.py

package info (click to toggle)
rednotebook 2.39%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,956 kB
  • sloc: python: 9,570; javascript: 4,103; xml: 128; sh: 58; makefile: 11
file content (45 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import re

from rednotebook.data import HASHTAG_PATTERN


def test_hashtags():
    vals = [
        ("test #hashtag", ["hashtag"]),
        ("text #hash0tag", ["hash0tag"]),
        ("text #1tag", ["1tag"]),
        ("text #hash_tag", ["hash_tag"]),
        ("text #1234", []),
        ("text #12é34", ["12é34"]),
        ("text#hashtag", []),
        ("texté#hashtag", []),
        ("text #hashtag1 #hashtag2", ["hashtag1", "hashtag2"]),
        ("text.#hashtag", ["hashtag"]),
        ("&#nbsp;", []),
        ("text #hashtag!", ["hashtag"]),
        ("text #dodge/#answer", ["dodge", "answer"]),
        ("text #dodge/answer", ["dodge"]),
        ("text dodge/#answer", ["answer"]),
        ("text #hashtagの", ["hashtagの"]),
        ("text #hashtag\u306e", ["hashtag\u306e"]),
        ("text #hashtag", ["hashtag"]),
        ("#hashtag text", ["hashtag"]),
        # (u"#hashtag", [u'hashtag']),
        ("#éhashtag", ["éhashtag"]),
        ("#hashtagé", ["hashtagé"]),
        ("#hashétag", ["hashétag"]),
        ("test #hashtag école", ["hashtag"]),
        ("hex #11ff22", []),
        ("hex start #11ff22abc", ["11ff22abc"]),
        ('<font color="#40e0d0">', []),
        ("test &#hashtag", []),
        ("test ##hashtag", []),
        ("test #!/usr/bin/env", []),
        ("#include_me", ["include_me"]),
        ("#include file", []),
    ]
    for text, tags in vals:
        print(repr(text))
        results = re.findall(HASHTAG_PATTERN, text, flags=re.I | re.U)
        results = [hashtag for _, _hash, hashtag in results]
        assert results == tags