Spelling fixes
[docutils.git] / test / test_parsers / test_rst / test_TableParser.py
blob874efae5621d8eb3ba93b7ffd2cddb41cf28f9ed
1 #! /usr/bin/env python
2 # coding: utf8
4 # $Id$
5 # Author: David Goodger <goodger@python.org>
6 # Copyright: This module has been placed in the public domain.
8 """
9 Tests for states.py.
10 """
12 from __init__ import DocutilsTestSupport
14 def suite():
15 s = DocutilsTestSupport.GridTableParserTestSuite()
16 s.generateTests(totest)
17 return s
19 totest = {}
21 totest['grid_tables'] = [
22 ["""\
23 +-------------------------------------+
24 | A table with one cell and one line. |
25 +-------------------------------------+
26 """,
27 [(0, 0, 2, 38, ['A table with one cell and one line.'])],
28 ([37],
29 [],
30 [[(0, 0, 1, ['A table with one cell and one line.'])]])],
31 ["""\
32 +--------------+--------------+
33 | A table with | two columns. |
34 +--------------+--------------+
35 """,
36 [(0, 0, 2, 15, ['A table with']),
37 (0, 15, 2, 30, ['two columns.'])],
38 ([14, 14],
39 [],
40 [[(0, 0, 1, ['A table with']),
41 (0, 0, 1, ['two columns.'])]])],
42 # Combining chars in grid tables still fail
43 # [u"""\
44 # +--------------+------------------+
45 # | A tāble w̅ith | comb̲ining chars. |
46 # +--------------+------------------+
47 # """,
48 # [(0, 0, 2, 15, [u'A table with']),
49 # (0, 15, 2, 30, [u'combining chars.'])],
50 # ([14, 14],
51 # [],
52 # [[(0, 0, 1, [u'A table with']),
53 # (0, 0, 1, [u'combining chars.'])]])],
54 ["""\
55 +--------------+-------------+
56 | A table with | two columns |
57 +--------------+-------------+
58 | and | two rows. |
59 +--------------+-------------+
60 """,
61 [(0, 0, 2, 15, ['A table with']),
62 (0, 15, 2, 29, ['two columns']),
63 (2, 0, 4, 15, ['and']),
64 (2, 15, 4, 29, ['two rows.'])],
65 ([14, 13],
66 [],
67 [[(0, 0, 1, ['A table with']),
68 (0, 0, 1, ['two columns'])],
69 [(0, 0, 3, ['and']),
70 (0, 0, 3, ['two rows.'])]])],
71 ["""\
72 +--------------------------+
73 | A table with three rows, |
74 +------------+-------------+
75 | and two | columns. |
76 +------------+-------------+
77 | First and last rows |
78 | contain column spans. |
79 +--------------------------+
80 """,
81 [(0, 0, 2, 27, ['A table with three rows,']),
82 (2, 0, 4, 13, ['and two']),
83 (2, 13, 4, 27, ['columns.']),
84 (4, 0, 7, 27, ['First and last rows', 'contain column spans.'])],
85 ([12, 13],
86 [],
87 [[(0, 1, 1, ['A table with three rows,']),
88 None],
89 [(0, 0, 3, ['and two']),
90 (0, 0, 3, ['columns.'])],
91 [(0, 1, 5, ['First and last rows', 'contain column spans.']),
92 None]])],
93 ["""\
94 +------------+-------------+---------------+
95 | A table | two rows in | and row spans |
96 | with three +-------------+ to left and |
97 | columns, | the middle, | right. |
98 +------------+-------------+---------------+
99 """,
100 [(0, 0, 4, 13, ['A table', 'with three', 'columns,']),
101 (0, 13, 2, 27, ['two rows in']),
102 (0, 27, 4, 43, ['and row spans', 'to left and', 'right.']),
103 (2, 13, 4, 27, ['the middle,'])],
104 ([12, 13, 15],
106 [[(1, 0, 1, ['A table', 'with three', 'columns,']),
107 (0, 0, 1, ['two rows in']),
108 (1, 0, 1, ['and row spans', 'to left and', 'right.'])],
109 [None,
110 (0, 0, 3, ['the middle,']),
111 None]])],
112 ["""\
113 +------------+-------------+---------------+
114 | A table | | two rows in | and funny |
115 | with 3 +--+-------------+-+ stuff. |
116 | columns, | the middle, | | |
117 +------------+-------------+---------------+
118 """,
119 [(0, 0, 4, 13, ['A table |', 'with 3 +--', 'columns,']),
120 (0, 13, 2, 27, ['two rows in']),
121 (0, 27, 4, 43, [' and funny', '-+ stuff.', ' |']),
122 (2, 13, 4, 27, ['the middle,'])],
123 ([12, 13, 15],
125 [[(1, 0, 1, ['A table |', 'with 3 +--', 'columns,']),
126 (0, 0, 1, ['two rows in']),
127 (1, 0, 1, [' and funny', '-+ stuff.', ' |'])],
128 [None,
129 (0, 0, 3, ['the middle,']),
130 None]])],
131 ["""\
132 +-----------+-------------------------+
133 | W/NW cell | N/NE cell |
134 | +-------------+-----------+
135 | | Middle cell | E/SE cell |
136 +-----------+-------------+ |
137 | S/SE cell | |
138 +-------------------------+-----------+
139 """,
140 [(0, 0, 4, 12, ['W/NW cell', '', '']),
141 (0, 12, 2, 38, ['N/NE cell']),
142 (2, 12, 4, 26, ['Middle cell']),
143 (2, 26, 6, 38, ['E/SE cell', '', '']),
144 (4, 0, 6, 26, ['S/SE cell'])],
145 ([11, 13, 11],
147 [[(1, 0, 1, ['W/NW cell', '', '']),
148 (0, 1, 1, ['N/NE cell']),
149 None],
150 [None,
151 (0, 0, 3, ['Middle cell']),
152 (1, 0, 3, ['E/SE cell', '', ''])],
153 [(0, 1, 5, ['S/SE cell']),
154 None,
155 None]])],
156 ["""\
157 +--------------+-------------+
158 | A bad table. | |
159 +--------------+ |
160 | Cells must be rectangles. |
161 +----------------------------+
162 """,
163 'TableMarkupError: Malformed table; parse incomplete.',
164 'TableMarkupError: Malformed table; parse incomplete.'],
165 ["""\
166 +-------------------------------+
167 | A table with two header rows, |
168 +------------+------------------+
169 | the first | with a span. |
170 +============+==================+
171 | Two body | rows, |
172 +------------+------------------+
173 | the second with a span. |
174 +-------------------------------+
175 """,
176 [(0, 0, 2, 32, ['A table with two header rows,']),
177 (2, 0, 4, 13, ['the first']),
178 (2, 13, 4, 32, ['with a span.']),
179 (4, 0, 6, 13, ['Two body']),
180 (4, 13, 6, 32, ['rows,']),
181 (6, 0, 8, 32, ['the second with a span.'])],
182 ([12, 18],
183 [[(0, 1, 1, ['A table with two header rows,']),
184 None],
185 [(0, 0, 3, ['the first']),
186 (0, 0, 3, ['with a span.'])]],
187 [[(0, 0, 5, ['Two body']),
188 (0, 0, 5, ['rows,'])],
189 [(0, 1, 7, ['the second with a span.']),
190 None]])],
191 ["""\
192 +-------------------------------+
193 | A table with two head/body |
194 +=============+=================+
195 | row | separators. |
196 +=============+=================+
197 | That's bad. | |
198 +-------------+-----------------+
199 """,
200 'TableMarkupError: Multiple head/body row separators '
201 '(table lines 3 and 5); only one allowed.',
202 'TableMarkupError: Multiple head/body row separators '
203 '(table lines 3 and 5); only one allowed.'],
204 ["""\
205 +-------------------------------------+
207 +-------------------------------------+
208 """,
209 [(0, 0, 2, 38, [''])],
210 ([37],
212 [[(0, 0, 1, [''])]])],
216 if __name__ == '__main__':
217 import unittest
218 unittest.main(defaultTest='suite')