MoinLight

Annotated tests/test_parser.py

23:3630b0946d2f
2017-05-01 Paul Boddie Added larger and smaller text formatting. Simplified inline pattern handling and document nodes somewhat.
paul@0 1
#!/usr/bin/env python
paul@0 2
paul@11 3
from moinformat import parse
paul@11 4
from moinformat.serialisers import serialise, HTMLSerialiser
paul@0 5
paul@12 6
sl = []
paul@12 7
paul@12 8
sl.append("""\
paul@1 9
Hello
paul@1 10
{{{{#!wiki
paul@1 11
A region
paul@10 12
  {{{
paul@1 13
Another
paul@1 14
}}}
paul@1 15
End
paul@1 16
}}}}
paul@1 17
XXX
paul@14 18
""")
paul@9 19
paul@14 20
sl.append("""\
paul@14 21
XXX
paul@9 22
 * Item 1
paul@14 23
   * Item 1.1
paul@9 24
 * Item 2
paul@14 25
 . Item 3
paul@14 26
   . Item 3.1
paul@9 27
XXX
paul@16 28
""")
paul@16 29
paul@16 30
sl.append("""\
paul@16 31
XXX
paul@14 32
 a. Appendix
paul@14 33
paul@14 34
 i. Romanus eunt domus!
paul@14 35
 I. What did they do for us?
paul@12 36
""")
paul@1 37
paul@12 38
sl.append("""\
paul@16 39
 term:: item
paul@16 40
not a term:: nor an item
paul@16 41
 term::
paul@16 42
 :: item
paul@16 43
 ::non-item
paul@16 44
""")
paul@16 45
paul@16 46
sl.append("""\
paul@0 47
Hello
paul@0 48
{{{{#!xxx
paul@0 49
A region
paul@0 50
{{{
paul@0 51
Another
paul@0 52
}}}
paul@0 53
End
paul@0 54
}}}}
paul@0 55
XXX
paul@12 56
""")
paul@0 57
paul@12 58
sl.append("""\
paul@0 59
Hello
paul@0 60
{{{{
paul@0 61
Start
paul@0 62
}}}
paul@0 63
Still in region
paul@0 64
}}}}
paul@0 65
End
paul@12 66
""")
paul@12 67
paul@12 68
sl.append("""\
paul@12 69
Hello {{{world}}} again""")
paul@0 70
paul@12 71
sl.append("""\
paul@12 72
XXX
paul@12 73
paul@12 74
YYY""")
paul@0 75
paul@12 76
sl.append("""\
paul@12 77
XXX
paul@12 78
----
paul@12 79
YYY
paul@12 80
 ----still a rule
paul@12 81
also still a rule----
paul@12 82
EOF""")
paul@0 83
paul@13 84
sl.append("""\
paul@13 85
= Level 1 =
paul@13 86
Text
paul@13 87
  == Level 2 Heading ==  
paul@13 88
Text
paul@13 89
Not == a heading ==
paul@13 90
== Not a heading == either
paul@13 91
= Mismatched heading ==
paul@13 92
== Another mismatched heading =
paul@19 93
=== Heading __Underlined__ ===
paul@13 94
""")
paul@13 95
paul@17 96
sl.append("""\
paul@18 97
''Some'' emphasised text. ''Emphasised''''text''.
paul@17 98
paul@17 99
'''Strong ''and italic'' text.'''
paul@17 100
paul@18 101
''Italic and '''strong'''''. '''''Both'', strong'''. '''''Both''', italic''.
paul@18 102
paul@18 103
'''Strong''''''text'''.
paul@18 104
paul@19 105
Some `monospace` text. `Mono, '''strong'''`, __underlined__, __''under''lined__.
paul@20 106
paul@20 107
H,,2,,O + CO,,2,,
paul@20 108
paul@20 109
== e = mc^2^ ==
paul@23 110
paul@23 111
~+Larger...+~ and ~-smaller-~
paul@17 112
""")
paul@17 113
paul@12 114
dl = map(parse, sl)
paul@12 115
nl = map(serialise, dl)
paul@0 116
paul@12 117
for s, n in zip(sl, nl):
paul@1 118
    print n == s
paul@2 119
    print "----"
paul@1 120
    print n
paul@1 121
    print "----"
paul@0 122
paul@12 123
for d in dl:
paul@2 124
    print
paul@2 125
    print "----"
paul@1 126
    print serialise(d, HTMLSerialiser)
paul@1 127
    print "----"
paul@0 128
paul@12 129
for d in dl:
paul@3 130
    print
paul@3 131
    print "----"
paul@3 132
    print d.prettyprint()
paul@3 133
    print "----"
paul@3 134
paul@0 135
# vim: tabstop=4 expandtab shiftwidth=4