#!/usr/bin/env python import unittest import sys if __name__ == "__main__": # Hack because we can't use from . import w/e if we're __main__ import os.path sys.path = ([os.path.dirname(os.path.dirname(os.path.realpath(__file__)))] + sys.path) from redbeans.parser import Parser from redbeans.formats import Format from redbeans.html import HTMLFormat from redbeans.latex import LaTeXFormat from redbeans.tokens import * if '-v' in sys.argv: import redbeans.creole redbeans.creole.debug = True class TestCreole(unittest.TestCase): def error_func(self): self.error = True def assertMakes(self, mf, str, format, correct, expect_error=False): if '-v' in sys.argv: print >>sys.stderr,"...................... New Test.................." self.error = False parser = Parser(format, mf, error_func=self.error_func) ev = '' for s in parser.iparse(str): if '-v' in sys.argv: print >>sys.stderr, repr(s) ev += s self.assertEqual(correct, ev) self.assertEqual(expect_error, self.error) def testBasics(self): self.assertMakes(None,'foo',Format,'foo') self.assertMakes(None, "foo **bar** baz was a parrot.", Format, "foo *bar* baz was a parrot.") self.assertMakes(None, "foo '[[GoogleFish|Google Fish]]' baz was a parrot.",HTMLFormat,u"""

foo \u2018Google Fish\u2019 baz was a parrot.

