1515#include < QtTest/QtTest>
1616#include < QAbstractItemView>
1717#include < QCompleter>
18+ #include < QDialog>
1819#include < QSignalSpy>
19- #include < QStringListModel>
2020#include < QTextCursor>
2121
2222#include " pythoneditor.h"
@@ -47,8 +47,8 @@ static QStringList completionStrings(PythonEditor& e)
4747/* !*******************************************************************************************************************
4848 * \brief Verifies that user identifiers are added to the completer model while Python keywords stay available.
4949 *
50- * The test sets editor text containing variables and Python keywords, triggers variable extraction,
51- * and verifies that custom identifiers are present in the completion model.
50+ * The test sets editor text containing variables and Python keywords and verifies that
51+ * custom identifiers are present in the completion model.
5252 **********************************************************************************************************************/
5353void PythonEditorTest::updateVariableList_addsIdentifiersToCompleter ()
5454{
@@ -60,7 +60,7 @@ void PythonEditorTest::updateVariableList_addsIdentifiersToCompleter()
6060 " for i in range(3):\n "
6161 " gamma = i\n " );
6262
63- e. testUpdateVariableList ();
63+ QCoreApplication::processEvents ();
6464
6565 const QStringList items = completionStrings (e);
6666
@@ -108,6 +108,84 @@ void PythonEditorTest::findAndHighlight_plainTextFlow_works()
108108 " Current-line highlight shall remain after clearHighlights()" );
109109}
110110
111+ /* !*******************************************************************************************************************
112+ * \brief Verifies regex-based forward search.
113+ *
114+ * The test searches using a regular expression pattern and verifies that the
115+ * first matching token is selected.
116+ **********************************************************************************************************************/
117+ void PythonEditorTest::find_regex_flow_works ()
118+ {
119+ PythonEditor e;
120+
121+ e.setPlainText (" abc1 abc2 abc3" );
122+
123+ QTextCursor c = e.textCursor ();
124+ c.movePosition (QTextCursor::Start);
125+ e.setTextCursor (c);
126+
127+ e.findNext (" abc\\ d" , false , false , true );
128+
129+ QCOMPARE (e.textCursor ().selectedText (), QString (" abc1" ));
130+ }
131+
132+ /* !*******************************************************************************************************************
133+ * \brief Verifies wrap-around behavior for forward search.
134+ *
135+ * The test places the cursor at the end of the document and searches forward
136+ * for a token that exists only earlier in the text. The search shall wrap and find it.
137+ **********************************************************************************************************************/
138+ void PythonEditorTest::find_wrapAround_works ()
139+ {
140+ PythonEditor e;
141+
142+ e.setPlainText (" first second third" );
143+
144+ QTextCursor c = e.textCursor ();
145+ c.movePosition (QTextCursor::End);
146+ e.setTextCursor (c);
147+
148+ e.findNext (" first" , false , false , false );
149+
150+ QCOMPARE (e.textCursor ().selectedText (), QString (" first" ));
151+ }
152+
153+ /* !*******************************************************************************************************************
154+ * \brief Verifies regex-based highlight of all matches.
155+ *
156+ * The test applies highlighting with a regular expression and checks that
157+ * extra selections are produced for matches.
158+ **********************************************************************************************************************/
159+ void PythonEditorTest::highlight_regex_works ()
160+ {
161+ PythonEditor e;
162+
163+ e.setPlainText (" a1 a2 a3" );
164+
165+ e.highlightAll (" a\\ d" , false , false , true );
166+
167+ QVERIFY2 (e.extraSelections ().size () > 1 , " Regex highlight shall produce match selections" );
168+ }
169+
170+ /* !*******************************************************************************************************************
171+ * \brief Verifies that the find dialog is created and shown on demand.
172+ *
173+ * The test invokes openFindDialog() and verifies that a dialog child exists.
174+ **********************************************************************************************************************/
175+ void PythonEditorTest::openFindDialog_createsDialog ()
176+ {
177+ PythonEditor e;
178+
179+ #ifdef EMSTUDIO_TESTING
180+ e.testOpenFindDialog ();
181+ #else
182+ e.openFindDialog ();
183+ #endif
184+
185+ const auto dialogs = e.findChildren <QDialog*>();
186+ QVERIFY2 (!dialogs.isEmpty (), " Find dialog was not created" );
187+ }
188+
111189/* !*******************************************************************************************************************
112190 * \brief Verifies zoom helpers and direct font-size setter.
113191 *
@@ -121,13 +199,19 @@ void PythonEditorTest::zoomAndFontSize_updateEditorFont_and_emitSignal()
121199
122200 QSignalSpy spy (&e, SIGNAL (sigFontSizeChanged (qreal)));
123201
202+ #ifdef EMSTUDIO_TESTING
124203 e.testZoomInText ();
204+ #else
205+ QSKIP (" zoom test wrappers are available only in EMSTUDIO_TESTING builds" );
206+ #endif
125207 QVERIFY2 (e.font ().pointSizeF () > initial, " zoomInText() shall increase font size" );
126208 QVERIFY2 (spy.count () == 1 , " zoomInText() shall emit sigFontSizeChanged" );
127209
128210 const qreal afterZoomIn = e.font ().pointSizeF ();
129211
212+ #ifdef EMSTUDIO_TESTING
130213 e.testZoomOutText ();
214+ #endif
131215 QVERIFY2 (e.font ().pointSizeF () < afterZoomIn, " zoomOutText() shall decrease font size" );
132216 QVERIFY2 (spy.count () == 2 , " zoomOutText() shall emit sigFontSizeChanged" );
133217
0 commit comments