[PATCH 2 of 2] templates/filters: add doctest to the 'person' filter
Yann E. MORIN
yann.morin.1998 at free.fr
Fri Mar 9 16:36:46 CST 2012
# HG changeset patch
# User "Yann E. MORIN" <yann.morin.1998 at free.fr>
# Date 1331078532 -3600
# Node ID 1b7f0cfa87aeb1316a0c293c8e824f8f687206b9
# Parent de00e433c8be1b7538ee675c31905468603c31e8
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 at aragost.com>
Thanks!
Signed-off-by: "Yann E. MORIN" <yann.morin.1998 at free.fr>
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -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 at bar')
+ 'foo'
+ >>> person('Foo Bar <foo at bar>')
+ 'Foo Bar'
+ >>> person('"Foo Bar" <foo at bar>')
+ 'Foo Bar'
+ >>> person('"Foo \"buz\" Bar" <foo at bar>')
+ 'Foo "buz" Bar'
+ >>> # The following are invalid, but do exist in real-life
+ ...
+ >>> person('Foo "buz" Bar <foo at bar>')
+ 'Foo "buz" Bar'
+ >>> person('"Foo Bar <foo at bar>')
+ 'Foo Bar'
"""
if not '@' in author:
return author
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -39,3 +39,6 @@
import mercurial.minirst
doctest.testmod(mercurial.minirst)
+
+import mercurial.templatefilters
+doctest.testmod(mercurial.templatefilters)
More information about the Mercurial-devel
mailing list