From 834b039a0df5e5e15af6b903d1f03e732182ab9f Mon Sep 17 00:00:00 2001 From: Jonathan Piacenti Date: Mon, 7 Apr 2014 11:12:59 -0500 Subject: [PATCH] Fixed issues with transformation functions on ANSIString. --- src/utils/ansi.py | 4 +++- src/utils/tests.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/ansi.py b/src/utils/ansi.py index 4126ea9b84..090cd37596 100644 --- a/src/utils/ansi.py +++ b/src/utils/ansi.py @@ -405,11 +405,13 @@ def _transform(func_name): def wrapped(self, *args, **kwargs): replacement_string = _query_super(func_name)(self, *args, **kwargs) to_string = [] + char_counter = 0 for index in range(0, len(self._raw_string)): if index in self._code_indexes: to_string.append(self._raw_string[index]) elif index in self._char_indexes: - to_string.append(replacement_string[index]) + to_string.append(replacement_string[char_counter]) + char_counter += 1 return ANSIString(''.join(to_string), decoded=True) return wrapped diff --git a/src/utils/tests.py b/src/utils/tests.py index 581e3f1972..9bb9c53de8 100644 --- a/src/utils/tests.py +++ b/src/utils/tests.py @@ -110,3 +110,12 @@ class ANSIStringTestCase(TestCase): ANSI codes. """ self.assertEqual(len(ANSIString('{gTest{n')), 4) + + def test_capitalize(self): + """ + Make sure that capitalization works. This is the simplest of the + _transform functions. + """ + target = ANSIString('{gtest{n') + result = u'\x1b[1m\x1b[32mTest\x1b[0m' + self.checker(target.capitalize(), result, u'Test') \ No newline at end of file