/
test_stringparser.py
79 lines (58 loc) · 1.38 KB
/
test_stringparser.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from jupytext.stringparser import StringParser
def test_long_string(
text="""'''This is a multiline
comment with "quotes", 'single quotes'
# and comments
and line breaks
and it ends here'''
1 + 1
""",
):
quoted = []
sp = StringParser("python")
for i, line in enumerate(text.splitlines()):
if sp.is_quoted():
quoted.append(i)
sp.read_line(line)
assert quoted == [1, 2, 3, 4, 5, 6]
def test_single_chars(
text="""'This is a single line comment'''
'and another one'
# and comments
"and line breaks"
"and it ends here'''"
1 + 1
""",
):
sp = StringParser("python")
for line in text.splitlines():
assert not sp.is_quoted()
sp.read_line(line)
def test_long_string_with_four_quotes(
text="""''''This is a multiline
comment that starts with four quotes
'''
1 + 1
""",
):
quoted = []
sp = StringParser("python")
for i, line in enumerate(text.splitlines()):
if sp.is_quoted():
quoted.append(i)
sp.read_line(line)
assert quoted == [1, 2]
def test_long_string_ends_with_four_quotes(
text="""'''This is a multiline
comment that ends with four quotes
''''
1 + 1
""",
):
quoted = []
sp = StringParser("python")
for i, line in enumerate(text.splitlines()):
if sp.is_quoted():
quoted.append(i)
sp.read_line(line)
assert quoted == [1, 2]