MoinLight

Annotated tests/test_parser.py

18:ca3330f1c234
2017-05-01 Paul Boddie Merged handling of emphasised and strong text. Added monospaced text support.
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@13 93
""")
paul@13 94
paul@17 95
sl.append("""\
paul@18 96
''Some'' emphasised text. ''Emphasised''''text''.
paul@17 97
paul@17 98
'''Strong ''and italic'' text.'''
paul@17 99
paul@18 100
''Italic and '''strong'''''. '''''Both'', strong'''. '''''Both''', italic''.
paul@18 101
paul@18 102
'''Strong''''''text'''.
paul@18 103
paul@18 104
Some `monospace` text. '''`Mono`, strong'''.
paul@17 105
""")
paul@17 106
paul@12 107
dl = map(parse, sl)
paul@12 108
nl = map(serialise, dl)
paul@0 109
paul@12 110
for s, n in zip(sl, nl):
paul@1 111
    print n == s
paul@2 112
    print "----"
paul@1 113
    print n
paul@1 114
    print "----"
paul@0 115
paul@12 116
for d in dl:
paul@2 117
    print
paul@2 118
    print "----"
paul@1 119
    print serialise(d, HTMLSerialiser)
paul@1 120
    print "----"
paul@0 121
paul@12 122
for d in dl:
paul@3 123
    print
paul@3 124
    print "----"
paul@3 125
    print d.prettyprint()
paul@3 126
    print "----"
paul@3 127
paul@0 128
# vim: tabstop=4 expandtab shiftwidth=4