core: Fix normalizeWhitespace handling of new lines.

This commit is contained in:
Valentin Lorentz 2013-01-04 22:28:44 +01:00
parent 29e13a9061
commit fe39d35b2f
2 changed files with 6 additions and 3 deletions

View File

@ -55,13 +55,14 @@ def rsplit(s, sep=None, maxsplit=-1):
else:
return s.rsplit(sep, maxsplit)
def normalizeWhitespace(s, removeNewline=False):
def normalizeWhitespace(s, removeNewline=True):
"""Normalizes the whitespace in a string; \s+ becomes one space."""
if not s:
return str(s) # not the same reference
starts_with_space = (s[0] in ' \n\t')
ends_with_space = (s[-1] in ' \n\t')
s = ('' if removeNewline else ' ').join(filter(bool, s.split('\n')))
if removeNewline:
s = ' '.join(filter(bool, s.split('\n')))
s = ' '.join(filter(bool, s.split('\t')))
s = ' '.join(filter(bool, s.split(' ')))
if starts_with_space:

View File

@ -39,7 +39,7 @@ _ = PluginInternationalization()
@internationalizeDocstring
def foo():
'The operation succeeded.'
"""The operation succeeded."""
pass
class I18nTestCase(SupyTestCase):
@ -49,6 +49,8 @@ class I18nTestCase(SupyTestCase):
self.assertEqual(_(msg_en), msg_fr)
conf.supybot.language.setValue('en')
self.assertEqual(_(msg_en), msg_en)
multiline = '%s\n\n%s' % (msg_en, msg_en)
self.assertEqual(_(multiline), multiline)
def testDocstring(self):
self.assertEqual(foo.__doc__, msg_en)