tests/test-minirst.py
changeset 15263 70d7293c41d6
parent 15262 e8076af14498
child 16815 e740746ea557
equal deleted inserted replaced
15262:e8076af14498 15263:70d7293c41d6
     1 from pprint import pprint
     1 from pprint import pprint
     2 from mercurial import minirst
     2 from mercurial import minirst
     3 
     3 
     4 def debugformat(title, text, width, **kwargs):
     4 def debugformat(text, form, **kwargs):
     5     print "%s formatted to fit within %d characters:" % (title, width)
     5     if form == 'html':
     6     formatted = minirst.format(text, width, **kwargs)
     6         print "html format:"
     7     html = minirst.format(text, width, style='html', **kwargs)
     7         out = minirst.format(text, style=form, **kwargs)
       
     8     else:
       
     9         print "%d column format:" % form
       
    10         out = minirst.format(text, width=form, **kwargs)
       
    11 
     8     print "-" * 70
    12     print "-" * 70
     9     if type(formatted) == tuple:
    13     if type(out) == tuple:
    10         print formatted[0]
    14         print out[0][:-1]
    11         print "-" * 70
    15         print "-" * 70
    12         print html
    16         pprint(out[1])
    13         print "-" * 70
       
    14         pprint(formatted[1])
       
    15     else:
    17     else:
    16         print formatted
    18         print out[:-1]
    17         print "-" * 70
       
    18         print html
       
    19     print "-" * 70
    19     print "-" * 70
    20     print
    20     print
       
    21 
       
    22 def debugformats(title, text, **kwargs):
       
    23     print "== %s ==" % title
       
    24     debugformat(text, 60, **kwargs)
       
    25     debugformat(text, 30, **kwargs)
       
    26     debugformat(text, 'html', **kwargs)
    21 
    27 
    22 paragraphs = """
    28 paragraphs = """
    23 This is some text in the first paragraph.
    29 This is some text in the first paragraph.
    24 
    30 
    25   A small indented paragraph.
    31   A small indented paragraph.
    26   It is followed by some lines
    32   It is followed by some lines
    27   containing random whitespace.
    33   containing random whitespace.
    28  \n  \n   \nThe third and final paragraph.
    34  \n  \n   \nThe third and final paragraph.
    29 """
    35 """
    30 
    36 
    31 debugformat('paragraphs', paragraphs, 60)
    37 debugformats('paragraphs', paragraphs)
    32 debugformat('paragraphs', paragraphs, 30)
       
    33 
       
    34 
    38 
    35 definitions = """
    39 definitions = """
    36 A Term
    40 A Term
    37   Definition. The indented
    41   Definition. The indented
    38   lines make up the definition.
    42   lines make up the definition.
    43 
    47 
    44   A Nested/Indented Term
    48   A Nested/Indented Term
    45     Definition.
    49     Definition.
    46 """
    50 """
    47 
    51 
    48 debugformat('definitions', definitions, 60)
    52 debugformats('definitions', definitions)
    49 debugformat('definitions', definitions, 30)
       
    50 
       
    51 
    53 
    52 literals = r"""
    54 literals = r"""
    53 The fully minimized form is the most
    55 The fully minimized form is the most
    54 convenient form::
    56 convenient form::
    55 
    57 
    69   This literal block is started with '::',
    71   This literal block is started with '::',
    70     the so-called expanded form. The paragraph
    72     the so-called expanded form. The paragraph
    71       with '::' disappears in the final output.
    73       with '::' disappears in the final output.
    72 """
    74 """
    73 
    75 
    74 debugformat('literals', literals, 60)
    76 debugformats('literals', literals)
    75 debugformat('literals', literals, 30)
       
    76 
       
    77 
    77 
    78 lists = """
    78 lists = """
    79 - This is the first list item.
    79 - This is the first list item.
    80 
    80 
    81   Second paragraph in the first list item.
    81   Second paragraph in the first list item.
   115 | This is the first line.
   115 | This is the first line.
   116   The line continues here.
   116   The line continues here.
   117 | This is the second line.
   117 | This is the second line.
   118 """
   118 """
   119 
   119 
   120 debugformat('lists', lists, 60)
   120 debugformats('lists', lists)
   121 debugformat('lists', lists, 30)
       
   122 
       
   123 
   121 
   124 options = """
   122 options = """
   125 There is support for simple option lists,
   123 There is support for simple option lists,
   126 but only with long options:
   124 but only with long options:
   127 
   125 
   143 marker after the option. It is treated as a normal paragraph:
   141 marker after the option. It is treated as a normal paragraph:
   144 
   142 
   145 --foo bar baz
   143 --foo bar baz
   146 """
   144 """
   147 
   145 
   148 debugformat('options', options, 60)
   146 debugformats('options', options)
   149 debugformat('options', options, 30)
       
   150 
       
   151 
   147 
   152 fields = """
   148 fields = """
   153 :a: First item.
   149 :a: First item.
   154 :ab: Second item. Indentation and wrapping
   150 :ab: Second item. Indentation and wrapping
   155      is handled automatically.
   151      is handled automatically.
   158 
   154 
   159 :small: The larger key below triggers full indentation here.
   155 :small: The larger key below triggers full indentation here.
   160 :much too large: This key is big enough to get its own line.
   156 :much too large: This key is big enough to get its own line.
   161 """
   157 """
   162 
   158 
   163 debugformat('fields', fields, 60)
   159 debugformats('fields', fields)
   164 debugformat('fields', fields, 30)
       
   165 
   160 
   166 containers = """
   161 containers = """
   167 Normal output.
   162 Normal output.
   168 
   163 
   169 .. container:: debug
   164 .. container:: debug
   177    .. container:: debug
   172    .. container:: debug
   178 
   173 
   179       Debug output.
   174       Debug output.
   180 """
   175 """
   181 
   176 
   182 debugformat('containers (normal)', containers, 60)
   177 debugformats('containers (normal)', containers)
   183 debugformat('containers (verbose)', containers, 60, keep=['verbose'])
   178 debugformats('containers (verbose)', containers, keep=['verbose'])
   184 debugformat('containers (debug)', containers, 60, keep=['debug'])
   179 debugformats('containers (debug)', containers, keep=['debug'])
   185 debugformat('containers (verbose debug)', containers, 60,
   180 debugformats('containers (verbose debug)', containers,
   186             keep=['verbose', 'debug'])
   181             keep=['verbose', 'debug'])
   187 
   182 
   188 roles = """Please see :hg:`add`."""
   183 roles = """Please see :hg:`add`."""
   189 debugformat('roles', roles, 60)
   184 debugformats('roles', roles)
   190 
   185 
   191 
   186 
   192 sections = """
   187 sections = """
   193 Title
   188 Title
   194 =====
   189 =====
   200 ''''''''''
   195 ''''''''''
   201 
   196 
   202 Markup: ``foo`` and :hg:`help`
   197 Markup: ``foo`` and :hg:`help`
   203 ------------------------------
   198 ------------------------------
   204 """
   199 """
   205 debugformat('sections', sections, 20)
   200 debugformats('sections', sections)
   206 
   201 
   207 
   202 
   208 admonitions = """
   203 admonitions = """
   209 .. note::
   204 .. note::
   210    This is a note
   205    This is a note
   217 
   212 
   218 .. danger::
   213 .. danger::
   219    This is danger
   214    This is danger
   220 """
   215 """
   221 
   216 
   222 debugformat('admonitions', admonitions, 30)
   217 debugformats('admonitions', admonitions)
   223 
   218 
   224 comments = """
   219 comments = """
   225 Some text.
   220 Some text.
   226 
   221 
   227 .. A comment
   222 .. A comment
   233 ..
   228 ..
   234 
   229 
   235 Empty comment above
   230 Empty comment above
   236 """
   231 """
   237 
   232 
   238 debugformat('comments', comments, 30)
   233 debugformats('comments', comments)
   239 
   234 
   240 
   235 
   241 data = [['a', 'b', 'c'],
   236 data = [['a', 'b', 'c'],
   242          ['1', '2', '3'],
   237          ['1', '2', '3'],
   243          ['foo', 'bar', 'baz this list is very very very long man']]
   238          ['foo', 'bar', 'baz this list is very very very long man']]
   244 
   239 
   245 table = minirst.maketable(data, 2, True)
   240 table = minirst.maketable(data, 2, True)
   246 
   241 
   247 print table
   242 print table
   248 
   243 
   249 debugformat('table', table, 30)
   244 debugformats('table', table)