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@33 | 47 | == |
paul@33 | 48 | A test || Of... |
paul@33 | 49 | ...non-continuation |
paul@0 | 50 | """ |
paul@0 | 51 | |
paul@0 | 52 | attrs, rows = parse(table) |
paul@33 | 53 | expected = 13 |
paul@0 | 54 | |
paul@0 | 55 | print table |
paul@0 | 56 | print attrs |
paul@0 | 57 | print rows |
paul@19 | 58 | print len(rows) == expected, ": length is", len(rows), "==", expected |
paul@0 | 59 | print |
paul@33 | 60 | for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2, 2, 2]): |
paul@0 | 61 | print row_attrs |
paul@0 | 62 | print columns |
paul@18 | 63 | non_continuation_columns = [ |
paul@18 | 64 | (column_attrs, content) |
paul@18 | 65 | for (column_attrs, content) in columns |
paul@18 | 66 | if not column_attrs.has_key("colcontinuation") |
paul@18 | 67 | and not column_attrs.has_key("rowcontinuation") |
paul@18 | 68 | and not content is None |
paul@18 | 69 | ] |
paul@18 | 70 | print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected |
paul@0 | 71 | print |
paul@0 | 72 | |
paul@32 | 73 | expected_text = "The second\nwith the continuation of\nthe text without indentation occurring.\n" |
paul@32 | 74 | text = rows[11][1][1][1] |
paul@32 | 75 | print text == expected_text, ": text is", repr(text) |
paul@32 | 76 | |
paul@33 | 77 | expected_text = "Of...\n ...non-continuation\n" |
paul@33 | 78 | text = rows[12][1][1][1] |
paul@33 | 79 | print text == expected_text, ": text is", repr(text) |
paul@33 | 80 | |
paul@0 | 81 | # vim: tabstop=4 expandtab shiftwidth=4 |