test.test_parsers.test_rst.test_tables.py Maven / Gradle / Ivy
#! /usr/bin/env python
# $Id: test_tables.py 7313 2012-01-11 20:28:57Z milde $
# Author: David Goodger
# Copyright: This module has been placed in the public domain.
"""
Tests for states.py.
"""
import os
from __init__ import DocutilsTestSupport
def suite():
s = DocutilsTestSupport.ParserTestSuite()
s.generateTests(totest)
return s
mydir = 'test_parsers/test_rst/'
include2 = os.path.join(mydir, 'test_directives/include2.txt')
totest = {}
totest['grid_tables'] = [
["""\
+-------------------------------------+
| A table with one cell and one line. |
+-------------------------------------+
""",
"""\
A table with one cell and one line.
"""],
["""\
+-----------------------+
| A table with one cell |
| and two lines. |
+-----------------------+
""",
"""\
A table with one cell
and two lines.
"""],
["""\
+-----------------------+
| A malformed table. |
+-----------------------+
""",
"""\
Malformed table.
+-----------------------+
| A malformed table. |
+-----------------------+
"""],
["""\
+------------------------+
| A well-formed | table. |
+------------------------+
+------------------------+
| This +----------+ too! |
+------------------------+
""",
"""\
A well-formed | table.
This +----------+ too!
"""],
["""\
+--------------+--------------+
| A table with | two columns. |
+--------------+--------------+
""",
"""\
A table with
two columns.
"""],
["""\
+--------------+
| A table with |
+--------------+
| two rows. |
+--------------+
""",
"""\
A table with
two rows.
"""],
["""\
+--------------+-------------+
| A table with | two columns |
+--------------+-------------+
| and | two rows. |
+--------------+-------------+
""",
"""\
A table with
two columns
and
two rows.
"""],
["""\
+--------------+---------------+
| A table with | two columns, |
+--------------+---------------+
| two rows, and a column span. |
+------------------------------+
""",
"""\
A table with
two columns,
two rows, and a column span.
"""],
["""\
+--------------------------+
| A table with three rows, |
+------------+-------------+
| and two | columns. |
+------------+-------------+
| First and last rows |
| contains column spans. |
+--------------------------+
""",
"""\
A table with three rows,
and two
columns.
First and last rows
contains column spans.
"""],
["""\
+--------------+--------------+
| A table with | two columns, |
+--------------+ and a row |
| two rows, | span. |
+--------------+--------------+
""",
"""\
A table with
two columns,
and a row
span.
two rows,
"""],
["""\
+------------+-------------+---------------+
| A table | two rows in | and row spans |
| with three +-------------+ to left and |
| columns, | the middle, | right. |
+------------+-------------+---------------+
""",
"""\
A table
with three
columns,
two rows in
and row spans
to left and
right.
the middle,
"""],
["""\
Complex spanning pattern (no edge knows all rows/cols):
+-----------+-------------------------+
| W/NW cell | N/NE cell |
| +-------------+-----------+
| | Middle cell | E/SE cell |
+-----------+-------------+ |
| S/SE cell | |
+-------------------------+-----------+
""",
"""\
Complex spanning pattern (no edge knows all rows/cols):
W/NW cell
N/NE cell
Middle cell
E/SE cell
S/SE cell
"""],
["""\
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
+========================+============+==========+==========+
| body row 1, column 1 | column 2 | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2 | Cells may span columns. |
+------------------------+------------+---------------------+
| body row 3 | Cells may | - Table cells |
+------------------------+ span rows. | - contain |
| body row 4 | | - body elements. |
+------------------------+------------+---------------------+
""",
"""\
Header row, column 1
Header 2
Header 3
Header 4
body row 1, column 1
column 2
column 3
column 4
body row 2
Cells may span columns.
body row 3
Cells may
span rows.
Table cells
contain
body elements.
body row 4
"""],
["""\
+-----------------+--------+
| A simple table | cell 2 |
+-----------------+--------+
| cell 3 | cell 4 |
+-----------------+--------+
No blank line after table.
""",
"""\
A simple table
cell 2
cell 3
cell 4
Blank line required after table.
No blank line after table.
"""],
["""\
+-----------------+--------+
| A simple table | cell 2 |
+-----------------+--------+
| cell 3 | cell 4 |
+-----------------+--------+
Unexpected indent and no blank line after table.
""",
"""\
A simple table
cell 2
cell 3
cell 4
Unexpected indentation.
Blank line required after table.
Unexpected indent and no blank line after table.
"""],
["""\
+--------------+-------------+
| A bad table. | |
+--------------+ |
| Cells must be rectangles. |
+----------------------------+
""",
"""\
Malformed table.
Malformed table; parse incomplete.
+--------------+-------------+
| A bad table. | |
+--------------+ |
| Cells must be rectangles. |
+----------------------------+
"""],
["""\
+------------------------------+
| This table contains another. |
| |
| +-------------------------+ |
| | A table within a table. | |
| +-------------------------+ |
+------------------------------+
""",
"""\