""") self.assertMakes(None, "foo '[[GoogleFish]]' baz was a parrot.", Format, u"foo \u2018GoogleFish@\u2019 baz was a parrot.") self.assertMakes(None,'{{wombat.png}}',Format,'[wombat.png]') self.assertMakes(None,'{{wombat.png|A wombat}}',Format,'[A wombat]') self.assertMakes(None,'[[Foo]] [[Bar]] [[Baz]]',HTMLFormat,'''

Foo Bar Baz

''') def testBasicLists(self): self.assertMakes(None,"""Fwee! * Foo ** Bar * Baz""",Format,"""Fwee! * Foo * Bar * Baz""") self.assertMakes(None,'\n* Test',Format,' * Test') self.assertMakes(None,'\n* Test',HTMLFormat,'') self.assertMakes(None,'\n* Test\n# Rest',HTMLFormat,'''
  1. Rest
''') self.assertMakes(None,''' * [[StatCard]] * [[StatCard]] * [[StatCard]] ''',HTMLFormat,u'''''') self.assertMakes(None, '**Bold**', HTMLFormat, '

Bold

') self.assertMakes(None, '##Typewriter##', HTMLFormat, '

Typewriter

') def testListIntegration(self): self.assertMakes(None,''' * [[StatCard]] == Not A StatCard == * [[StatCard]] ''',HTMLFormat,u'''

Not A StatCard

''') def mf(name, arglist=None,content=None): if name == 'cheese': yield Text(u'cheese\n') elif name == 'lis': yield Start(UNORDERED_ITEM, 1) yield Text(u'Foo') yield End(UNORDERED_ITEM, 1) yield Start(UNORDERED_ITEM, 1) yield Text(u'Bar') yield End(UNORDERED_ITEM, 1) self.assertMakes(mf,''' * Fleas * <> * Trees ''',HTMLFormat,u'''''') self.assertMakes(mf, '''|=Title|<>|''', HTMLFormat, '''
Title
  • Foo
  • Bar
''') def testBasicMacros(self): # Macros def mf(name, arglist, content=None): if name == 'fish': if content: for t in content: assert False, t yield Text(u"Carp") self.assertMakes(mf,'<>',Format,'Carp') self.assertMakes(mf,r'\fish{}',Format,'Carp') self.assertMakes(mf,r'\fish',Format,'Carp') self.assertMakes(mf,r'\fish cake\fish',Format,'Carp cakeCarp') self.assertMakes(mf,'\\fish\ncake\\fish',Format,'Carp cakeCarp') self.assertMakes(mf, '[[foo|<>]]', Format, 'Carp@') def mf(name, arglist=None, content=None): if name == 'fish': yield Start(HEADING, 2) yield Text(u"Test") yield End(HEADING, 2) self.assertMakes(mf,'Foo\n<>',HTMLFormat,'

Foo\n

\n\n

Test

') self.assertMakes(mf,'Foo\n <>',HTMLFormat,'

Foo\n

\n\n

Test

') def mf(name, arglist=None, content=None): if name == 'twice': lst = list(content) #print >>sys.stderr, 'twice:', lst for x in xrange(2): for t in lst: yield t self.assertMakes(mf,'''<> * This<>''',Format,''' * This * This''') self.assertMakes(mf,'''<>* This<>''',Format,'''* This* This''') def mf(name, arglist=None, content=None): if name == 'par': yield Entity(ENV_BREAK) elif name == 'fish': yield Start(UNORDERED_ITEM, 1) yield Text(u"Carp") yield End(UNORDERED_ITEM, 1) yield Entity(ENV_BREAK) yield Start(UNORDERED_ITEM, 1) yield Text(u"Trout") yield End(UNORDERED_ITEM, 1) self.assertMakes(mf,'''Bob<>George''',HTMLFormat,'''

Bob

George

''') self.assertMakes(mf,'''Bob<>George''',HTMLFormat,'''

Bob

  • Carp
  • Trout

George

''') self.assertMakes(mf,'''|= Title |= Fish | | Ralph | Which<>Carp |''',HTMLFormat,'''
TitleFish
RalphWhich

\n\nCarp
''') self.assertMakes(mf,'''**Bob<>George**''',HTMLFormat,'''

Bob

George

''') def mf(name, arglist=None, content=None): if name == 'bar': yield Text(u"Foo") elif name == 'fish': yield Entity(MACRO, ('bar', None)) self.assertMakes(mf,'''<>''',Format,'''Foo''') self.assertMakes(mf,'''<>''',Format,'''Foo''') self.assertMakes(mf, '''<><>''', Format, '''Foo''') def testBrokenMacros(self): # Macros def mf(name, arglist, content=None): if name == 'fish': yield Text(u"Carp") else: yield Text(u'???' + name) self.assertMakes(mf,'<', Format, 'Carp') self.assertMakes(mf,'<\nCheese', Format, 'Carp Cheese') self.assertMakes(mf,'<Cheese<>', Format, u"???fish>Cheese<Cheese<> * <><><> <> * <><><> <>''', Format, ' * Name') def testContentMacros(self): def mf(name, arglist=None, content=None): if name == 'par': yield Entity(ENV_BREAK) elif name == 'bold': yield Start(BOLD) for t in content: yield t yield End(BOLD) elif name == 'great': yield Start(BOLD) for t in content: yield t yield End(BOLD) elif name == 'token': yield Text(u':') elif name == 'let': for t in content: yield t self.assertMakes(mf,'''<>Bob George<>''',HTMLFormat,'''

Bob George

''') self.assertMakes(mf,r'''\bold{Bob George}''',HTMLFormat,'''

Bob George

''') self.assertMakes(mf,r'''\bold{Bob George''',HTMLFormat,'''

Bob GeorgeUnclosed macro 'bold'!

''', expect_error=True) self.assertMakes(mf, '''<>Nesting is <>great<>!<>''', HTMLFormat, '''

Nesting is great!

''') self.assertMakes(mf, '''<>Nesting is <>great<>!<>''', HTMLFormat, '''

Nesting is great!

''') self.assertMakes(mf, '''<> <> == Name == <> * A * <>[[B]]<> <> <> <>''', HTMLFormat, '''

Name

  • A
  • B
''') self.assertMakes(mf, '''<> == Name == * C * [[Badge]] <> <> == [[Next]] == <> <> * A * <>[[B]]<> <> <> <>''', HTMLFormat, '''

Name

''') self.assertMakes(mf, '''<> <> is equivalent to : <>''', Format, ": is equivalent to :") self.assertMakes(mf, '''<> <> is equivalent to : <>''', Format, ": is equivalent to :") self.assertMakes(mf, '''<> <> To flip over. <> <> To go on this Quest. <> ''', LaTeXFormat, ":\n\n To flip over.\n\n\n\n:\n\n To go on this Quest.") self.assertMakes(mf, '''<> == <> == = <> = === <> === = <> = <>''', HTMLFormat, '''

:

:

:

:

''') def testBoldLists(self): # Bold/list interaction self.assertMakes(None,'** foo **',Format,'* foo *') self.assertMakes(None,'//* Bar//',Format,'/* Bar/') self.assertMakes(None,'http://web.mit.edu/',Format,'http://web.mit.edu/') self.assertMakes(None,'http://web.mit.edu/ Next',LaTeXFormat,r'\href{http://web.mit.edu/}{http://web.mit.edu/} Next') self.assertMakes(None,'## foo ##',Format,' foo ') self.assertMakes(None,'''* bar ## foo ##''',Format,''' * bar # foo ''') self.assertMakes(None,'''* bar ## foo ##''',Format,''' * bar foo ''') self.assertMakes(None, '** foo **', HTMLFormat, '

foo

') self.assertMakes(None, ' ** foo **', HTMLFormat, '

foo

') def testHeadings(self): # Headings self.assertMakes(None,'= Head =',HTMLFormat,'

Head

') self.assertMakes(None,'== Head',Format,'== Head ==') self.assertMakes(None,'=== Head ===',Format,'=== Head ===') self.assertMakes(None,'= Head ===',Format,'= Head =') self.assertMakes(None,'Foo\n== Head',HTMLFormat,'

Foo

\n\n

Head

') self.assertMakes(None,'Foo == Head',HTMLFormat,'

Foo == Head

') self.assertMakes(None,'''Paragraph. = Head === Wine is great.''',Format,'Paragraph.\n\n= Head =\n\nWine is great.') self.assertMakes(None,'''* Listless ** List listers. == Head == Wine is great.''',Format,' * Listless\n * List listers.\n\n== Head ==\n\nWine is great.') self.assertMakes(None,'''* Listless ** List listers. == Head == Wine is great.''',HTMLFormat,'''
  • Listless
    • List listers.

Head

Wine is great.

''') def testTables(self): self.assertMakes(None,'|= Test |= Table |\n|Here|Contents|',Format,'''\t* Test *\t* Table *\n\tHere\tContents''') self.assertMakes(None,'|= Test |= Table |\n|Here|Contents|',HTMLFormat,'''
TestTable
HereContents
''') self.assertMakes(None,'| Test | Table |\n|Here|Contents|\n|Three| LineS |',HTMLFormat,'''
TestTable
HereContents
ThreeLineS
''') def mf(name, arglist=None, content=None): if name == 'mesa': yield Start(TABLE_ROW) yield Start(TABLE_HEADING) yield Text(u' Foo ') yield End(TABLE_HEADING) yield Start(TABLE_HEADING) yield Text(u' Bar') yield End(TABLE_HEADING) yield End(TABLE_ROW) yield Start(TABLE_ROW) yield Start(TABLE_CELL) yield Text(u'Baz') yield End(TABLE_CELL) yield Start(TABLE_CELL) yield Text(u'Quux') yield End(TABLE_CELL) yield End(TABLE_ROW) elif name == 'table': yield Start(TABLE) for t in content: yield t yield End(TABLE) self.assertMakes(mf,'''<>''',HTMLFormat,'''
Foo Bar
BazQuux
''') self.assertMakes(mf,'''<> |Rab|Ongo''',HTMLFormat,'''
Foo Bar
BazQuux
RabOngo
''') self.assertMakes(mf,'''|Rab|Ongo <>''',HTMLFormat,'''
RabOngo
Foo Bar
BazQuux
''') self.assertMakes(mf, '''<> | A | B | C | D <
>''', HTMLFormat, '''
AB
CD
''') def mf(name, arglist=None,content=None): if name == 'cheese': yield Text(u'cheese\n') elif name == 'mesa': yield Start(TABLE_ROW) yield Start(TABLE_CELL) yield Text(u'Foo ') yield End(TABLE_CELL) yield Start(TABLE_CELL) yield Entity(MACRO, ['cheese', None]) yield End(TABLE_CELL) yield End(TABLE_ROW) yield Start(TABLE_ROW) yield Start(TABLE_CELL) yield Text(u"Baz ") yield End(TABLE_CELL) yield Start(TABLE_CELL) yield Entity(MACRO, ['cheese', None]) yield End(TABLE_CELL) yield End(TABLE_ROW) self.assertMakes(mf,'''<>''',HTMLFormat,'''
Foo cheese\n
Baz cheese\n
''') self.assertMakes(None,'''This is to test that things like the foll |= Title |= More Title| | Body | Elephant |''',HTMLFormat,'''

This is to test that things like the foll

TitleMore Title
BodyElephant
''') def mf(name, arglist=None,content=None): if name == 'repeat': lst = list(content) for x in xrange(3): for t in lst: yield t self.assertMakes(mf,'''|=Title|=Row <> |Foo|Bar<> |Last|Row''', HTMLFormat,'''
TitleRow
FooBar
FooBar
FooBar
LastRow
''') self.assertMakes(None, ''' |= Faction |= Brainwashed | [[Light]] | [[ThomasMorgan]] 9 regular actors: # [[Max]] ''', HTMLFormat, '''
FactionBrainwashed
LightThomasMorgan

9 regular actors:

  1. Max
''') def testDynamicLists(self): def mf(name, arglist=None, content=None): if name == 'tree': for x in [1,2,2,3,2,3,4,1,2,1,2,3,3,1]: yield Start(UNORDERED_ITEM, x) yield Text(u'content') yield End(UNORDERED_ITEM, x) self.assertMakes(mf,'''Tree: <>''',HTMLFormat,'''

Tree:

  • content
    • content
    • content
      • content
    • content
      • content
        • content
  • content
    • content
  • content
    • content
      • content
      • content
  • content
''') def testBlockquote(self): # Blockquote self.assertMakes(None,''': Line :: More indented : Less''',HTMLFormat,'''
Line
More indented
Less
''') self.assertMakes(None,'''Para > Line >> More indented >> Second > Less''',HTMLFormat,'''

Para

Line
More indented Second
Less
''') def testURLEncoding(self): self.assertMakes(None,'''[[http://sevenmonkey.mit.edu/Japan/Early Netsuke]]''',HTMLFormat, '''

http://sevenmonkey.mit.edu/Japan/Early Netsuke

''') self.assertMakes(None,'''[[http://heraldry.sca.org/sena.html#A1|SENA]]''',HTMLFormat, '''

SENA

''') def testEscapes(self): #Escape tests self.assertMakes(None,'''http://pianojuice.net/~xavid''',HTMLFormat, '''

http://pianojuice.net/~xavid

''') self.assertMakes(None,'''[[http://pianojuice.net/~xavid|My home page]]''',HTMLFormat, '''

My home page

''') self.assertMakes(None,'''~http://pianojuice.net/~xavid''',HTMLFormat, '''

http://pianojuice.net/~xavid

''') self.assertMakes(None,'''~http://pianojuice.net/~~xavid''',HTMLFormat, '''

http://pianojuice.net/~xavid

''') self.assertMakes(None,'''**bold**''',HTMLFormat, '''

bold

''') self.assertMakes(None,'''~**bold**''',HTMLFormat, '''

**bold

''') self.assertMakes(None,'''~**bold~**''',HTMLFormat, '''

**bold**

''') self.assertMakes(None,'''~***bold**''',HTMLFormat, '''

*bold

''') self.assertMakes(None, '''##~###''', HTMLFormat, '''

#

''') self.assertMakes(None, '''~Xavid''', Format, '~Xavid') self.assertMakes(None, '''~the''', Format, '~the') def testFullparse(self): def mf(name, arglist=None, content=None): if name == 'block': for t in content: yield t yield Entity(ENV_BREAK, True) self.assertMakes(mf,''' <> * Fleas * Swiss <> * Trees ''',HTMLFormat,'''
  • Fleas
  • Swiss
  • Trees
''') def testLaTeX(self): self.assertMakes(None, '[[Foo|Bar]]', LaTeXFormat, r'\href{Foo}{Bar}') self.assertMakes(None, '* Foo\n* Bar\n* Baz', LaTeXFormat, '\\begin{itemize}\n\\item Foo\n\\item Bar\n\\item Baz\n\\end{itemize}\n') def mf(name, arglist=None, content=None): if name == 'propname': yield Text(u'CR') self.assertMakes(mf,'''Foo. * **<>**: 4''', LaTeXFormat, r'''Foo. \begin{itemize} \item {\bfseries CR}: 4 \end{itemize} ''') self.assertMakes(mf, "'", LaTeXFormat, u'\u2018') self.assertMakes(mf, "~'", LaTeXFormat, r'\textquotesingle{}') self.assertMakes(mf, '"', LaTeXFormat, u'\u201c') self.assertMakes(mf, '~"', LaTeXFormat, r'\textquotedbl{}') # def testDefinitionLists(self): # self.assertMakes(None,'\n; Test: Desc',Format,'\n * Test: Desc') # self.assertMakes(None,'\n; Test: Desc\n',HTMLFormat,'
\n
Test
Desc
\n
\n\n') # self.assertMakes(None,'\n; Test: Desc\n;Two: Desc', LaTeXFormat, # r'''\begin{descripton} #\item[Test] Desc #\item[Two] Desc #\end{description} #''') def testTeXMarkup(self): def mf(name, arglist=None, content=[]): if name == 'textbf': yield Start(BOLD) for t in content: yield t yield End(BOLD) elif name == 'emph': yield Start(ITALIC) for t in content: yield t yield End(ITALIC) elif name == 'center': yield Start(CENTER) for t in content: yield t yield End(CENTER) elif name == 'cenquote': yield Start(CENTER) closed = False for t in content: if (t.op == ENTITY and t.style == MACRO and t.arg[0] == 'break'): yield End(CENTER) yield Start(RIGHT) closed = True else: yield t if closed: yield End(RIGHT) else: yield End(CENTER) elif name == "'": lc = list(content) assert len(lc) == 1 and lc[0].op == TEXT, lc char = lc[0].arg assert len(char) == 1 if char == 'e': yield Text(u'\u00E9') else: yield Text(char) elif name == "Dude": yield Text(u'Bob') elif name == "start": yield Text(u'1615') elif name == "end": yield Text(u'1618') else: assert False, name self.assertMakes(mf, 'foo', Format, 'foo') self.assertMakes(mf, r"foo \textbf{fish} baz was a parrot.",HTMLFormat,"""

