1.1 --- a/tests/test_parser.py Wed May 03 00:32:46 2017 +0200
1.2 +++ b/tests/test_parser.py Wed May 03 16:27:07 2017 +0200
1.3 @@ -2,144 +2,38 @@
1.4
1.5 from moinformat import parse
1.6 from moinformat.serialisers import serialise, HTMLSerialiser
1.7 -
1.8 -sl = []
1.9 -
1.10 -sl.append("""\
1.11 -Hello
1.12 -{{{{#!wiki
1.13 -A region
1.14 - {{{
1.15 -Another
1.16 -}}}
1.17 -End
1.18 -}}}}
1.19 -XXX
1.20 -""")
1.21 -
1.22 -sl.append("""\
1.23 -XXX
1.24 - * Item 1
1.25 - * Item 1.1
1.26 - * Item 2
1.27 - . Item 3
1.28 - . Item 3.1
1.29 -XXX
1.30 -""")
1.31 -
1.32 -sl.append("""\
1.33 -XXX
1.34 - a. Appendix
1.35 -
1.36 - i. Romanus eunt domus!
1.37 - I. What did they do for us?
1.38 -""")
1.39 +from glob import glob
1.40 +from os.path import join, split
1.41 +import sys
1.42
1.43 -sl.append("""\
1.44 - term:: item
1.45 -not a term:: nor an item
1.46 - term::
1.47 - :: item
1.48 - ::non-item
1.49 -""")
1.50 +dirname = split(sys.argv[0])[0]
1.51
1.52 -sl.append("""\
1.53 -Hello
1.54 -{{{{#!xxx
1.55 -A region
1.56 -{{{
1.57 -Another
1.58 -}}}
1.59 -End
1.60 -}}}}
1.61 -XXX
1.62 -""")
1.63 -
1.64 -sl.append("""\
1.65 -Hello
1.66 -{{{{
1.67 -Start
1.68 -}}}
1.69 -Still in region
1.70 -}}}}
1.71 -End
1.72 -""")
1.73 -
1.74 -sl.append("""\
1.75 -Hello {{{world}}} again""")
1.76 -
1.77 -sl.append("""\
1.78 -XXX
1.79 +def test_input(s):
1.80 + d = parse(s)
1.81 + o = serialise(d)
1.82
1.83 -YYY""")
1.84 -
1.85 -sl.append("""\
1.86 -XXX
1.87 -----
1.88 -YYY
1.89 - ----still a rule
1.90 -also still a rule----
1.91 -EOF""")
1.92 -
1.93 -sl.append("""\
1.94 -= Level 1 =
1.95 -Text
1.96 - == Level 2 Heading ==
1.97 -Text
1.98 -Not == a heading ==
1.99 -== Not a heading == either
1.100 -= Mismatched heading ==
1.101 -== Another mismatched heading =
1.102 -=== Heading __Underlined__ ===
1.103 -""")
1.104 -
1.105 -sl.append("""\
1.106 -''Some'' emphasised text. ''Emphasised''''text''.
1.107 -
1.108 -'''Strong ''and italic'' text.'''
1.109 -
1.110 -''Italic and '''strong'''''. '''''Both'', strong'''. '''''Both''', italic''.
1.111 -
1.112 -'''Strong''''''text'''.
1.113 -
1.114 -Some `monospace` text. `Mono, '''strong'''`, __underlined__, __''under''lined__.
1.115 -
1.116 -H,,2,,O + CO,,2,,
1.117 + print o == s
1.118 + print "-" * 60
1.119 + print o
1.120 + if o != s:
1.121 + print "-" * 60
1.122 + print s
1.123 + print "-" * 60
1.124 + print serialise(d, HTMLSerialiser)
1.125 + print "-" * 60
1.126 + print d.prettyprint()
1.127 + print
1.128
1.129 -== e = mc^2^ ==
1.130 -
1.131 -~+Larger...+~ and ~-smaller-~
1.132 -""")
1.133 -
1.134 -sl.append("""\
1.135 -||<20%|2-2)^> Cell 1 || Cell 2 ||
1.136 -|| Cell 3 ||<#FF0000 width="15%"> Cell 4 ||
1.137 -
1.138 -|| Not a table
1.139 - || Also not a table
1.140 -|| Almost a table || ...
1.141 -|| A table, trailing space ||
1.142 -""")
1.143 -
1.144 -dl = map(parse, sl)
1.145 -nl = map(serialise, dl)
1.146 +if __name__ == "__main__":
1.147 + filenames = sys.argv[1:] or glob(join(dirname, "test*.txt"))
1.148 + filenames.sort()
1.149
1.150 -for s, n in zip(sl, nl):
1.151 - print n == s
1.152 - print "----"
1.153 - print n
1.154 - print "----"
1.155 -
1.156 -for d in dl:
1.157 - print
1.158 - print "----"
1.159 - print serialise(d, HTMLSerialiser)
1.160 - print "----"
1.161 -
1.162 -for d in dl:
1.163 - print
1.164 - print "----"
1.165 - print d.prettyprint()
1.166 - print "----"
1.167 + for filename in filenames:
1.168 + f = open(filename)
1.169 + try:
1.170 + print filename
1.171 + test_input(f.read())
1.172 + finally:
1.173 + f.close()
1.174
1.175 # vim: tabstop=4 expandtab shiftwidth=4