templates/filters: add doctest to the 'person' filter
author"Yann E. MORIN" <yann.morin.1998@free.fr>
Wed, 07 Mar 2012 01:02:12 +0100
changeset 16251 db68ee3289b6
parent 16250 684864d54903
child 16253 17f179805297
templates/filters: add doctest to the 'person' filter Add a doctest with an hopefuly-comprehensive list of combinations we can expect in real-life situations. This does not cover corner cases, for example when a CR or LF is embedded in the name (allowed by RFC 5322!). Code in tests/test-doctest.py contributed by: Martin Geisler <mg@aragost.com> Thanks! Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
mercurial/templatefilters.py
tests/test-doctest.py
--- a/mercurial/templatefilters.py	Fri Mar 09 22:54:17 2012 +0100
+++ b/mercurial/templatefilters.py	Wed Mar 07 01:02:12 2012 +0100
@@ -244,6 +244,21 @@
 def person(author):
     """:person: Any text. Returns the name before an email address,
     interpreting it as per RFC 5322.
+
+    >>> person('foo@bar')
+    'foo'
+    >>> person('Foo Bar <foo@bar>')
+    'Foo Bar'
+    >>> person('"Foo Bar" <foo@bar>')
+    'Foo Bar'
+    >>> person('"Foo \"buz\" Bar" <foo@bar>')
+    'Foo "buz" Bar'
+    >>> # The following are invalid, but do exist in real-life
+    ...
+    >>> person('Foo "buz" Bar <foo@bar>')
+    'Foo "buz" Bar'
+    >>> person('"Foo Bar <foo@bar>')
+    'Foo Bar'
     """
     if not '@' in author:
         return author
--- a/tests/test-doctest.py	Fri Mar 09 22:54:17 2012 +0100
+++ b/tests/test-doctest.py	Wed Mar 07 01:02:12 2012 +0100
@@ -39,3 +39,6 @@
 
 import mercurial.minirst
 doctest.testmod(mercurial.minirst)
+
+import mercurial.templatefilters
+doctest.testmod(mercurial.templatefilters)