Fix [ 2926161 ] for simple tables.
[docutils.git] / test / test_parsers / test_rst / test_SimpleTableParser.py
blobb755e33d9a38b1abfe2736048d75938ea91afd91
1 #! /usr/bin/env python
2 # .. coding: utf-8
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.SimpleTableParserTestSuite()
16 s.generateTests(totest)
17 return s
19 totest = {}
21 totest['simple_tables'] = [
22 ["""\
23 ============ ============
24 A table with two columns.
25 ============ ============
26 """,
27 ([12, 12],
28 [],
29 [[[0, 0, 1, ['A table with']],
30 [0, 0, 1, ['two columns.']]]])],
31 [u"""\
32 ============ ===============
33 A tāble w̅ith comb̲ining chars
34 ============ ===============
35 """,
36 ([12, 15],
37 [],
38 [[[0, 0, 1, [u'A ta\u0304ble w\u0305ith']],
39 [0, 0, 1, [u'comb\u0332ining chars']]]])],
40 ["""\
41 ============ ============
42 A table with two columns
43 and two rows.
44 ============ ============
45 """,
46 ([12, 12],
47 [],
48 [[[0, 0, 1, ['A table with']],
49 [0, 0, 1, ['two columns']]],
50 [[0, 0, 2, ['and']],
51 [0, 0, 2, ['two rows.']]]])],
52 ["""\
53 ======================================
54 The last row might stick into the margin
55 second row.
56 ======================================
57 """,
58 ([40],
59 [],
60 [[[0, 0, 1, ['The last row might stick into the margin']]],
61 [[0, 0, 2, ['second row.']]]])],
62 ["""\
63 ========== ===========
64 A table with four rows,
65 -----------------------
66 and two columns.
67 First and last rows
68 contain column spans.
69 =======================
70 """,
71 ([10, 11],
72 [],
73 [[[0, 1, 1, ['A table with four rows,']]],
74 [[0, 0, 3, ['and two']],
75 [0, 0, 3, ['columns.']]],
76 [[0, 0, 4, ['First and']],
77 [0, 0, 4, ['last rows']]],
78 [[0, 1, 5, ['contain column spans.']]]])],
79 ["""\
80 ======= ===== ======
81 A bad table cell 2
82 cell 3 cell 4
83 ============ ======
84 """,
85 'TableMarkupError: Text in column margin at line offset 1.'],
86 ["""\
87 ====== ===== ======
88 row one
89 Another bad table
90 ====== ===== ======
91 """,
92 'TableMarkupError: Text in column margin at line offset 2.'],
93 ["""\
94 =========== ================
95 A table with two header rows,
96 -----------------------------
97 the first with a span.
98 =========== ================
99 Two body rows,
100 the second with a span.
101 =============================
102 """,
103 ([11, 16],
104 [[[0, 1, 1, ['A table with two header rows,']]],
105 [[0, 0, 3, ['the first']],
106 [0, 0, 3, ['with a span.']]]],
107 [[[0, 0, 5, ['Two body']],
108 [0, 0, 5, ['rows,']]],
109 [[0, 1, 6, ['the second with a span.']]]])],
110 ["""\
111 ============ =============
112 A table with two head/body
113 ============ =============
114 row separators.
115 ============ =============
116 That's bad.
117 ============ =============
118 """,
119 'TableMarkupError: Multiple head/body row separators in table '
120 '(at line offset 2 and 4); only one allowed.'],
121 ["""\
122 ============ ============
123 ============ ============
124 """,
125 ([12, 12],
127 [[[0, 0, 1, []],
128 [0, 0, 1, []]]])],
129 # ["""\
130 # ============== ==========
131 # Table with row separators
132 # ============== ==========
133 # and blank
134 # -------------- ----------
135 # entries
136 # -------------- ----------
137 # in first
138 # -------------- ----------
139 # columns.
140 # ============== ==========
141 # """,
142 # '']
146 if __name__ == '__main__':
147 import unittest
148 unittest.main(defaultTest='suite')