2014-07-02 13:40:29 -07:00
#!/usr/bin/python2.7
import recentrunes
2014-08-03 11:25:29 -07:00
mediawiki = recentrunes . Parser . fromFile ( ' static/grammars/mediawiki.js ' )
2014-07-02 13:40:29 -07:00
teststring = \
""" This is a paragraph with many text styles. This is ' ' italic ' ' and this
is ''' bold ''' ; this is ''' ' ' both ''' ' ' . This is < u > underline < / u > as is
< ins > this < / ins > . This is < u > ''' ' ' underlined, bold and italic ''' ' ' < / u > .
This is < del > strikethrough < / del > , as is < strike > this < / strike > . Source
code looks like < code > this < / code > . Fixed width text looks like
< tt > this < / tt > . < pre > This sentence is inline pre - formatted , which stops
''' ' ' this from being bold and italic. ''' ' ' < / pre > < nowiki > We can also
stop < u > this from being underlined < / u > < / nowiki > , or just try
<< nowiki / > pre > interrupting cow style . < / pre > < ! - - This is a comment and
shouldn ' t be visible --><blockquote>This is a blockquote</blockquote>
== Header 2 ==
== = Header 3 ' ' with italics ' ' == =
== == Header 4 == ==
== == = Header 5 == == =
== == == Header 6 == == ==
- - - -
* Item 1 a
* Item 1 b
* * Item 2
* * * Item 3
* Item 1 c
# Item 1a
# Item 1b
## Item 2
### Item 3
# Item 1c
; I don ' t really understand what a definition is
: But blockquotes are easy
: : Even larger ones
: : : : : And really huge ones
This line is pre - formatted and < del > not interpolated < / del >
This line is also pre - formatted """
2014-08-03 11:25:29 -07:00
result = str ( mediawiki . parseFromString ( teststring ) )
2014-07-02 13:40:29 -07:00
assert result == \
""" <wikidoc><p>This is a paragraph with many text styles. This is <i>italic</i> and this
is < b > bold < / b > ; this is < b > < i > both < / i > < / b > . This is < u > underline < / u > as is
< u > this < / u > . This is < u > < b > < i > underlined , bold and italic < / i > < / b > < / u > .
This is < del > strikethrough < / del > , as is < del > this < / del > . Source
code looks like < code > this < / code > . Fixed width text looks like
< tt > this < / tt > . < pre > This sentence is inline pre - formatted , which stops
''' ' ' this from being bold and italic. ''' ' ' < / pre > We can also
2014-07-02 13:42:17 -07:00
stop & lt ; u & gt ; this from being underlined & lt ; / u & gt ; , or just try
2014-07-03 01:20:40 -04:00
& lt ; pre & gt ; interrupting cow style . & lt ; / pre & gt ; < blockquote > This is a blockquote < / blockquote > < / p > < p > < h2 > Header 2 < / h2 > < h3 > Header 3 < i > with italics < / i > < / h3 > < h4 > Header 4 < / h4 > < h5 > Header 5 < / h5 > < h6 > Header 6 < / h6 > < hr > < / hr > < ul > < li > Item 1 a < / li > < li > Item 1 b < / li > < ul > < li > Item 2 < / li > < ul > < li > Item 3 < / li > < / ul > < / ul > < li > Item 1 c < / li > < / ul > < ol > < li > Item 1 a < / li > < li > Item 1 b < / li > < ol > < li > Item 2 < / li > < ol > < li > Item 3 < / li > < / ol > < / ol > < li > Item 1 c < / li > < / ol > < def > I don ' t really understand what a definition is</def><blockquote>But blockquotes are easy<blockquote>Even larger ones<blockquote><blockquote><blockquote>And really huge ones</blockquote></blockquote></blockquote></blockquote></blockquote><pre>This line is pre-formatted and <del>not interpolated</del>
2014-07-02 14:01:19 -07:00
This line is also pre - formatted
2014-07-03 01:11:39 -04:00
< / pre > < / p > < / wikidoc > """ , result
2014-08-03 10:59:39 -07:00
2014-08-03 11:25:29 -07:00
badpenny = recentrunes . Parser . fromFile ( ' static/grammars/badpenny.js ' )
teststring = \
""" foo {{ value1}}bar
foo { { ( container1 } } contents { { ) nottheend } } more contents { { ) container1 } } bar
foo { { [ repeated1 } } testing { { ] notthis } } { { ) repeated1 } } zig { { ] repeated1 } } bar """
result = str ( badpenny . parseFromString ( teststring ) )
assert result == \
""" <badpenny>foo<value name= " value1 " ></value>bar
foo < container name = " container1 " > contents { { ) nottheend } } more contents < / container > bar
foo < repeated name = " repeated1 " > testing { { ] notthis } } { { ) repeated1 } } zig < / repeated > bar < / badpenny > """