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@0 | 43 | """ |
paul@0 | 44 | |
paul@0 | 45 | attrs, rows = parse(table) |
paul@22 | 46 | expected = 11 |
paul@0 | 47 | |
paul@0 | 48 | print table |
paul@0 | 49 | print attrs |
paul@0 | 50 | print rows |
paul@19 | 51 | print len(rows) == expected, ": length is", len(rows), "==", expected |
paul@0 | 52 | print |
paul@22 | 53 | for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2]): |
paul@0 | 54 | print row_attrs |
paul@0 | 55 | print columns |
paul@18 | 56 | non_continuation_columns = [ |
paul@18 | 57 | (column_attrs, content) |
paul@18 | 58 | for (column_attrs, content) in columns |
paul@18 | 59 | if not column_attrs.has_key("colcontinuation") |
paul@18 | 60 | and not column_attrs.has_key("rowcontinuation") |
paul@18 | 61 | and not content is None |
paul@18 | 62 | ] |
paul@18 | 63 | print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected |
paul@0 | 64 | print |
paul@0 | 65 | |
paul@0 | 66 | # vim: tabstop=4 expandtab shiftwidth=4 |