@@ -128,21 +128,37 @@ filePathCompletionContextTests =
128
128
testGroup
129
129
" File Path Completion Context Tests"
130
130
[ testCase " empty line" $ do
131
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " " 0 3 )) @?= Just " "
132
- , testCase " simple filepath" $ do
133
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " src/" 0 7 )) @?= Just " "
131
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " " 0 3 )
132
+ completionSuffix complContext @?= Just " "
133
+ completionPrefix complContext @?= " "
134
+ , testCase " simple filepath" $ do
135
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " src/" 0 7 )
136
+ completionSuffix complContext @?= Just " "
137
+ completionPrefix complContext @?= " src/"
134
138
, testCase " simple filepath - starting apostrophe" $ do
135
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " \" src/" 0 7 )) @?= Just " \" "
139
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " \" src/" 0 8 )
140
+ completionSuffix complContext @?= Just " \" "
141
+ completionPrefix complContext @?= " src/"
136
142
, testCase " simple filepath - starting apostrophe, already closed" $ do
137
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " \" src/\" " 0 7 )) @?= Just " "
143
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " \" src/\" " 0 8 )
144
+ completionSuffix complContext @?= Just " "
145
+ completionPrefix complContext @?= " src/"
138
146
, testCase " second filepath - starting apostrophe" $ do
139
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " fp.txt \" src/" 0 12 )) @?= Just " \" "
147
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " fp.txt \" src/" 0 12 )
148
+ completionSuffix complContext @?= Just " \" "
149
+ completionPrefix complContext @?= " src/"
140
150
, testCase " middle filepath - starting apostrophe" $ do
141
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " fp.txt \" src/ fp2.txt" 0 12 )) @?= Just " \" "
151
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " fp.txt \" src/ fp2.txt" 0 12 )
152
+ completionSuffix complContext @?= Just " \" "
153
+ completionPrefix complContext @?= " src/"
142
154
, testCase " middle filepath - starting apostrophe, already closed" $ do
143
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " fp.t xt \" src\" fp2.txt" 0 12 )) @?= Just " "
155
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " fp.t xt \" src\" fp2.txt" 0 12 )
156
+ completionSuffix complContext @?= Just " "
157
+ completionPrefix complContext @?= " src"
144
158
, testCase " middle filepath - starting apostrophe, already closed" $ do
145
- (completionSuffix $ getFilePathCompletionContext " " (simplePosPrefixInfo " \" fp.txt\" \" src fp2.txt" 0 11 )) @?= Just " \" "
159
+ let complContext = getFilePathCompletionContext " " (simplePosPrefixInfo " \" fp.txt\" \" src fp2.txt" 0 13 )
160
+ completionSuffix complContext @?= Just " \" "
161
+ completionPrefix complContext @?= " src"
146
162
]
147
163
where
148
164
simplePosPrefixInfo :: T. Text -> UInt -> UInt -> VFS. PosPrefixInfo
@@ -155,9 +171,10 @@ filePathCompletionContextTests =
155
171
}
156
172
157
173
pathCompleterTests :: TestTree
158
- pathCompleterTests = testGroup " Path Completer Tests"
174
+ pathCompleterTests = testGroup " Path Completion Tests"
159
175
[ fileCompleterTests
160
176
, directoryCompleterTests
177
+ , pathCompletionInfoFromCompletionContextTests
161
178
, testGroup " Helper - List File Completion Tests"
162
179
[ testCase " Current Directory" $ do
163
180
testDir <- getTestDir
@@ -190,6 +207,37 @@ pathCompleterTests = testGroup "Path Completer Tests"
190
207
getTestDir = do
191
208
cwd <- getCurrentDirectory
192
209
pure $ cwd </> " test/testdata/filepath-completions/"
210
+ pathCompletionInfoFromCompletionContextTests :: TestTree
211
+ pathCompletionInfoFromCompletionContextTests = testGroup " Completion Info to Completion Context Tests"
212
+ [ testCase " Current Directory" $ do
213
+ testDir <- getTestDir
214
+ let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext " " testDir
215
+ prefixPathInfo complInfo @?= " ./" ,
216
+ testCase " Current Directory - partly written next" $ do
217
+ testDir <- getTestDir
218
+ let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext " di" testDir
219
+ prefixPathInfo complInfo @?= " ./"
220
+ prefixLeftOver complInfo @?= " di" ,
221
+ testCase " Current Directory - alternative writing" $ do
222
+ testDir <- getTestDir
223
+ let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext " ./" testDir
224
+ prefixPathInfo complInfo @?= " ./" ,
225
+ testCase " Subdirectory" $ do
226
+ testDir <- getTestDir
227
+ let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext " dir1/" testDir
228
+ prefixPathInfo complInfo @?= " dir1/"
229
+ prefixLeftOver complInfo @?= " " ,
230
+ testCase " Subdirectory - partly written next" $ do
231
+ testDir <- getTestDir
232
+ let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext " dir1/d" testDir
233
+ prefixPathInfo complInfo @?= " dir1/"
234
+ prefixLeftOver complInfo @?= " d" ,
235
+ testCase " Subdirectory - partly written next" $ do
236
+ testDir <- getTestDir
237
+ let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext " dir1/dir2/d" testDir
238
+ prefixPathInfo complInfo @?= " dir1/dir2/"
239
+ prefixLeftOver complInfo @?= " d"
240
+ ]
193
241
directoryCompleterTests :: TestTree
194
242
directoryCompleterTests = testGroup " Directory Completer Tests"
195
243
[ testCase " Current Directory" $ do
0 commit comments