Mercurial > hg-stable
changeset 15263:70d7293c41d6
minirst: improve test harness
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 15 Oct 2011 00:39:06 -0500 |
parents | e8076af14498 |
children | 157d93c41c10 |
files | tests/test-minirst.py tests/test-minirst.py.out |
diffstat | 2 files changed, 295 insertions(+), 297 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-minirst.py Sat Oct 15 00:39:04 2011 -0500 +++ b/tests/test-minirst.py Sat Oct 15 00:39:06 2011 -0500 @@ -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 @@ \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 @@ 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 @@ 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 @@ | 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 @@ --foo bar baz """ -debugformat('options', options, 60) -debugformat('options', options, 30) - +debugformats('options', options) fields = """ :a: First item. @@ -160,8 +156,7 @@ :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 @@ 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 @@ Markup: ``foo`` and :hg:`help` ------------------------------ """ -debugformat('sections', sections, 20) +debugformats('sections', sections) admonitions = """ @@ -219,7 +214,7 @@ This is danger """ -debugformat('admonitions', admonitions, 30) +debugformats('admonitions', admonitions) comments = """ Some text. @@ -235,7 +230,7 @@ Empty comment above """ -debugformat('comments', comments, 30) +debugformats('comments', comments) data = [['a', 'b', 'c'], @@ -246,4 +241,4 @@ print table -debugformat('table', table, 30) +debugformats('table', table)
--- a/tests/test-minirst.py.out Sat Oct 15 00:39:04 2011 -0500 +++ b/tests/test-minirst.py.out Sat Oct 15 00:39:06 2011 -0500 @@ -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 @@ 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: ---------------------------------------------------------------------- <p> This is some text in the first paragraph. @@ -19,37 +35,10 @@ <p> The third and final paragraph. </p> - ---------------------------------------------------------------------- -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. - ----------------------------------------------------------------------- -<p> -This is some text in the first paragraph. -</p> -<p> -A small indented paragraph. -It is followed by some lines -containing random whitespace. -</p> -<p> -The third and final paragraph. -</p> - ----------------------------------------------------------------------- - -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 @@ A Nested/Indented Term Definition. - ----------------------------------------------------------------------- -<dl> - <dt>A Term - <dd>Definition. The indented lines make up the definition. - <dt>Another Term - <dd>Another definition. The final line in the definition determines the indentation, so this will be indented with four spaces. - <dt>A Nested/Indented Term - <dd>Definition. -</dl> - ---------------------------------------------------------------------- -definitions formatted to fit within 30 characters: +30 column format: ---------------------------------------------------------------------- A Term Definition. The indented @@ -91,7 +69,9 @@ A Nested/Indented Term Definition. +---------------------------------------------------------------------- +html format: ---------------------------------------------------------------------- <dl> <dt>A Term @@ -101,10 +81,10 @@ <dt>A Nested/Indented Term <dd>Definition. </dl> - ---------------------------------------------------------------------- -literals formatted to fit within 60 characters: +== literals == +60 column format: ---------------------------------------------------------------------- The fully minimized form is the most convenient form: @@ -122,7 +102,31 @@ 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: ---------------------------------------------------------------------- <p> The fully minimized form is the most @@ -147,58 +151,10 @@ the so-called expanded form. The paragraph with '::' disappears in the final output. </pre> - ---------------------------------------------------------------------- -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. - ----------------------------------------------------------------------- -<p> -The fully minimized form is the most -convenient form: -</p> -<pre> -Hello - literal - world -</pre> -<p> -In the partially minimized form a paragraph -simply ends with space-double-colon. -</p> -<pre> -//////////////////////////////////////// -long un-wrapped line in a literal block -\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ -</pre> -<pre> -This literal block is started with '::', - the so-called expanded form. The paragraph - with '::' disappears in the final output. -</pre> - ----------------------------------------------------------------------- - -lists formatted to fit within 60 characters: +== lists == +60 column format: ---------------------------------------------------------------------- - This is the first list item. @@ -231,7 +187,53 @@ 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: ---------------------------------------------------------------------- <ul> <li> This is the first list item. @@ -274,98 +276,10 @@ <li> This is the first line. The line continues here. <li> This is the second line. </ol> - ---------------------------------------------------------------------- -lists formatted to fit within 30 characters: ----------------------------------------------------------------------- -- 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. - ----------------------------------------------------------------------- -<ul> - <li> This is the first list item. -<p> -Second paragraph in the first list item. -</p> - <li> List items need not be separated by a blank line. - <li> And will be rendered without one in any case. -</ul> -<p> -We can have indented lists: -</p> -<ul> - <li> This is an indented list item - <li> Another indented list item: -<pre> -- A literal block in the middle - of an indented list. -</pre> -<pre> -(The above is not a list item since we are in the literal block.) -</pre> -</ul> -<pre> -Literal block with no indentation (apart from -the two spaces added to all literal blocks). -</pre> -<ol> - <li> This is an enumerated list (first item). - <li> Continuing with the second item. - <li> foo - <li> bar - <li> Another - <li> List -</ol> -<p> -Line blocks are also a form of list: -</p> -<ol> - <li> This is the first line. The line continues here. - <li> This is the second line. -</ol> - ----------------------------------------------------------------------- - -options formatted to fit within 60 characters: +== options == +60 column format: ---------------------------------------------------------------------- There is support for simple option lists, but only with long options: @@ -390,41 +304,9 @@ paragraph: --foo bar baz - ----------------------------------------------------------------------- -<p> -There is support for simple option lists, -but only with long options: -</p> -<dl> - <dt>-X --exclude filter - <dd>an option with a short and long option with an argument - <dt>-I --include - <dd>an option with both a short option and a long option - <dt> --all - <dd>Output all. - <dt> --both - <dd>Output both (this description is quite long). - <dt> --long - <dd>Output all day long. - <dt> --par - <dd>This option has two paragraphs in its description. This is the first. -<p> -This is the second. Blank lines may be omitted between -options (as above) or left in (as here). -</p> -</dl> -<p> -The next paragraph looks like an option list, but lacks the two-space -marker after the option. It is treated as a normal paragraph: -</p> -<p> ---foo bar baz -</p> - ---------------------------------------------------------------------- -options formatted to fit within 30 characters: +30 column format: ---------------------------------------------------------------------- There is support for simple option lists, but only with @@ -494,7 +376,9 @@ normal paragraph: --foo bar baz +---------------------------------------------------------------------- +html format: ---------------------------------------------------------------------- <p> There is support for simple option lists, @@ -525,10 +409,10 @@ <p> --foo bar baz </p> - ---------------------------------------------------------------------- -fields formatted to fit within 60 characters: +== fields == +60 column format: ---------------------------------------------------------------------- a First item. ab Second item. Indentation and wrapping is handled @@ -540,27 +424,9 @@ here. much too large This key is big enough to get its own line. - ----------------------------------------------------------------------- -<dl> - <dt>a - <dd>First item. - <dt>ab - <dd>Second item. Indentation and wrapping is handled automatically. -</dl> -<p> -Next list: -</p> -<dl> - <dt>small - <dd>The larger key below triggers full indentation here. - <dt>much too large - <dd>This key is big enough to get its own line. -</dl> - ---------------------------------------------------------------------- -fields formatted to fit within 30 characters: +30 column format: ---------------------------------------------------------------------- a First item. ab Second item. Indentation @@ -577,7 +443,9 @@ This key is big enough to get its own line. +---------------------------------------------------------------------- +html format: ---------------------------------------------------------------------- <dl> <dt>a @@ -594,45 +462,90 @@ <dt>much too large <dd>This key is big enough to get its own line. </dl> - ---------------------------------------------------------------------- -containers (normal) formatted to fit within 60 characters: +== containers (normal) == +60 column format: ---------------------------------------------------------------------- Normal output. +---------------------------------------------------------------------- +30 column format: +---------------------------------------------------------------------- +Normal output. +---------------------------------------------------------------------- + +html format: ---------------------------------------------------------------------- <p> Normal output. </p> - ---------------------------------------------------------------------- -containers (verbose) formatted to fit within 60 characters: +== containers (verbose) == +60 column format: +---------------------------------------------------------------------- +Normal output. + +Verbose output. +---------------------------------------------------------------------- +['debug', 'debug'] +---------------------------------------------------------------------- + +30 column format: ---------------------------------------------------------------------- Normal output. Verbose output. +---------------------------------------------------------------------- +['debug', 'debug'] +---------------------------------------------------------------------- +html format: ---------------------------------------------------------------------- -('<p>\nNormal output.\n</p>\n<p>\nVerbose output.\n</p>\n', ['debug', 'debug']) +<p> +Normal output. +</p> +<p> +Verbose output. +</p> ---------------------------------------------------------------------- ['debug', 'debug'] ---------------------------------------------------------------------- -containers (debug) formatted to fit within 60 characters: +== containers (debug) == +60 column format: +---------------------------------------------------------------------- +Normal output. + +Initial debug output. +---------------------------------------------------------------------- +['verbose'] +---------------------------------------------------------------------- + +30 column format: ---------------------------------------------------------------------- Normal output. Initial debug output. - ----------------------------------------------------------------------- -('<p>\nNormal output.\n</p>\n<p>\nInitial debug output.\n</p>\n', ['verbose']) ---------------------------------------------------------------------- ['verbose'] ---------------------------------------------------------------------- -containers (verbose debug) formatted to fit within 60 characters: +html format: +---------------------------------------------------------------------- +<p> +Normal output. +</p> +<p> +Initial debug output. +</p> +---------------------------------------------------------------------- +['verbose'] +---------------------------------------------------------------------- + +== containers (verbose debug) == +60 column format: ---------------------------------------------------------------------- Normal output. @@ -641,25 +554,61 @@ Verbose output. Debug output. +---------------------------------------------------------------------- +[] +---------------------------------------------------------------------- +30 column format: ---------------------------------------------------------------------- -('<p>\nNormal output.\n</p>\n<p>\nInitial debug output.\n</p>\n<p>\nVerbose output.\n</p>\n<p>\nDebug output.\n</p>\n', []) +Normal output. + +Initial debug output. + +Verbose output. + +Debug output. ---------------------------------------------------------------------- [] ---------------------------------------------------------------------- -roles formatted to fit within 60 characters: +html format: +---------------------------------------------------------------------- +<p> +Normal output. +</p> +<p> +Initial debug output. +</p> +<p> +Verbose output. +</p> +<p> +Debug output. +</p> +---------------------------------------------------------------------- +[] +---------------------------------------------------------------------- + +== roles == +60 column format: ---------------------------------------------------------------------- Please see "hg add". +---------------------------------------------------------------------- +30 column format: +---------------------------------------------------------------------- +Please see "hg add". +---------------------------------------------------------------------- + +html format: ---------------------------------------------------------------------- <p> Please see "hg add". </p> - ---------------------------------------------------------------------- -sections formatted to fit within 20 characters: +== sections == +60 column format: ---------------------------------------------------------------------- Title ===== @@ -672,16 +621,48 @@ Markup: "foo" and "hg help" --------------------------- +---------------------------------------------------------------------- +30 column format: +---------------------------------------------------------------------- +Title +===== + +Section +------- + +Subsection +'''''''''' + +Markup: "foo" and "hg help" +--------------------------- +---------------------------------------------------------------------- + +html format: ---------------------------------------------------------------------- <h1>Title</h1> <h2>Section</h2> <h3>Subsection</h3> <h2>Markup: "foo" and "hg help"</h2> - ---------------------------------------------------------------------- -admonitions formatted to fit within 30 characters: +== admonitions == +60 column format: +---------------------------------------------------------------------- +Note: + This is a note + + - Bullet 1 + - Bullet 2 + + Warning! + This is a warning Second input line of warning + +!Danger! + This is danger +---------------------------------------------------------------------- + +30 column format: ---------------------------------------------------------------------- Note: This is a note @@ -695,7 +676,9 @@ !Danger! This is danger +---------------------------------------------------------------------- +html format: ---------------------------------------------------------------------- <p> <b>Note:</b> This is a note @@ -710,17 +693,28 @@ <p> <b>!Danger!</b> This is danger </p> - ---------------------------------------------------------------------- -comments formatted to fit within 30 characters: +== comments == +60 column format: ---------------------------------------------------------------------- Some text. Some indented text. Empty comment above +---------------------------------------------------------------------- +30 column format: +---------------------------------------------------------------------- +Some text. + + Some indented text. + +Empty comment above +---------------------------------------------------------------------- + +html format: ---------------------------------------------------------------------- <p> Some text. @@ -731,7 +725,6 @@ <p> Empty comment above </p> - ---------------------------------------------------------------------- === === ======================================== @@ -741,7 +734,16 @@ foo bar baz this list is very very very long man === === ======================================== -table formatted to fit within 30 characters: +== table == +60 column format: +---------------------------------------------------------------------- + a b c + ------------------------------------------------ + 1 2 3 + foo bar baz this list is very very very long man +---------------------------------------------------------------------- + +30 column format: ---------------------------------------------------------------------- a b c ------------------------------ @@ -749,13 +751,14 @@ foo bar baz this list is very very very long man +---------------------------------------------------------------------- +html format: ---------------------------------------------------------------------- <table> <tr><th>a</th><th>b</th><th>c</th></tr> <tr><td>1</td><td>2</td><td>3</td></tr> <tr><td>foo</td><td>bar</td><td>baz this list is very very very long man</td></tr> </table> - ----------------------------------------------------------------------