Mercurial > hg-stable
changeset 16251:db68ee3289b6
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>
author | "Yann E. MORIN" <yann.morin.1998@free.fr> |
---|---|
date | Wed, 07 Mar 2012 01:02:12 +0100 |
parents | 684864d54903 |
children | 17f179805297 |
files | mercurial/templatefilters.py tests/test-doctest.py |
diffstat | 2 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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