Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 203846a

Browse files
committed
Add tests for infix completions
1 parent 3c8f462 commit 203846a

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

test/functional/CompletionSpec.hs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,67 @@ spec = describe "completions" $ do
250250
item ^. insertTextFormat `shouldBe` Just Snippet
251251
item ^. insertText `shouldBe` Just "mapM ${1:a -> m b} ${2:t a}"
252252

253+
it "work for infix functions" $ runSession hieCommand fullCaps "test/testdata/completion" $ do
254+
doc <- openDoc "Completion.hs" "haskell"
255+
_ <- skipManyTill loggingNotification (count 2 noDiagnostics)
256+
257+
let te = TextEdit (Range (Position 5 7) (Position 5 24)) "even `filte"
258+
_ <- applyEdit doc te
259+
260+
compls <- getCompletions doc (Position 5 17)
261+
let item = head $ filter ((== "filter") . (^. label)) compls
262+
liftIO $ do
263+
item ^. label `shouldBe` "filter"
264+
item ^. kind `shouldBe` Just CiFunction
265+
item ^. insertTextFormat `shouldBe` Just Snippet
266+
item ^. insertText `shouldBe` Just "`filter`"
267+
268+
it "work for infix functions in backticks" $ runSession hieCommand fullCaps "test/testdata/completion" $ do
269+
doc <- openDoc "Completion.hs" "haskell"
270+
_ <- skipManyTill loggingNotification (count 2 noDiagnostics)
271+
272+
let te = TextEdit (Range (Position 5 7) (Position 5 24)) "even `filte`"
273+
_ <- applyEdit doc te
274+
275+
compls <- getCompletions doc (Position 5 17)
276+
let item = head $ filter ((== "filter") . (^. label)) compls
277+
liftIO $ do
278+
item ^. label `shouldBe` "filter"
279+
item ^. kind `shouldBe` Just CiFunction
280+
item ^. insertTextFormat `shouldBe` Just Snippet
281+
item ^. insertText `shouldBe` Just "`filter`"
282+
283+
it "work for qualified infix functions" $ runSession hieCommand fullCaps "test/testdata/completion" $ do
284+
doc <- openDoc "Completion.hs" "haskell"
285+
_ <- skipManyTill loggingNotification (count 2 noDiagnostics)
286+
287+
let te = TextEdit (Range (Position 5 7) (Position 5 24)) "\"\" `Data.List.interspe"
288+
_ <- applyEdit doc te
289+
290+
compls <- getCompletions doc (Position 5 34)
291+
let item = head $ filter ((== "intersperse") . (^. label)) compls
292+
liftIO $ do
293+
item ^. label `shouldBe` "intersperse"
294+
item ^. kind `shouldBe` Just CiFunction
295+
item ^. insertTextFormat `shouldBe` Just Snippet
296+
item ^. insertText `shouldBe` Just "`Data.List.intersperse`"
297+
298+
it "work for qualified infix functions in backticks" $ runSession hieCommand fullCaps "test/testdata/completion" $ do
299+
doc <- openDoc "Completion.hs" "haskell"
300+
_ <- skipManyTill loggingNotification (count 2 noDiagnostics)
301+
302+
let te = TextEdit (Range (Position 5 7) (Position 5 24)) "\"\" `Data.List.interspe`"
303+
_ <- applyEdit doc te
304+
305+
306+
compls <- getCompletions doc (Position 5 34)
307+
let item = head $ filter ((== "intersperse") . (^. label)) compls
308+
liftIO $ do
309+
item ^. label `shouldBe` "intersperse"
310+
item ^. kind `shouldBe` Just CiFunction
311+
item ^. insertTextFormat `shouldBe` Just Snippet
312+
item ^. insertText `shouldBe` Just "`Data.List.intersperse`"
313+
253314
it "respects lsp configuration" $ runSession hieCommand fullCaps "test/testdata/completion" $ do
254315
doc <- openDoc "Completion.hs" "haskell"
255316
_ <- skipManyTill loggingNotification (count 2 noDiagnostics)

test/testdata/completion/Completion.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ import qualified Data.List
44

55
main :: IO ()
66
main = putStrLn "hello"
7+
8+
foo :: Either a b -> Either a b
9+
foo = id

0 commit comments

Comments
 (0)