# HG changeset patch # User Matt Mackall # Date 2011-10-15 05:39:06 # Node ID 70d7293c41d62c97e3a922e26f66eb020a2bfe7a # Parent e8076af14498cdc1097db4a92e909c20cb5bca07 minirst: improve test harness diff --git a/tests/test-minirst.py b/tests/test-minirst.py --- a/tests/test-minirst.py +++ b/tests/test-minirst.py @@ -1,24 +1,30 @@ from pprint import pprint from mercurial import minirst -def debugformat(title, text, width, **kwargs): - print "%s formatted to fit within %d characters:" % (title, width) - formatted = minirst.format(text, width, **kwargs) - html = minirst.format(text, width, style='html', **kwargs) +def debugformat(text, form, **kwargs): + if form == 'html': + print "html format:" + out = minirst.format(text, style=form, **kwargs) + else: + print "%d column format:" % form + out = minirst.format(text, width=form, **kwargs) + print "-" * 70 - if type(formatted) == tuple: - print formatted[0] + if type(out) == tuple: + print out[0][:-1] print "-" * 70 - print html - print "-" * 70 - pprint(formatted[1]) + pprint(out[1]) else: - print formatted - print "-" * 70 - print html + print out[:-1] print "-" * 70 print +def debugformats(title, text, **kwargs): + print "== %s ==" % title + debugformat(text, 60, **kwargs) + debugformat(text, 30, **kwargs) + debugformat(text, 'html', **kwargs) + paragraphs = """ This is some text in the first paragraph. @@ -28,9 +34,7 @@ This is some text in the first paragraph \n \n \nThe third and final paragraph. """ -debugformat('paragraphs', paragraphs, 60) -debugformat('paragraphs', paragraphs, 30) - +debugformats('paragraphs', paragraphs) definitions = """ A Term @@ -45,9 +49,7 @@ Another Term Definition. """ -debugformat('definitions', definitions, 60) -debugformat('definitions', definitions, 30) - +debugformats('definitions', definitions) literals = r""" The fully minimized form is the most @@ -71,9 +73,7 @@ simply ends with space-double-colon. :: with '::' disappears in the final output. """ -debugformat('literals', literals, 60) -debugformat('literals', literals, 30) - +debugformats('literals', literals) lists = """ - This is the first list item. @@ -117,9 +117,7 @@ Line blocks are also a form of list: | This is the second line. """ -debugformat('lists', lists, 60) -debugformat('lists', lists, 30) - +debugformats('lists', lists) options = """ There is support for simple option lists, @@ -145,9 +143,7 @@ marker after the option. It is treated a --foo bar baz """ -debugformat('options', options, 60) -debugformat('options', options, 30) - +debugformats('options', options) fields = """ :a: First item. @@ -160,8 +156,7 @@ Next list: :much too large: This key is big enough to get its own line. """ -debugformat('fields', fields, 60) -debugformat('fields', fields, 30) +debugformats('fields', fields) containers = """ Normal output. @@ -179,14 +174,14 @@ Normal output. Debug output. """ -debugformat('containers (normal)', containers, 60) -debugformat('containers (verbose)', containers, 60, keep=['verbose']) -debugformat('containers (debug)', containers, 60, keep=['debug']) -debugformat('containers (verbose debug)', containers, 60, +debugformats('containers (normal)', containers) +debugformats('containers (verbose)', containers, keep=['verbose']) +debugformats('containers (debug)', containers, keep=['debug']) +debugformats('containers (verbose debug)', containers, keep=['verbose', 'debug']) roles = """Please see :hg:`add`.""" -debugformat('roles', roles, 60) +debugformats('roles', roles) sections = """ @@ -202,7 +197,7 @@ Subsection Markup: ``foo`` and :hg:`help` ------------------------------ """ -debugformat('sections', sections, 20) +debugformats('sections', sections) admonitions = """ @@ -219,7 +214,7 @@ admonitions = """ This is danger """ -debugformat('admonitions', admonitions, 30) +debugformats('admonitions', admonitions) comments = """ Some text. @@ -235,7 +230,7 @@ Some text. Empty comment above """ -debugformat('comments', comments, 30) +debugformats('comments', comments) data = [['a', 'b', 'c'], @@ -246,4 +241,4 @@ table = minirst.maketable(data, 2, True) print table -debugformat('table', table, 30) +debugformats('table', table) diff --git a/tests/test-minirst.py.out b/tests/test-minirst.py.out --- a/tests/test-minirst.py.out +++ b/tests/test-minirst.py.out @@ -1,4 +1,5 @@ -paragraphs formatted to fit within 60 characters: +== paragraphs == +60 column format: ---------------------------------------------------------------------- This is some text in the first paragraph. @@ -6,7 +7,22 @@ This is some text in the first paragraph containing random whitespace. The third and final paragraph. +---------------------------------------------------------------------- +30 column format: +---------------------------------------------------------------------- +This is some text in the first +paragraph. + + A small indented paragraph. + It is followed by some lines + containing random + whitespace. + +The third and final paragraph. +---------------------------------------------------------------------- + +html format: ----------------------------------------------------------------------