foo fish baz was a parrot.

""") self.assertMakes(mf, r"foo \textbf{\emph{fish}} baz was a parrot.",HTMLFormat,"""

foo fish baz was a parrot.

""") self.assertMakes(mf,'\\center{Row, row, row}',HTMLFormat, '
Row, row, row
') #self.assertMakes(mf,'\\begin{center}\n\nRow, row, row\n\n\\end{center}',HTMLFormat, '

\n\nRow, row, row\n\n

\n\n
') self.assertMakes(mf, '...', Format, u'\u2026') self.assertMakes(mf, "Dr. Alex ``Bulldozer'' Anderson, Esq.", Format, u"Dr. Alex \u201CBulldozer\u201D Anderson, Esq.") self.assertMakes(mf, "\cenquote{``Dude.''}{Mike}", HTMLFormat, u'
\u201cDude.\u201d

Mike

') self.assertMakes(mf, 'Tammy & Rachel', LaTeXFormat, 'Tammy \\& Rachel') self.assertMakes(mf, '[[Wherever|Tammy & Rachel]]', LaTeXFormat, '\\href{Wherever}{Tammy \\& Rachel}') self.assertMakes(mf, '---', Format, u'\u2014') self.assertMakes(mf, '--', Format, u'\u2013') self.assertMakes(mf, "Foo---bar.", Format, u"Foo\u2014bar.") self.assertMakes(mf, "Foo -- bar.", Format, u"Foo\u2014bar.") self.assertMakes(mf, "7--9", Format, u"7\u20139") self.assertMakes(mf, "7-9", Format, u"7\u20139") self.assertMakes(mf, "Foo--\n\nbar.", Format, u"Foo\u2014\n\nbar.") self.assertMakes(mf, '--strike--', Format, u'\u2014strike\u2014') self.assertMakes(mf, "The party is from 7--9 or 8--10.", Format, u'The party is from 7\u20139 or 8\u201310.') self.assertMakes(mf, "5-story pagoda", Format, u'5-story pagoda') self.assertMakes(mf, '\start--\end', Format, u'1615\u20131618') self.assertMakes(mf, '\Dude--\Dude', Format, u'Bob\u2013Bob') self.assertMakes(mf, "\cenquote{``Dude.''}{-- Mike}", HTMLFormat, u'
\u201cDude.\u201d

\u2014Mike

') self.assertMakes(mf, r'Pok\'{e}mon', Format, u'Pok\u00E9mon') self.assertMakes(mf, r'Pok\'emon', Format, u'Pok\u00E9mon') self.assertMakes(mf, r"\Dude's sandwich", Format, u'Bob\u2019s sandwich') self.assertMakes(mf, r"I like \Dude.", Format, u'I like Bob.') self.assertMakes(mf, r"\Dude{Likes \Actors.}\Dude{}\Dude{}", Format, u'BobBobBob') self.assertMakes(mf, r"\Dude{\first}", Format, u'Bob') self.assertMakes(mf, r"\textbf{{{otron}}}", HTMLFormat, u'

otron

') # TODO(xavid) self.assertMakes(mf, r"\textbf{{img}}", HTMLFormat, u'

{img}

') self.assertMakes(mf, r"\Dude[[link]]", HTMLFormat, u'

Boblink

') self.assertMakes(mf, r"\Dude\\Fish", HTMLFormat, u'

Bob
Fish

') self.assertMakes(mf, r"\Dude~\Dude", Format, u'Bob\Dude') self.assertMakes(mf, r"<>I like \Dude<>", Format, u'*I like Bob*') self.assertMakes(mf, "* \emph{**\Dude**: \Dude, \Dude}", Format, u' * /*Bob*: Bob, Bob/') self.assertMakes(mf, r'''Foo \Dude Bar''', LaTeXFormat, u'''Foo Bob Bar''') # This syntax is standard to use with \LARGE, etc. self.assertMakes(mf, r'''{\textbf Foo}''', Format, '*Foo*') self.assertMakes(mf, r'''\textbf{{\emph Foo}}''', Format, '*/Foo/*') self.assertMakes(mf, r'''\Dude\Dude''', Format, 'BobBob') self.assertMakes(mf, r'''== Foo == \Dude == Foo ==''', HTMLFormat, '

Foo

\n\n

Bob

\n\n

Foo

') def testTeXMacros(self): def mf(name, arglist=None, content=None): if name == 'count': if content is not None: count = 1 for t in content: if (t.op == ENTITY and t.style == MACRO and t.arg[0] == 'break'): count += 1 else: count = 0 if arglist is not None: yield Text(unicode(len(arglist))) yield Text(u',') yield Text(unicode(count)) elif name == 'fish': yield Text(u"Trout") elif name.startswith('fish.'): yield Text(u"Fishy %s!" % name[len('fish.'):]) else: assert False, name self.assertMakes(mf, r'''\count{foo}{bar}{baz}''', Format, u'3') self.assertMakes(mf, r'''\count[foo][bar][baz]''', Format, u'3,0') self.assertMakes(mf, r'''\count[foo bar baz]''', Format, u'1,0') self.assertMakes(mf, r'''\count[foo][bar][baz]{fush}''', Format, u'3,1') self.assertMakes(mf, r'''\count[foo]{bar}[baz]{fush}''', Format, u'1,1[baz]{fush}') self.assertMakes(mf, r'''\fish.tree''', Format, u'Fishy tree!') self.assertMakes(mf, r'''\fish.tree house''', Format, u'Fishy tree! house') self.assertMakes(mf, r'''\fish. tree house''', Format, u'Trout. tree house') self.assertMakes(mf, r'''\fish.tree.house''', Format, u'Fishy tree.house!') def test_arglists(self): def mf(name, arglist=None, content=None): if name == 'fish': for a in arglist: assert isinstance(a, unicode), arglist yield Text(a) yield Text(u'.') elif name == 'element': yield Text(u'Metal') if arglist is not None: yield Text(unicode(len(arglist))) else: assert False, name self.assertMakes(mf, r'''\fish[foo bar][baz]''', Format, 'foo bar.baz.') self.assertMakes(mf, r'''<>''', Format, 'i.range(2, 4)."test this".') # Args aren't auto-evaled. self.assertMakes(mf, r'''\fish[Maladama][\element]''', Format, r'Maladama.\element.') self.assertMakes(mf, r'''\fish[Maladama][\element[2]]''', Format, 'Maladama.\element[2].') self.assertMakes(mf, r'''\fish[Maladama][\element["2"]]''', Format, 'Maladama.\element["2"].') def testQuotes(self): self.assertMakes(None, '"Why?"', Format, u'\u201CWhy?\u201D') self.assertMakes(None, "'Why?'", Format, u'\u2018Why?\u2019') self.assertMakes(None, 'He asked, "Why?"', Format, u'He asked, \u201CWhy?\u201D') self.assertMakes(None, 'He asked "Why?"', Format, u'He asked \u201CWhy?\u201D') self.assertMakes(None, '"Why?" he asked.', Format, u'\u201CWhy?\u201D he asked.') self.assertMakes(None, '"He told me \'No,\'" she said.', Format, u'\u201CHe told me \u2018No,\u2019\u201D she said.') self.assertMakes(None, '"He told me \'No,\' " she said.', Format, u'\u201CHe told me \u2018No,\u2019 \u201D she said.') self.assertMakes(None, '"\'No,\' he told me," she said.', Format, u'\u201C\u2018No,\u2019 he told me,\u201D she said.') self.assertMakes(None, '" \'No,\' he told me," she said.', Format, u'\u201C \u2018No,\u2019 he told me,\u201D she said.') self.assertMakes(None, 'Hank the-"Big"-Man Whistleblower', Format, u'Hank the-\u201CBig\u201D-Man Whistleblower') self.assertMakes(None, '("Why?")', Format, u'(\u201CWhy?\u201D)') self.assertMakes(None, '**"Why?"**', Format, u'*\u201CWhy?\u201D*') self.assertMakes(None, '"**Why?**"', Format, u'\u201C*Why?*\u201D') def mf(name, arglist=None, content=None): if name == 'break': return for t in content: yield t self.assertMakes(mf, r'\cenquote{"Why?"}', Format, u'\u201CWhy?\u201D') self.assertMakes(mf, r'\cenquote{"Why?"}{"Why not?}"', Format, u'\u201CWhy?\u201D\u201CWhy not?\u201D') def testCodeblock(self): self.assertMakes(None, """{{{ foo: bar }}}""", HTMLFormat, """
foo:
  bar
