comparison mercurial/templatefilters.py @ 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 eb39bbda167b
children e5788269741a
comparison
equal deleted inserted replaced
16250:684864d54903 16251:db68ee3289b6
242 return "-rw-r--r--" 242 return "-rw-r--r--"
243 243
244 def person(author): 244 def person(author):
245 """:person: Any text. Returns the name before an email address, 245 """:person: Any text. Returns the name before an email address,
246 interpreting it as per RFC 5322. 246 interpreting it as per RFC 5322.
247
248 >>> person('foo@bar')
249 'foo'
250 >>> person('Foo Bar <foo@bar>')
251 'Foo Bar'
252 >>> person('"Foo Bar" <foo@bar>')
253 'Foo Bar'
254 >>> person('"Foo \"buz\" Bar" <foo@bar>')
255 'Foo "buz" Bar'
256 >>> # The following are invalid, but do exist in real-life
257 ...
258 >>> person('Foo "buz" Bar <foo@bar>')
259 'Foo "buz" Bar'
260 >>> person('"Foo Bar <foo@bar>')
261 'Foo Bar'
247 """ 262 """
248 if not '@' in author: 263 if not '@' in author:
249 return author 264 return author
250 f = author.find('<') 265 f = author.find('<')
251 if f != -1: 266 if f != -1: