File indexing completed on 2024-07-14 03:56:49

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2004 Arend van Beelen jr. <arend@auton.nl>
0004     SPDX-FileCopyrightText: 2010 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KFINDTEST_H
0010 #define KFINDTEST_H
0011 
0012 #include <QObject>
0013 #include <QStringList>
0014 #include <ktextwidgets_export.h>
0015 #include <memory>
0016 class KFind;
0017 class KFindRecorder : public QObject
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     explicit KFindRecorder(const QStringList &text);
0023 
0024     ~KFindRecorder() override;
0025     void find(const QString &pattern, long options = 0);
0026     bool findNext(const QString &pattern = QString());
0027 
0028     void changeText(int line, const QString &text);
0029 
0030     const QStringList &hits() const
0031     {
0032         return m_hits;
0033     }
0034     void clearHits()
0035     {
0036         m_hits.clear();
0037     }
0038 
0039 public Q_SLOTS:
0040     void slotHighlight(const QString &text, int index, int matchedLength);
0041     void slotHighlight(int id, int index, int matchedLengthlength);
0042 
0043 private:
0044     std::unique_ptr<KFind> m_find;
0045     QStringList m_text;
0046     int m_line;
0047     QStringList m_hits;
0048 };
0049 
0050 class TestKFind : public QObject
0051 {
0052     Q_OBJECT
0053 
0054 public:
0055     TestKFind();
0056 
0057 private Q_SLOTS:
0058 
0059     void testStaticFindRegexp_data();
0060     void testStaticFindRegexp();
0061 
0062     void testRegexpUnicode_data();
0063     void testRegexpUnicode();
0064 
0065     void testSimpleSearch();
0066     void testSimpleRegexp();
0067 
0068     void testLineBeginRegularExpression();
0069     void testFindIncremental();
0070     void testFindIncrementalDynamic();
0071 
0072 private:
0073     QString m_text;
0074 };
0075 
0076 #endif