summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QRegularExpression: use modernize comparisonsTatiana Borisova3 days1-24/+16
| | | | | | | | | | | | | Replace class operators operator==(), operator!=() of QRegularExpression to friend method comparesEqual() and Q_DECLARE_EQUALITY_COMPARABLE macro. Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current comparison methods and replace them with a friend. Task-number: QTBUG-120304 Change-Id: Ib6fc83d29ad9bc710c2fdf32a3d60131fbf298b6 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QRegularExpressionMatch: port API from QString to QAnyStringView keysMatthias Rauter10 days1-0/+2
| | | | | | | | | | | | | | The QRegularExpression capture-by-name keys are currently QStringViews, but are only ever used to compare them against a const char16_t*, so this API is a perfect candidate for replacing all of these overload sets with a single QAnyStringView function. [ChangeLog][QtCore][QRegularExpression] Keys can now be passed as QAnyStringView (was QStringView). Fixes: QTBUG-103097 Change-Id: I1a80e85f301cc08370d70b3b5eb0ae10c6a51f33 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* Skip the tst_QRegularExpression::threadSafety test on WASM temporarilyMikolaj Boc2023-06-261-0/+4
| | | | | | | | | The test needs investigation. Skip it for now so that we can enable CI for WASM but leave a note to investigate it. Task-number: QTBUG-109954 Change-Id: I445996e969e7016a4d92a7e70da10b6d84a0fc71 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* QRegularExpression: match newlines when converting wildcardsGiuseppe D'Angelo2023-05-231-0/+4
| | | | | | | | | | | | | | | | | | A * or a ? in a wildcard pattern is allowed to match any character, including newlines. When converting a wildcard pattern to a PCRE, * and ? were converted to ., which by default does _not_ match over newlines (/s is necessary). There isn't a metacharacter that matches everything, so either we modify the returned pattern to enable dot-matches-all (for instance, by wrapping the returned expression in (?s:...)), or use a character class that includes everything. Picking this last approach for simplicity. Change-Id: I86703f654e3414783427c4c8e0bb018885b42e54 Fixes: QTBUG-113676 Pick-to: 6.5 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: extend wildcard testsGiuseppe D'Angelo2023-03-091-5/+17
| | | | | | | Test for non-anchored wildcards too. Change-Id: I98cb47d76861d145bc409112981f52e246beb0a7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: add support for non-filepath wildcards/globbingGiuseppe D'Angelo2023-03-071-48/+67
| | | | | | | | | | | | | | | | | | | | | | | | A glob pattern has different semantics depending on whether it's used in "filepath mode" (FNM_PATHNAME) or not. QRegularExpression only implemented the former, but the latter is also useful, and possibly more "intuitive" for certain use cases (e.g. offering users a simplified version of regexps that however still need "*" to match a "/"). Add this support. The problems highlighted by QTBUG-111234 have not been addressed, I've just amended a bit of documentation relating backslashes. [ChangeLog][QtCore][QRegularExpression] Support for non-filepath wildcards has been added to wildcardToRegularExpression(). Fixes: QTBUG-110901 Task-number: QTBUG-104585 Task-number: QTBUG-111234 Change-Id: If9850616267980fa843bda996fcb4552b5375938 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* tst_QRE::wildcard(): use more informative data row tagsEdward Welbourne2022-10-111-2/+1
| | | | | | | | | | Using simply the pattern didn't work so well when some patters are used repeatedly, on different haystacks. So include the haystack in the tag name. Remove one straight up duplicate row. Change-Id: Ib46364581f23c493e83d75e6d04ab09e4329a3a5 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
* QRegularExpression: introduce (global)matchViewGiuseppe D'Angelo2022-07-291-16/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QRegularExpression::match (and globalMatch) is currently overloaded for QString and QStringView. This creates a subtle API asymmetry: QRegularExpression re; auto m1 = re.match(getQString()); // OK auto m2 = re.match(getStdU16String()); // Dangling This goes against our decision that every time that there's a possible lifetime issue at play, it should be "evident". Solving the lifetime issue here is possible, but tricky -- since QRegularExpression is out-of-line, one needs a type-erased container for the input string (basically, std::any) to keep it alive and so on. Instead I went for the simpler solution: deprecate match(QStringView) and introduce matchView(QStringView) (same for globalMatch). This makes it clear that the call is matching over a view and therefore users are supposed to keep the source object alive. Drive-by, remove the documentation that says that the QString overloads might not keep the string alive: they do and forever will. [ChangeLog][QtCore][QRegularExpression] Added the matchView() and globalMatchView() functions that operate on string views. The match(QStringView) and globalMatch(QStringView) overloads have been deprecated. Change-Id: I054b8605c2fdea59b556dcfea8920ef4eee78ee9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-28/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QRegularExpression: print the pattern when warningGiuseppe D'Angelo2022-02-221-2/+7
| | | | | | | | | | Just as a minor debugging helper: when warning that an invalid regular expression object is being used to match, also print the used regular expression pattern. Change-Id: I0f99bcf4ca87ec67d04ed91d9dc315814f56d392 Fixes: QTBUG-76670 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Check that QStringView::split() w/rvalue QRegularExpression returns valid dataMarc Mutz2021-11-291-0/+29
| | | | | | | | | | | This test currently passes in Qt 6, but fails in Qt 5.15, thus the QT_VERSION check. Pick-to: 6.2 5.15 Task-number: QTBUG-98653 Change-Id: I3c7b9bc7ef74f605ff63768b38c473296274d0de Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Always enable QRegularExpression's JIT when testingGiuseppe D'Angelo2021-10-061-0/+14
| | | | | | | | | | | | | | | | | | | | Given on most CI configurations we run tests only on debug builds, this means that effectively we don't test JIT paths (JIT is kept disabled in debug builds). To keep it enabled in a test, we have a few options: * export a developer-build-only variable from QtCore, to force JIT usage, and set it in the test. This is still suboptimal as many configurations aren't using developer builds in the first place; * use the already existing QT_REGEXP_USE_JIT environment variable, setting it from CMake/CTest. The problem here is that although add_test does support it, we don't expose it through our wrapper functions; * just set that env variable from within the test itself. I went for this option. Change-Id: I73abfb7fc0d76ec77e881f24c5daf5be304ab948 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpressionMatch: add a way to know if a capturing group capturedGiuseppe D'Angelo2021-08-251-79/+159
| | | | | | | | | | | | | | | | | | | | | | | Relying on the fact that a given capturing group captured a null string doesn't allow users to distinguish whether a capturing group did not capture anything, or captured a null substring (say, from a null subject string). Perl allows for the distinction: the entries in the @- and @+ arrays are set to values in case there is a capture, but they're undef otherwise. PCRE2 gives us the information already in the results "ovector", but it was simply not exposed to QREM users. So, expose it. [ChangeLog][QtCore][QRegularExpressionMatch] Added the hasCaptured() family of functions to know if a given capturing group has captured something. Change-Id: Ic1320933d4554e2e313c0a680be1b1b9dd95af0b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QRegularExpression: fix matching over null/empty QString(View)Giuseppe D'Angelo2021-08-191-2/+23
| | | | | | | | | | | | | | | | | | | | | | | An empty QString(View) is allowed to have nullptr as its data pointer (of course, only if its size is 0). This wasn't properly checked in QRegularExpression, which passed such nullptr to PCRE, and that resulted in PCRE raising an error (PCRE_ERROR_NULL). Detect this case and pass a dummy pointer to keep PCRE happy. Fixing and testing this in turn exposed a problem with QStringView support in QRegularExpression when used over a null QString: the code is supposed to use the QStringView(QString) constructor and NOT qToStringViewIgnoringNull. That's because QRE distinguishes null and empty subjects; when using qToStringViewIgnoringNull over a null QString, one gets a non-null QStringView (!). Again, this in turn exposed a problem with a QRegularExpression autotest that assumed that a null match could only mean "no match" (instead, it can happen at position 0 of a null QString(View)). Change-Id: Ifb3cf14dec42ce76fcdbcb07ea1d80784d52ef65 Pick-to: 6.1 6.2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QRegularExpression: add move constructorIvan Solovev2021-01-261-0/+115
| | | | | | | | | | | | - Add move constructors to QRegularExpression, QRegularExpressionMatch and QRegularExpressionMatchIterator. - Update the documentation to explicitly state that only destructor and assignment operators can be called for a moved-from object Task-number: QTBUG-86634 Change-Id: I06b4f54e300541033a9a18339c97338717a06da0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Replace QtTest headers with QTestDavid Skoland2020-12-221-1/+1
| | | | | | | | | | | Complete search and replace of QtTest and QtTest/QtTest with QTest, as QtTest includes the whole module. Replace all such instances with correct header includes. See Jira task for more discussion. Fixes: QTBUG-88831 Change-Id: I981cfae18a1cabcabcabee376016b086d9d01f44 Pick-to: 6.0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix compiler warning from discarded return valueVolker Hilsheimer2020-12-041-1/+1
| | | | | | | | Amend 53b7cb1bd73c773521f85c48ecd0c9daed14f7b3, match() is only used to provoke data races. Change-Id: Id20b11fedf7f20e74baab15bbb60c995c1a0c794 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace discouraged Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPEAndreas Buhr2020-11-301-1/+1
| | | | | | | | | | | | | | Q_MOVABLE_TYPE was conceived before C++ had move semantics. Now, with move semantics, its name is misleading. Q_RELOCATABLE_TYPE was introduced as a synonym to Q_MOVABLE_TYPE. Usage of Q_MOVABLE_TYPE is discouraged now. This patch replaces all usages of Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPE in QtBase. As the two are synonymous, this patch should have no impact on users. Pick-to: 6.0 Change-Id: Ie653984363198c1aeb1f70f8e0fa189aae38eb5c Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* QREMatchIterator: add support for range-based forGiuseppe D'Angelo2020-09-301-0/+21
| | | | | | | | | | | | | Add begin()/end() on QRegularExpressionMatchIterator, making iterators over an iterator (like directory_iterator). [ChangeLog][QtCore][QRegularExpression] The iterator object (QRegularExpressionMatchIterator) returned by a global match is now usable in a range-based for loop. Change-Id: If3d31bd2e84e7d1fb626a0b3d2745914dff03e39 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use qsizetype in QRegularExpressionMarcel Krems2020-08-281-76/+76
| | | | | | | PCRE2 already uses size_t which we can now make full use of. Change-Id: Icb5efd5c6ef27f2e31a9780bf62f5671ddc603cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: do not assume QStringViews are NUL terminatedGiuseppe D'Angelo2020-08-251-0/+31
| | | | | | | | | | | The convenience API used to look up the index of a named capturing group expects NUL terminated strings. Therefore, we can't just use it together with QStringViews, which may be not. Use the non-convenience API instead. Pick-to: 5.15 Change-Id: I25ca14de49b13ee1764525f8b19f2550c30c1afa Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QStringRef and remains to Qt5CompatKarsten Heimrich2020-08-201-15/+15
| | | | | | | | | Export some private functions from QUtf8 to resolve undefined symbols in Qt5Compat after moving QStringRef. Task-number: QTBUG-84437 Change-Id: I9046dcb14ed520d8868a511d79da6e721e26f72b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use QList instead of QVector in corelib testsJarek Kobus2020-07-071-8/+8
| | | | | | Task-number: QTBUG-84469 Change-Id: Ic80fde5517aed363f17d0da55cadcc958c3c8895 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Remove winrtOliver Wolff2020-06-061-4/+0
| | | | | | | | | Macros and the await helper function from qfunctions_winrt(_p).h are needed in other Qt modules which use UWP APIs on desktop windows. Task-number: QTBUG-84434 Change-Id: Ice09c11436ad151c17bdccd2c7defadd08c13925 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Port QRegularExpression to QStringView, drop QStringRefGiuseppe D'Angelo2020-05-311-10/+7
| | | | | | | | | | | | | | | | | | | | | | The idea is pretty simple -- add QRegularExpression matching over QStringView. When matching over a QString, keep the string alive (by taking a copy), and set the view onto that string. Otherwise, just use the view provided by the user (who is then responsible for ensuring the data stays valid while matching). Do just minor refactorings to support this use case in a cleaner fashion. In QRegularExpressionMatch drop the QStringRef-returning methods, as they cannot work any more -- in the general case there won't be a QString to build a QStringRef from. [ChangeLog][QtCore][QRegularExpression] All the APIs dealing with QStringRef have been ported to QStringView, following QStringRef deprecation in Qt 6.0. Change-Id: Ic367991d9583cc108c045e4387c9b7288c8f1ffd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QRegularExpression: rename AnchoredMatchOption to AnchorAtOffsetMatchOptionGiuseppe D'Angelo2020-04-031-2/+2
| | | | | | | | | | | | | | | | | | The name of the option may cause confusion due to the fact that it's not _fully_ anchoring the match, only anchoring it at the offset passed to match() -- in other words, it's a "left" anchoring. Deprecate the old name and introduce a new one that should explain the situation better. [ChangeLog][QtCore][QRegularExpression] The AnchoredMatchOption match option has been deprecated in favor of AnchorAtOffsetMatchOption, which should better describe that the match is only anchored at the offset. Change-Id: Ib751e5e488f2d0309a2da6496378247dfa4648de Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* Avoid initializing QFlags with 0 or nullptr in testsFriedemann Kleint2019-11-261-6/+6
| | | | | | | Amends qtbase/af2daafde72db02454d24b7d691aa6861525ab99. Change-Id: Ib5d17611e43e7ab2c63c7f0587f549377f262e32 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Move text-related code out of corelib/tools/ to corelib/text/Edward Welbourne2019-07-101-0/+2254
This includes byte array, string, char, unicode, locale, collation and regular expressions. Change-Id: I8b125fa52c8c513eb57a0f1298b91910e5a0d786 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>