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@1 | 24 | \\{\\{\\{ |
paul@1 | 25 | Some preformatted text. |
paul@1 | 26 | \\}\\}\\} |
paul@1 | 27 | ||<colspan="2"> Preformatted text in a separate section |
paul@18 | 28 | == |
paul@18 | 29 | == Heading 2 == |
paul@18 | 30 | This is in the first column. |
paul@18 | 31 | || And this is in the second. |
paul@18 | 32 | == This, despite the == is in a new row. |
paul@18 | 33 | || |
paul@18 | 34 | And this is the second column. |
paul@19 | 35 | == |
paul@19 | 36 | Some \\{\\{\\{preformatted text\\}\\}\\} || Some `preformatted text` || Observe the region notation inline. |
paul@22 | 37 | == |
paul@22 | 38 | <rowspan=2> 1 || 2 || 3 |
paul@22 | 39 | == |
paul@22 | 40 | <rowstyle="background-color: #f33"> 2 || 3 |
paul@0 | 41 | """ |
paul@0 | 42 | |
paul@0 | 43 | attrs, rows = parse(table) |
paul@22 | 44 | expected = 11 |
paul@0 | 45 | |
paul@0 | 46 | print table |
paul@0 | 47 | print attrs |
paul@0 | 48 | print rows |
paul@19 | 49 | print len(rows) == expected, ": length is", len(rows), "==", expected |
paul@0 | 50 | print |
paul@22 | 51 | for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2]): |
paul@0 | 52 | print row_attrs |
paul@0 | 53 | print columns |
paul@18 | 54 | non_continuation_columns = [ |
paul@18 | 55 | (column_attrs, content) |
paul@18 | 56 | for (column_attrs, content) in columns |
paul@18 | 57 | if not column_attrs.has_key("colcontinuation") |
paul@18 | 58 | and not column_attrs.has_key("rowcontinuation") |
paul@18 | 59 | and not content is None |
paul@18 | 60 | ] |
paul@18 | 61 | print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected |
paul@0 | 62 | print |
paul@0 | 63 | |
paul@0 | 64 | # vim: tabstop=4 expandtab shiftwidth=4 |