This is some text in the first paragraph. @@ -19,37 +35,10 @@ containing random whitespace.

The third and final paragraph.

- ---------------------------------------------------------------------- -paragraphs formatted to fit within 30 characters: ----------------------------------------------------------------------- -This is some text in the first -paragraph. - - A small indented paragraph. - It is followed by some lines - containing random - whitespace. - -The third and final paragraph. - ----------------------------------------------------------------------- -

-This is some text in the first paragraph. -

-

-A small indented paragraph. -It is followed by some lines -containing random whitespace. -

-

-The third and final paragraph. -

- ----------------------------------------------------------------------- - -definitions formatted to fit within 60 characters: +== definitions == +60 column format: ---------------------------------------------------------------------- A Term Definition. The indented lines make up the definition. @@ -61,20 +50,9 @@ Another Term A Nested/Indented Term Definition. - ----------------------------------------------------------------------- -
-
A Term -
Definition. The indented lines make up the definition. -
Another Term -
Another definition. The final line in the definition determines the indentation, so this will be indented with four spaces. -
A Nested/Indented Term -
Definition. -
- ---------------------------------------------------------------------- -definitions formatted to fit within 30 characters: +30 column format: ---------------------------------------------------------------------- A Term Definition. The indented @@ -91,7 +69,9 @@ Another Term A Nested/Indented Term Definition. +---------------------------------------------------------------------- +html format: ----------------------------------------------------------------------
A Term @@ -101,10 +81,10 @@ Another Term
A Nested/Indented Term
Definition.
- ---------------------------------------------------------------------- -literals formatted to fit within 60 characters: +== literals == +60 column format: ---------------------------------------------------------------------- The fully minimized form is the most convenient form: @@ -122,7 +102,31 @@ space-double-colon. This literal block is started with '::', the so-called expanded form. The paragraph with '::' disappears in the final output. +---------------------------------------------------------------------- +30 column format: +---------------------------------------------------------------------- +The fully minimized form is +the most convenient form: + + Hello + literal + world + +In the partially minimized +form a paragraph simply ends +with space-double-colon. + + //////////////////////////////////////// + long un-wrapped line in a literal block + \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ + + This literal block is started with '::', + the so-called expanded form. The paragraph + with '::' disappears in the final output. +---------------------------------------------------------------------- + +html format: ----------------------------------------------------------------------

The fully minimized form is the most @@ -147,58 +151,10 @@ This literal block is started with '::', the so-called expanded form. The paragraph with '::' disappears in the final output. - ---------------------------------------------------------------------- -literals formatted to fit within 30 characters: ----------------------------------------------------------------------- -The fully minimized form is -the most convenient form: - - Hello - literal - world - -In the partially minimized -form a paragraph simply ends -with space-double-colon. - - //////////////////////////////////////// - long un-wrapped line in a literal block - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ - - This literal block is started with '::', - the so-called expanded form. The paragraph - with '::' disappears in the final output. - ----------------------------------------------------------------------- -

-The fully minimized form is the most -convenient form: -

-
-Hello
-  literal
-    world
-
-

-In the partially minimized form a paragraph -simply ends with space-double-colon. -

-
-////////////////////////////////////////
-long un-wrapped line in a literal block
-\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
-
-
-This literal block is started with '::',
-  the so-called expanded form. The paragraph
-    with '::' disappears in the final output.
-
- ----------------------------------------------------------------------- - -lists formatted to fit within 60 characters: +== lists == +60 column format: ---------------------------------------------------------------------- - This is the first list item. @@ -231,7 +187,53 @@ Line blocks are also a form of list: This is the first line. The line continues here. This is the second line. +---------------------------------------------------------------------- +30 column format: +---------------------------------------------------------------------- +- This is the first list item. + + Second paragraph in the + first list item. + +- List items need not be + separated by a blank line. +- And will be rendered without + one in any case. + +We can have indented lists: + + - This is an indented list + item + - Another indented list + item: + + - A literal block in the middle + of an indented list. + + (The above is not a list item since we are in the literal block.) + + Literal block with no indentation (apart from + the two spaces added to all literal blocks). + +1. This is an enumerated list + (first item). +2. Continuing with the second + item. +(1) foo +(2) bar +1) Another +2) List + +Line blocks are also a form of +list: + +This is the first line. The +line continues here. +This is the second line. +---------------------------------------------------------------------- + +html format: ----------------------------------------------------------------------