@@ -139,180 +139,120 @@ final class FindTests: XCTestCase {
139139
140140 /// Tests the search functionality of the `WorkspaceDocument.SearchState` and `SearchIndexer`.
141141 func testSearch( ) async {
142- let searchExpectation = XCTestExpectation ( description: " Search for 'Ipsum' " )
143- let searchExpectation2 = XCTestExpectation ( description: " Search for 'asperiores' " )
144-
145- Task {
146- await searchState. search ( " Ipsum " )
147- searchExpectation. fulfill ( )
148- }
149-
142+ await searchState. search ( " Ipsum " )
150143 // Wait for the first search expectation to be fulfilled
151- await fulfillment ( of: [ searchExpectation] , timeout: 10 )
152- // Retrieve the search results after the first search
153- let searchResults = searchState. searchResult
154-
155- XCTAssertEqual ( searchResults. count, 2 )
156-
157- Task {
158- await searchState. search ( " asperiores " )
159- searchExpectation2. fulfill ( )
144+ await waitForExpectation {
145+ searchState. searchResult. count == 2
146+ } onTimeout: {
147+ XCTFail ( " Search state did not find two results. " )
160148 }
161149
162- await fulfillment ( of: [ searchExpectation2] , timeout: 10 )
163- let searchResults2 = searchState. searchResult
164-
165- XCTAssertEqual ( searchResults2. count, 1 )
150+ await searchState. search ( " asperiores " )
151+ await waitForExpectation {
152+ searchState. searchResult. count == 1
153+ } onTimeout: {
154+ XCTFail ( " Search state did not find correct results. " )
155+ }
166156 }
167157
168158 /// Checks if the search still returns proper results,
169159 /// if the search term isn't a complete word
170160 func testSearchWithOptionContaining( ) async {
171- let searchExpectation = XCTestExpectation ( description: " Search for 'psu' " )
172- let searchExpectation2 = XCTestExpectation ( description: " Search for 'erio' " )
173-
174- Task {
175- await searchState. search ( " psu " )
176- searchExpectation. fulfill ( )
161+ await searchState. search ( " psu " )
162+ await waitForExpectation {
163+ searchState. searchResult. count == 2
164+ } onTimeout: {
165+ XCTFail ( " Search state did not find two results. " )
177166 }
178167
179- await fulfillment ( of: [ searchExpectation] , timeout: 10 )
180-
181- let searchResults = searchState. searchResult
182-
183- XCTAssertEqual ( searchResults. count, 2 )
184-
185- Task {
186- await searchState. search ( " erio " )
187- searchExpectation2. fulfill ( )
168+ await searchState. search ( " erio " )
169+ await waitForExpectation {
170+ searchState. searchResult. count == 1
171+ } onTimeout: {
172+ XCTFail ( " Search state did not find correct results. " )
188173 }
189-
190- await fulfillment ( of: [ searchExpectation2] , timeout: 10 )
191- let searchResults2 = searchState. searchResult
192-
193- XCTAssertEqual ( searchResults2. count, 1 )
194174 }
195175
196176 /// This test verifies the accuracy of the word search feature.
197177 /// It first checks for the presence of 'Ipsum,' as done in previous tests.
198178 /// Following that, it examines the occurrence of the fragment 'perior,'
199179 /// which is not a complete word in any of the documents
200180 func testSearchWithOptionMatchingWord( ) async {
201- let searchExpectation = XCTestExpectation ( description: " Search for 'Ipsum' " )
202- let searchExpectation2 = XCTestExpectation ( description: " Search for 'perior' " )
203-
204181 // Set the search option to 'Matching Word'
205182 searchState. selectedMode [ 2 ] = . MatchingWord
206183
207- Task {
208- await searchState. search ( " Ipsum " )
209- searchExpectation. fulfill ( )
184+ await searchState. search ( " Ipsum " )
185+ await waitForExpectation {
186+ searchState. searchResult. count == 2
187+ } onTimeout: {
188+ XCTFail ( " Search state did not find correct results. " )
210189 }
211190
212- await fulfillment ( of: [ searchExpectation] , timeout: 10 )
213-
214- let searchResults = searchState. searchResult
215-
216- XCTAssertEqual ( searchResults. count, 2 )
217-
218191 // Check if incomplete words return no search results.
219- Task {
220- await searchState. search ( " perior " )
221- searchExpectation2. fulfill ( )
192+ await searchState. search ( " perior " )
193+ await waitForExpectation {
194+ searchState. searchResult. isEmpty
195+ } onTimeout: {
196+ XCTFail ( " Search state did not find correct results. " )
222197 }
223-
224- await fulfillment ( of: [ searchExpectation2] , timeout: 10 )
225- let searchResults2 = searchState. searchResult
226-
227- XCTAssertEqual ( searchResults2. count, 0 )
228198 }
229199
230200 func testSearchWithOptionStartingWith( ) async {
231- let searchExpectation = XCTestExpectation ( description: " Search for 'Ip' " )
232- let searchExpectation2 = XCTestExpectation ( description: " Search for 'res' " )
233-
234201 // Set the search option to 'Starting With'
235202 searchState. selectedMode [ 2 ] = . StartingWith
236203
237- Task {
238- await searchState. search ( " Ip " )
239- searchExpectation. fulfill ( )
204+ await searchState. search ( " Ip " )
205+ await waitForExpectation {
206+ searchState. searchResult. count == 2
207+ } onTimeout: {
208+ XCTFail ( " Search state did not find two results. " )
240209 }
241210
242- await fulfillment ( of: [ searchExpectation] , timeout: 10 )
243-
244- let searchResults = searchState. searchResult
245-
246- XCTAssertEqual ( searchResults. count, 2 )
247-
248- Task {
249- await searchState. search ( " res " )
250- searchExpectation2. fulfill ( )
211+ await searchState. search ( " res " )
212+ await waitForExpectation {
213+ searchState. searchResult. isEmpty
214+ } onTimeout: {
215+ XCTFail ( " Search state did not find two results. " )
251216 }
252-
253- await fulfillment ( of: [ searchExpectation2] , timeout: 10 )
254- let searchResults2 = searchState. searchResult
255-
256- XCTAssertEqual ( searchResults2. count, 0 )
257217 }
258218
259219 func testSearchWithOptionEndingWith( ) async {
260- let searchExpectation = XCTestExpectation ( description: " Search for 'um' " )
261- let searchExpectation2 = XCTestExpectation ( description: " Search for 'res' " )
262-
263220 // Set the search option to 'Ending with'
264221 searchState. selectedMode [ 2 ] = . EndingWith
265222
266- Task {
267- await searchState. search ( " um " )
268- searchExpectation. fulfill ( )
223+ await searchState. search ( " um " )
224+ await waitForExpectation {
225+ searchState. searchResult. count == 2
226+ } onTimeout: {
227+ XCTFail ( " Search state did not find two results. " )
269228 }
270229
271- await fulfillment ( of: [ searchExpectation] , timeout: 10 )
272-
273- let searchResults = searchState. searchResult
274-
275- XCTAssertEqual ( searchResults. count, 2 )
276-
277- Task {
278- await searchState. search ( " asperi " )
279- searchExpectation2. fulfill ( )
230+ await searchState. search ( " asperi " )
231+ await waitForExpectation {
232+ searchState. searchResult. isEmpty
233+ } onTimeout: {
234+ XCTFail ( " Search state did not find correct results. " )
280235 }
281-
282- await fulfillment ( of: [ searchExpectation2] , timeout: 10 )
283- let searchResults2 = searchState. searchResult
284-
285- XCTAssertEqual ( searchResults2. count, 0 )
286236 }
287237
288238 func testSearchWithOptionCaseSensitive( ) async {
289- let searchExpectation = XCTestExpectation ( description: " Search for 'Ipsum' " )
290- let searchExpectation2 = XCTestExpectation ( description: " Search for 'asperiores' " )
291-
292239 searchState. caseSensitive = true
293- Task {
294- await searchState. search ( " ipsum " )
295- searchExpectation. fulfill ( )
296- }
297-
240+ await searchState. search ( " ipsum " )
298241 // Wait for the first search expectation to be fulfilled
299- await fulfillment ( of: [ searchExpectation] , timeout: 10 )
300- // Retrieve the search results after the first search
301- let searchResults = searchState. searchResult
302-
303- // Expecting a result count of 0 due to the intentional use of a lowercase 'i'
304- XCTAssertEqual ( searchResults. count, 0 )
305-
306- Task {
307- await searchState. search ( " Asperiores " )
308- searchExpectation2. fulfill ( )
242+ await waitForExpectation {
243+ // Expecting a result count of 0 due to the intentional use of a lowercase 'i'
244+ searchState. searchResult. isEmpty
245+ } onTimeout: {
246+ XCTFail ( " Search state did not find correct results. " )
309247 }
310248
311- await fulfillment ( of: [ searchExpectation2] , timeout: 10 )
312- let searchResults2 = searchState. searchResult
313-
314- // Anticipating zero results since the search is case-sensitive and we used an uppercase 'A'
315- XCTAssertEqual ( searchResults2. count, 0 )
249+ await searchState. search ( " Asperiores " )
250+ await waitForExpectation {
251+ // Anticipating zero results since the search is case-sensitive and we used an uppercase 'A'
252+ searchState. searchResult. isEmpty
253+ } onTimeout: {
254+ XCTFail ( " Search state did not find correct results. " )
255+ }
316256 }
317257
318258 // Not implemented yet
0 commit comments