@@ -47,9 +47,9 @@ final class FindTests: XCTestCase {
47
47
48
48
for index in 0 ..< fileURLs. count {
49
49
if index % 2 == 0 {
50
- try String ( " Loren Ipsum " ) . write ( to: fileURLs [ index] , atomically: true , encoding: . utf8)
50
+ try String ( " Loren Ipsum. " ) . write ( to: fileURLs [ index] , atomically: true , encoding: . utf8)
51
51
} else {
52
- try String ( " Aperiam asperiores " ) . write ( to: fileURLs [ index] , atomically: true , encoding: . utf8)
52
+ try String ( " Aperiam* asperiores " ) . write ( to: fileURLs [ index] , atomically: true , encoding: . utf8)
53
53
}
54
54
}
55
55
@@ -89,6 +89,52 @@ final class FindTests: XCTestCase {
89
89
try ? FileManager . default. removeItem ( at: directory)
90
90
}
91
91
92
+ func testGetSearchTerm( ) {
93
+ let query = " test*/Quer@#y "
94
+
95
+ searchState. selectedMode [ 2 ] = . Containing
96
+ XCTAssertEqual ( searchState. getSearchTerm ( query) , " *test*quer*y* " )
97
+
98
+ searchState. selectedMode [ 2 ] = . StartingWith
99
+ XCTAssertEqual ( searchState. getSearchTerm ( query) , " test*quer*y* " )
100
+
101
+ searchState. selectedMode [ 2 ] = . EndingWith
102
+ XCTAssertEqual ( searchState. getSearchTerm ( query) , " *test*quer*y " )
103
+
104
+ searchState. selectedMode [ 2 ] = . MatchingWord
105
+ XCTAssertEqual ( searchState. getSearchTerm ( query) , " test*quer*y " )
106
+
107
+ searchState. caseSensitive = true
108
+ XCTAssertEqual ( searchState. getSearchTerm ( query) , " test*Quer*y " )
109
+ }
110
+
111
+ func testStripSpecialCharacters( ) {
112
+ let string = " test!@#Query "
113
+ let strippedString = searchState. stripSpecialCharacters ( from: string)
114
+ XCTAssertEqual ( strippedString, " test*Query " )
115
+ }
116
+
117
+ func testGetRegexPattern( ) {
118
+ let query = " @(test. !*#Query "
119
+
120
+ searchState. selectedMode [ 2 ] = . Containing
121
+ XCTAssertEqual ( searchState. getRegexPattern ( query) , " @ \\ (test \\ . ! \\ *#Query " )
122
+
123
+ searchState. selectedMode [ 2 ] = . StartingWith
124
+ XCTAssertEqual ( searchState. getRegexPattern ( query) , " \\ b@ \\ (test \\ . ! \\ *#Query " )
125
+
126
+ searchState. selectedMode [ 2 ] = . EndingWith
127
+ XCTAssertEqual ( searchState. getRegexPattern ( query) , " @ \\ (test \\ . ! \\ *#Query \\ b " )
128
+
129
+ searchState. selectedMode [ 2 ] = . MatchingWord
130
+ XCTAssertEqual ( searchState. getRegexPattern ( query) , " \\ b@ \\ (test \\ . ! \\ *#Query \\ b " )
131
+
132
+ // Enabling case sensitivity shouldn't affect the regex pattern because if case sensitivity is enabled,
133
+ // `NSRegularExpression.Options.caseInsensitive` is passed to `NSRegularExpression`.
134
+ searchState. caseSensitive = true
135
+ XCTAssertEqual ( searchState. getRegexPattern ( query) , " \\ b@ \\ (test \\ . ! \\ *#Query \\ b " )
136
+ }
137
+
92
138
/// Tests the search functionality of the `WorkspaceDocument.SearchState` and `SearchIndexer`.
93
139
func testSearch( ) async {
94
140
let searchExpectation = XCTestExpectation ( description: " Search for 'Ipsum' " )
0 commit comments