paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | from ImprovedTableParser import parse |
paul@0 | 4 | |
paul@0 | 5 | table = """<tablestyle="border: 2px solid red; border-collapse: collapse;" rowstyle="background-color: #f77;"> |
paul@0 | 6 | Test||Outcome||Comments |
paul@0 | 7 | == |
paul@0 | 8 | Colspan |
paul@0 | 9 | ||<colspan="2"> Test a column with attributes |
paul@0 | 10 | == |
paul@0 | 11 | Normal || <style=" |
paul@0 | 12 | text-align: center" colspan=1> Three columns || Adjacent column |
paul@0 | 13 | == |
paul@0 | 14 | Split |
paul@0 | 15 | || Three columns |
paul@0 | 16 | || Separate lines |
paul@0 | 17 | == |
paul@0 | 18 | * Item #1 |
paul@0 | 19 | * Item #2 |
paul@0 | 20 | || |
paul@0 | 21 | * Item #A |
paul@0 | 22 | || Not a list |
paul@1 | 23 | == |
paul@23 | 24 | {{{ |
paul@1 | 25 | Some preformatted text. |
paul@23 | 26 | == |
paul@23 | 27 | Not another row. |
paul@23 | 28 | }}} |
paul@1 | 29 | ||<colspan="2"> Preformatted text in a separate section |
paul@18 | 30 | == |
paul@18 | 31 | == Heading 2 == |
paul@18 | 32 | This is in the first column. |
paul@18 | 33 | || And this is in the second. |
paul@18 | 34 | == This, despite the == is in a new row. |
paul@18 | 35 | || |
paul@18 | 36 | And this is the second column. |
paul@19 | 37 | == |
paul@23 | 38 | Some {{{{preformatted text}}}} || Some `preformatted text` || Observe the region notation inline. |
paul@22 | 39 | == |
paul@22 | 40 | <rowspan=2> 1 || 2 || 3 |
paul@22 | 41 | == |
paul@22 | 42 | <rowstyle="background-color: #f33"> 2 || 3 |
paul@32 | 43 | == |
paul@32 | 44 | The first column || The second |
paul@32 | 45 | .. with the continuation of |
paul@32 | 46 | .. the text without indentation occurring. |
paul@0 | 47 | """ |
paul@0 | 48 | |
paul@0 | 49 | attrs, rows = parse(table) |
paul@32 | 50 | expected = 12 |
paul@0 | 51 | |
paul@0 | 52 | print table |
paul@0 | 53 | print attrs |
paul@0 | 54 | print rows |
paul@19 | 55 | print len(rows) == expected, ": length is", len(rows), "==", expected |
paul@0 | 56 | print |
paul@32 | 57 | for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2, 2]): |
paul@0 | 58 | print row_attrs |
paul@0 | 59 | print columns |
paul@18 | 60 | non_continuation_columns = [ |
paul@18 | 61 | (column_attrs, content) |
paul@18 | 62 | for (column_attrs, content) in columns |
paul@18 | 63 | if not column_attrs.has_key("colcontinuation") |
paul@18 | 64 | and not column_attrs.has_key("rowcontinuation") |
paul@18 | 65 | and not content is None |
paul@18 | 66 | ] |
paul@18 | 67 | print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected |
paul@0 | 68 | print |
paul@0 | 69 | |
paul@32 | 70 | expected_text = "The second\nwith the continuation of\nthe text without indentation occurring.\n" |
paul@32 | 71 | text = rows[11][1][1][1] |
paul@32 | 72 | print text == expected_text, ": text is", repr(text) |
paul@32 | 73 | |
paul@0 | 74 | # vim: tabstop=4 expandtab shiftwidth=4 |