# HG changeset patch # User "Yann E. MORIN" # Date 1331078532 -3600 # Node ID db68ee3289b634dd33579273a2ddd60cdea4a2ea # Parent 684864d54903e4d15a0fd6f3368574a1fa50cac5 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 Thanks! Signed-off-by: "Yann E. MORIN" diff -r 684864d54903 -r db68ee3289b6 mercurial/templatefilters.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' + >>> person('"Foo Bar" ') + 'Foo Bar' + >>> person('"Foo \"buz\" Bar" ') + 'Foo "buz" Bar' + >>> # The following are invalid, but do exist in real-life + ... + >>> person('Foo "buz" Bar ') + 'Foo "buz" Bar' + >>> person('"Foo Bar ') + 'Foo Bar' """ if not '@' in author: return author diff -r 684864d54903 -r db68ee3289b6 tests/test-doctest.py --- 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)