""") def testNoindent(self): def mf(name, arglist=None, content=None): if name == 'noindent': yield Entity(NOINDENT) # TODO(xavid): The space before Foo is dumb, but not worth worrying # about right now. self.assertMakes(mf, '\\noindent\nFoo\n', LaTeXFormat, u'\\noindent{} Foo') self.assertMakes(mf, '\\noindent\nFoo\n', HTMLFormat, u'

\nFoo

') def testSpacing(self): self.assertMakes(None, 'Foo Bar', Format, 'Foo Bar') self.assertMakes(None, 'Foo\n Bar', Format, 'Foo Bar') self.assertMakes(None, 'Foo\n\n----\n\nBar', Format, 'Foo\n\n' + 70*'-' + '\n\nBar') self.assertMakes(None, 'Foo\\\\\nBar', Format, 'Foo\nBar') self.assertMakes(None, 'Foo\\\\Bar', Format, 'Foo\nBar') def mf(name, arglist, content=None): if name == 'fish': yield Text(u"Carp") elif name == 'c': for t in content: yield t else: yield Text(u'???' + name) self.assertMakes(mf, '<>\\\\Bar', Format, 'Carp\nBar') self.assertMakes(mf, '\\c{foo\\\\bar}', Format, 'foo\nbar') def testLinks(self): self.assertMakes(None, '[[http://xavid.us/|Xavidland]]', LaTeXFormat, r'\href{http://xavid.us/}{Xavidland}') self.assertMakes(None, '[[http://xavid.us/?__arg=true|Xavidland]]', LaTeXFormat, r'\href{http://xavid.us/?\_\_arg=true}{Xavidland}') self.assertMakes(None, '[[http://xavid.us/~xavid/|Xavidland]]', LaTeXFormat, r'\href{http://xavid.us/\~{}xavid/}{Xavidland}') self.assertMakes(None, 'http://xavid.us/\n\nFoo', LaTeXFormat, r'''\href{http://xavid.us/}{http://xavid.us/} Foo''') self.assertMakes(None, '~http://xavid.us/', LaTeXFormat, r'http://xavid.us/') self.assertMakes(None, 'http://xavid.us/?__arg=true', LaTeXFormat, r'\href{http://xavid.us/?\_\_arg=true}{http://xavid.us/?\_\_arg=true}') self.assertMakes(None, '"http://xavid.us/">', LaTeXFormat, u'''\u201c\\href{http://xavid.us/}{http://xavid.us/}\u201c$>$''') self.assertMakes(None, '(http://xavid.us/).', LaTeXFormat, u'''(\\href{http://xavid.us/}{http://xavid.us/}).''') self.assertMakes(None, '[http://xavid.us/].', LaTeXFormat, u'''{[}\\href{http://xavid.us/}{http://xavid.us/}{]}.''') def mf(name, arglist, content=None): if name == 'subpage': yield Text(u"carp") # TODO(xavid): this should magically do the right thing self.assertMakes(mf, 'http://xavid.us/<>', LaTeXFormat, r'\href{http://xavid.us/}{http://xavid.us/}carp') self.assertMakes(mf, 'http://xavid.us/\subpage', LaTeXFormat, r'\href{http://xavid.us/}{http://xavid.us/}carp') if __name__ == "__main__": unittest.main()