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@0 | 35 | """ |
paul@0 | 36 | |
paul@0 | 37 | attrs, rows = parse(table) |
paul@0 | 38 | |
paul@0 | 39 | print table |
paul@0 | 40 | print attrs |
paul@0 | 41 | print rows |
paul@18 | 42 | print len(rows) == 8, ": length is", len(rows), "==", 8 |
paul@0 | 43 | print |
paul@18 | 44 | for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2]): |
paul@0 | 45 | print row_attrs |
paul@0 | 46 | print columns |
paul@18 | 47 | non_continuation_columns = [ |
paul@18 | 48 | (column_attrs, content) |
paul@18 | 49 | for (column_attrs, content) in columns |
paul@18 | 50 | if not column_attrs.has_key("colcontinuation") |
paul@18 | 51 | and not column_attrs.has_key("rowcontinuation") |
paul@18 | 52 | and not content is None |
paul@18 | 53 | ] |
paul@18 | 54 | print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected |
paul@0 | 55 | print |
paul@0 | 56 | |
paul@0 | 57 | # vim: tabstop=4 expandtab shiftwidth=4 |