/
test_preformatted_paragraphs.py
137 lines (122 loc) · 3.78 KB
/
test_preformatted_paragraphs.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf8 -*-
from mediawiki_parser.tests import ParserTestCase
class PreformattedParagraphsTests(ParserTestCase):
def test_single_line_paragraph(self):
source = " This is a preformatted paragraph.\n"
result = """body:
preformatted_lines:
preformatted_line:
preformatted_inline:
raw_text:This is a preformatted paragraph.
EOL_KEEP:
"""
self.parsed_equal_tree(source, result, None)
def test_preformatted_and_normal_paragraphs(self):
source = """ This is a preformatted paragraph.
Followed by a "normal" one.
"""
result = """body:
preformatted_lines:
preformatted_line:
preformatted_inline:
raw_text:This is a preformatted paragraph.
EOL_KEEP:
paragraphs:
paragraph:
raw_text:Followed by a "normal" one."""
self.parsed_equal_tree(source, result, None)
def test_multiline_paragraph(self):
source = """ This is a multiline
preformatted paragraph.
"""
result = """body:
preformatted_lines:
preformatted_line:
preformatted_inline:
raw_text:This is a multiline
EOL_KEEP:
preformatted_line:
preformatted_inline:
raw_text:preformatted paragraph.
EOL_KEEP:
"""
self.parsed_equal_tree(source, result, None)
def test_style_in_preformatted_paragraph(self):
source = """ Styled text such as ''italic'', '''bold''', {{templates}} also work.
"""
result = """body:
preformatted_lines:
preformatted_line:
preformatted_inline:
raw_text:Styled text such as ''italic'', '''bold''',
internal_link:
page_name:Template:templates
raw_text: also work.
EOL_KEEP:
"""
self.parsed_equal_tree(source, result, None)
def test_tabs_in_preformatted_paragraph(self):
source = """ Preformatted\tparagraph
\twith
\t\tmultiple tabs.
"""
result = """body:
preformatted_lines:
preformatted_line:
preformatted_inline:
raw_text:Preformatted
tab_to_8_spaces:
raw_text:paragraph
EOL_KEEP:
preformatted_line:
preformatted_inline:
tab_to_8_spaces:
raw_text:with
EOL_KEEP:
preformatted_line:
preformatted_inline:
tab_to_8_spaces:
tab_to_8_spaces:
raw_text:multiple tabs.
EOL_KEEP:
"""
self.parsed_equal_tree(source, result, None)
def test_html_pre_paragraph(self):
source = """<pre>
Preformatted paragraph.
</pre>
"""
result = """body:
preformatted_paragraph:
preformatted_text:
raw_text:Preformatted paragraph."""
self.parsed_equal_tree(source, result, None)
def test_formatted_html_pre_paragraph(self):
# <pre> should act like <nowiki>
source = "<pre>some [[text]] that should {{not}} be changed</pre>\n"
result = "[paragraphs:[paragraph:[preformatted:'some [[text]] that should {{not}} be changed']]]"
self.parsed_equal_string(source, result, None)
def test_html_pre_in_paragraph(self):
source = "Normal paragraph <pre>Preformatted one</pre> Normal one.\n"
result = """body:
paragraphs:
paragraph:
raw_text:Normal paragraph
preformatted:Preformatted one
raw_text: Normal one."""
self.parsed_equal_tree(source, result, None)
def test_pre_paragraph_in_table(self):
source = """{|
|-
! <pre>Text</pre>
|}
"""
result = """body:
table:
table_line_break:
table_line_header:
table_cell:
table_cell_content:
raw_text:
preformatted:Text"""
self.parsed_equal_tree(source, result, None)