From e87d370c2c4f5236cbbd5a55e49571fbd517bde7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 5 Sep 2017 13:10:34 +0200 Subject: Add bindings for QRegularExpression Task-number: PYSIDE-487 Change-Id: I5902ce37ad40b8180b6710b3e7cd091925ad392d Reviewed-by: Alexandru Croitor --- sources/pyside2/PySide2/QtCore/CMakeLists.txt | 3 ++ .../PySide2/QtCore/typesystem_core_common.xml | 9 ++++ sources/pyside2/tests/QtCore/CMakeLists.txt | 1 + .../tests/QtCore/qregularexpression_test.py | 56 ++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 sources/pyside2/tests/QtCore/qregularexpression_test.py (limited to 'sources') diff --git a/sources/pyside2/PySide2/QtCore/CMakeLists.txt b/sources/pyside2/PySide2/QtCore/CMakeLists.txt index 5e178cb70..384243f7c 100644 --- a/sources/pyside2/PySide2/QtCore/CMakeLists.txt +++ b/sources/pyside2/PySide2/QtCore/CMakeLists.txt @@ -97,6 +97,9 @@ ${QtCore_GEN_DIR}/qreadwritelock_wrapper.cpp ${QtCore_GEN_DIR}/qrect_wrapper.cpp ${QtCore_GEN_DIR}/qrectf_wrapper.cpp ${QtCore_GEN_DIR}/qregexp_wrapper.cpp +${QtCore_GEN_DIR}/qregularexpression_wrapper.cpp +${QtCore_GEN_DIR}/qregularexpressionmatch_wrapper.cpp +${QtCore_GEN_DIR}/qregularexpressionmatchiterator_wrapper.cpp ${QtCore_GEN_DIR}/qresource_wrapper.cpp ${QtCore_GEN_DIR}/qrunnable_wrapper.cpp ${QtCore_GEN_DIR}/qsavefile_wrapper.cpp diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index af6ca7700..bb0986f10 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -2467,6 +2467,15 @@ + + + + + + + + + diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt index 940bf523c..d3d31af18 100644 --- a/sources/pyside2/tests/QtCore/CMakeLists.txt +++ b/sources/pyside2/tests/QtCore/CMakeLists.txt @@ -85,6 +85,7 @@ PYSIDE_TEST(qprocess_test.py) PYSIDE_TEST(qproperty_decorator.py) PYSIDE_TEST(qrect_test.py) PYSIDE_TEST(qregexp_test.py) +PYSIDE_TEST(qregularexpression_test.py) PYSIDE_TEST(qresource_test.py) PYSIDE_TEST(qsize_test.py) PYSIDE_TEST(qslot_object_test.py) diff --git a/sources/pyside2/tests/QtCore/qregularexpression_test.py b/sources/pyside2/tests/QtCore/qregularexpression_test.py new file mode 100644 index 000000000..e11b9b61c --- /dev/null +++ b/sources/pyside2/tests/QtCore/qregularexpression_test.py @@ -0,0 +1,56 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Unit tests for QRegularExpression''' + +import unittest +from PySide2.QtCore import QRegularExpression, QRegularExpressionMatch, QRegularExpressionMatchIterator + +class QRegularExpressionTest(unittest.TestCase): + + def testMatch(self): + re = QRegularExpression('^.*(word2).*$') + self.assertTrue(re.isValid()) + match = re.match('word1 word2 word3') + self.assertTrue(match.isValid()) + self.assertEqual(match.captured(1), 'word2') + + def testMatchIterator(self): + re = QRegularExpression('(\w+)') + self.assertTrue(re.isValid()) + count = 0 + it = re.globalMatch('word1 word2 word3'); + while it.hasNext(): + it.next() + count = count + 1 + self.assertEqual(count, 3) + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3