diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-12-03 17:07:11 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:47:56 -0300 |
commit | edf5b58da83696ad908ac21b18bdd9a343d842ee (patch) | |
tree | 3ce899c72ff81b7958e463c4d96ae6f58d7835af /tests | |
parent | 1c6fad98417ad5be5a4748ac865ed81f52b5d9c5 (diff) |
Added QRegExp.replace(QString, const char*) method.
The only way to search and replace using QRegExp is using the
QString::replace method. Since QString was removed, QRegExp now is
useful only to search stuff, but not replace. For this purpose the
QRegExp.replace method was added. The first argument is the string
that will be operated over, the second argument contains the
replacement, and the return value is a new modified Python string.
Unit tests and documentation for QRegExp.replace were added as well.
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/QtCore/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/QtCore/qregexp_test.py | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt index b73a1ba24..40b83864d 100644 --- a/tests/QtCore/CMakeLists.txt +++ b/tests/QtCore/CMakeLists.txt @@ -49,6 +49,7 @@ PYSIDE_TEST(qobject_tr_as_instance_test.py) PYSIDE_TEST(qpoint_test.py) PYSIDE_TEST(qprocess_test.py) PYSIDE_TEST(qrect_test.py) +PYSIDE_TEST(qregexp_test.py) PYSIDE_TEST(qresource_test.py) PYSIDE_TEST(qsize_test.py) PYSIDE_TEST(qslot_object_test.py) diff --git a/tests/QtCore/qregexp_test.py b/tests/QtCore/qregexp_test.py new file mode 100644 index 000000000..54991854a --- /dev/null +++ b/tests/QtCore/qregexp_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/python + +import unittest +from PySide.QtCore import QRegExp + +class QRegExpTest(unittest.TestCase): + + def testReplace1(self): + re = QRegExp('a[mn]') + string = re.replace('Banana', 'ox') + self.assertEqual(string, 'Boxoxa') + + def testReplace2(self): + re = QRegExp('<i>([^<]*)</i>') + string = re.replace('A <i>bon mot</i>.', '\\emph{\\1}') + self.assertEqual(string, 'A \\emph{bon mot}.') + +if __name__ == '__main__': + unittest.main() + |