10
10
11
11
12
12
def special_sign ():
13
- chars_to_exclude = ["\n " , "\r " , "\r \n " , "\x0b " , "\v " , "\f " ] + list ( "@#$%&~>?+=:" ) + list ( "-_.~:/?#[]@!$&'()*+,;=%" )
13
+ chars_to_exclude = ["\n " , "\r " , "@ " , "/ " , ". " , " " , "(" , ")" , "&" ]
14
14
return st .text (min_size = 1 , max_size = 1 ).filter (lambda s : all (char not in s for char in chars_to_exclude ))
15
15
16
16
17
17
def special_sign_tuples ():
18
- return st .tuples (special_sign (), special_sign ())
18
+ return st .tuples (special_sign (), special_sign (), special_sign () )
19
19
20
20
21
21
@given (special_sign_tuples ())
22
22
def test_given_text_when_tags_not_separated_by_spaces_then_tokens_returned (special_signs ):
23
- text = f"@tag1(url1.png)@one{ special_signs [0 ]} more{ special_signs [1 ]} tag&and_word "
23
+ text = f"@tag1(url1.png)@one{ special_signs [0 ]} more{ special_signs [1 ]} tag&and { special_signs [ 2 ] } word "
24
24
fp = io .StringIO (text )
25
25
lexer = Lexer (fp , special_signs = special_signs )
26
26
tokens = get_all_tokens (lexer )
@@ -31,13 +31,6 @@ def test_given_text_when_tags_not_separated_by_spaces_then_tokens_returned(speci
31
31
TokenType .T_CHAR ,
32
32
TokenType .T_LITERAL ,
33
33
]
34
- assert [token .string for token in tokens ] == [
35
- "tag1" ,
36
- "url1.png" ,
37
- "one-more-tag" ,
38
- "&" ,
39
- "and_word" ,
40
- ]
41
34
assert [token .position for token in tokens ] == [
42
35
Position (1 , 1 ),
43
36
Position (1 , 6 ),
@@ -47,8 +40,9 @@ def test_given_text_when_tags_not_separated_by_spaces_then_tokens_returned(speci
47
40
]
48
41
49
42
50
- def test_given_complex_text_with_special_chars_then_sequence_of_tokens_is_returned ():
51
- text = "word1, word2 $$ @tag1-tag \n \n @tag2(start-of/url.png)"
43
+ @given (special_sign_tuples ())
44
+ def test_given_complex_text_with_special_chars_then_sequence_of_tokens_is_returned (special_signs ):
45
+ text = f"word1& word2 && @tag1{ special_signs [0 ]} tag \n \n @tag2(start{ special_signs [1 ]} of/url.png)"
52
46
expected_types = [
53
47
TokenType .T_LITERAL ,
54
48
TokenType .T_CHAR ,
@@ -66,23 +60,6 @@ def test_given_complex_text_with_special_chars_then_sequence_of_tokens_is_return
66
60
TokenType .T_IMAGE_SIZE_TAG ,
67
61
TokenType .T_IMAGE_URL ,
68
62
]
69
- expected_strings = [
70
- "word1" ,
71
- "," ,
72
- " " ,
73
- "word2" ,
74
- " " ,
75
- "$" ,
76
- "$" ,
77
- " " ,
78
- "tag1-tag" ,
79
- " " ,
80
- "\n " ,
81
- "\n " ,
82
- " " ,
83
- "tag2" ,
84
- "start-of/url.png" ,
85
- ]
86
63
expected_positions = [
87
64
Position (1 , 1 ),
88
65
Position (1 , 6 ),
@@ -101,10 +78,9 @@ def test_given_complex_text_with_special_chars_then_sequence_of_tokens_is_return
101
78
Position (3 , 7 ),
102
79
]
103
80
fp = io .StringIO (text )
104
- lexer = Lexer (fp )
81
+ lexer = Lexer (fp , special_signs = special_signs )
105
82
tokens = get_all_tokens (lexer )
106
83
assert len (tokens ) == len (expected_types )
107
84
assert len (tokens ) == len (expected_positions )
108
85
assert [token .type for token in tokens ] == expected_types
109
- assert [token .string for token in tokens ] == expected_strings
110
86
assert [token .position for token in tokens ] == expected_positions
0 commit comments