@@ -4,6 +4,7 @@ module Completion(tests) where
44
55import Control.Lens hiding ((.=) )
66import Data.Aeson (object , (.=) )
7+ import Data.Foldable (find )
78import qualified Data.Text as T
89import Ide.Plugin.Config (maxCompletions )
910import Language.LSP.Types.Lens hiding (applyEdit )
@@ -19,7 +20,7 @@ tests = testGroup "completions" [
1920 _ <- applyEdit doc te
2021
2122 compls <- getCompletions doc (Position 5 9 )
22- let item = head $ filter (( == " putStrLn" ) . ( ^. label)) compls
23+ item <- getCompletionByLabel " putStrLn" compls
2324 liftIO $ do
2425 item ^. label @?= " putStrLn"
2526 item ^. kind @?= Just CiFunction
@@ -35,7 +36,7 @@ tests = testGroup "completions" [
3536 _ <- applyEdit doc te
3637
3738 compls <- getCompletions doc (Position 5 9 )
38- let item = head $ filter (( == " putStrLn" ) . ( ^. label)) compls
39+ item <- getCompletionByLabel " putStrLn" compls
3940 resolvedRes <- request SCompletionItemResolve item
4041 let eResolved = resolvedRes ^. result
4142 case eResolved of
@@ -56,7 +57,7 @@ tests = testGroup "completions" [
5657 _ <- applyEdit doc te
5758
5859 compls <- getCompletions doc (Position 1 23 )
59- let item = head $ filter (( == " Maybe" ) . ( ^. label)) compls
60+ item <- getCompletionByLabel " Maybe" compls
6061 liftIO $ do
6162 item ^. label @?= " Maybe"
6263 item ^. detail @?= Just " Data.Maybe"
@@ -71,7 +72,7 @@ tests = testGroup "completions" [
7172 _ <- applyEdit doc te
7273
7374 compls <- getCompletions doc (Position 2 24 )
74- let item = head $ filter (( == " List" ) . ( ^. label)) compls
75+ item <- getCompletionByLabel " List" compls
7576 liftIO $ do
7677 item ^. label @?= " List"
7778 item ^. detail @?= Just " Data.List"
@@ -91,7 +92,7 @@ tests = testGroup "completions" [
9192 _ <- applyEdit doc te
9293
9394 compls <- getCompletions doc (Position 5 4 )
94- let item = head $ filter ( \ c -> c ^. label == " accessor" ) compls
95+ item <- getCompletionByLabel " accessor" compls
9596 liftIO $ do
9697 item ^. label @?= " accessor"
9798 item ^. kind @?= Just CiFunction
@@ -101,7 +102,7 @@ tests = testGroup "completions" [
101102 let te = TextEdit (Range (Position 5 7 ) (Position 5 9 )) " id"
102103 _ <- applyEdit doc te
103104 compls <- getCompletions doc (Position 5 9 )
104- let item = head $ filter (( == " id" ) . ( ^. label)) compls
105+ item <- getCompletionByLabel " id" compls
105106 liftIO $ do
106107 item ^. detail @?= Just " :: a -> a"
107108
@@ -111,7 +112,7 @@ tests = testGroup "completions" [
111112 let te = TextEdit (Range (Position 5 7 ) (Position 5 24 )) " flip"
112113 _ <- applyEdit doc te
113114 compls <- getCompletions doc (Position 5 11 )
114- let item = head $ filter (( == " flip" ) . ( ^. label)) compls
115+ item <- getCompletionByLabel " flip" compls
115116 liftIO $
116117 item ^. detail @?= Just " :: (a -> b -> c) -> b -> a -> c"
117118
@@ -128,7 +129,7 @@ tests = testGroup "completions" [
128129 _ <- applyEdit doc te
129130
130131 compls <- getCompletions doc (Position 0 31 )
131- let item = head $ filter (( == " Alternative" ) . ( ^. label)) compls
132+ item <- getCompletionByLabel " Alternative" compls
132133 liftIO $ do
133134 item ^. label @?= " Alternative"
134135 item ^. kind @?= Just CiFunction
@@ -141,7 +142,7 @@ tests = testGroup "completions" [
141142 _ <- applyEdit doc te
142143
143144 compls <- getCompletions doc (Position 0 41 )
144- let item = head $ filter (( == " liftA" ) . ( ^. label)) compls
145+ item <- getCompletionByLabel " liftA" compls
145146 liftIO $ do
146147 item ^. label @?= " liftA"
147148 item ^. kind @?= Just CiFunction
@@ -159,7 +160,7 @@ snippetTests = testGroup "snippets" [
159160 _ <- applyEdit doc te
160161
161162 compls <- getCompletions doc (Position 5 14 )
162- let item = head $ filter (( == " Nothing" ) . ( ^. label)) compls
163+ item <- getCompletionByLabel " Nothing" compls
163164 liftIO $ do
164165 item ^. insertTextFormat @?= Just Snippet
165166 item ^. insertText @?= Just " Nothing "
@@ -171,7 +172,7 @@ snippetTests = testGroup "snippets" [
171172 _ <- applyEdit doc te
172173
173174 compls <- getCompletions doc (Position 5 11 )
174- let item = head $ filter (( == " foldl" ) . ( ^. label)) compls
175+ item <- getCompletionByLabel " foldl" compls
175176 liftIO $ do
176177 item ^. label @?= " foldl"
177178 item ^. kind @?= Just CiFunction
@@ -185,7 +186,7 @@ snippetTests = testGroup "snippets" [
185186 _ <- applyEdit doc te
186187
187188 compls <- getCompletions doc (Position 5 11 )
188- let item = head $ filter (( == " mapM" ) . ( ^. label)) compls
189+ item <- getCompletionByLabel " mapM" compls
189190 liftIO $ do
190191 item ^. label @?= " mapM"
191192 item ^. kind @?= Just CiFunction
@@ -199,7 +200,7 @@ snippetTests = testGroup "snippets" [
199200 _ <- applyEdit doc te
200201
201202 compls <- getCompletions doc (Position 5 18 )
202- let item = head $ filter (( == " filter" ) . ( ^. label)) compls
203+ item <- getCompletionByLabel " filter" compls
203204 liftIO $ do
204205 item ^. label @?= " filter"
205206 item ^. kind @?= Just CiFunction
@@ -213,7 +214,7 @@ snippetTests = testGroup "snippets" [
213214 _ <- applyEdit doc te
214215
215216 compls <- getCompletions doc (Position 5 18 )
216- let item = head $ filter (( == " filter" ) . ( ^. label)) compls
217+ item <- getCompletionByLabel " filter" compls
217218 liftIO $ do
218219 item ^. label @?= " filter"
219220 item ^. kind @?= Just CiFunction
@@ -227,7 +228,7 @@ snippetTests = testGroup "snippets" [
227228 _ <- applyEdit doc te
228229
229230 compls <- getCompletions doc (Position 5 29 )
230- let item = head $ filter (( == " intersperse" ) . ( ^. label)) compls
231+ item <- getCompletionByLabel " intersperse" compls
231232 liftIO $ do
232233 item ^. label @?= " intersperse"
233234 item ^. kind @?= Just CiFunction
@@ -241,7 +242,7 @@ snippetTests = testGroup "snippets" [
241242 _ <- applyEdit doc te
242243
243244 compls <- getCompletions doc (Position 5 29 )
244- let item = head $ filter (( == " intersperse" ) . ( ^. label)) compls
245+ item <- getCompletionByLabel " intersperse" compls
245246 liftIO $ do
246247 item ^. label @?= " intersperse"
247248 item ^. kind @?= Just CiFunction
@@ -268,7 +269,9 @@ snippetTests = testGroup "snippets" [
268269 _ <- applyEdit doc te
269270
270271 compls <- getCompletions doc (Position 1 6 )
271- let item = head $ filter (\ c -> (c ^. label == " MkFoo" ) && maybe False (" MkFoo {" `T.isPrefixOf` ) (c ^. insertText)) compls
272+ item <- case find (\ c -> (c ^. label == " MkFoo" ) && maybe False (" MkFoo {" `T.isPrefixOf` ) (c ^. insertText)) compls of
273+ Just c -> pure c
274+ Nothing -> liftIO . assertFailure $ " Completion with label 'MkFoo' and insertText starting with 'MkFoo {' not found among " <> show compls
272275 liftIO $ do
273276 item ^. insertTextFormat @?= Just Snippet
274277 item ^. insertText @?= Just " MkFoo {arg1=${1:_arg1}, arg2=${2:_arg2}, arg3=${3:_arg3}, arg4=${4:_arg4}, arg5=${5:_arg5}}"
@@ -279,7 +282,7 @@ snippetTests = testGroup "snippets" [
279282 _ <- applyEdit doc te
280283
281284 compls <- getCompletions doc (Position 5 11 )
282- let item = head $ filter (( == " foldl" ) . ( ^. label)) compls
285+ item <- getCompletionByLabel " foldl" compls
283286 liftIO $ do
284287 item ^. label @?= " foldl"
285288 item ^. kind @?= Just CiFunction
@@ -327,11 +330,11 @@ contextTests = testGroup "contexts" [
327330 ]
328331
329332shouldContainCompl :: [CompletionItem ] -> T. Text -> Assertion
330- compls `shouldContainCompl` x =
331- any ((== x ) . (^. label)) compls
332- @? " Should contain completion: " ++ show x
333+ compls `shouldContainCompl` lbl =
334+ any ((== lbl ) . (^. label)) compls
335+ @? " Should contain completion: " ++ show lbl
333336
334337shouldNotContainCompl :: [CompletionItem ] -> T. Text -> Assertion
335- compls `shouldNotContainCompl` x =
336- all ((/= x ) . (^. label)) compls
337- @? " Should not contain completion: " ++ show x
338+ compls `shouldNotContainCompl` lbl =
339+ all ((/= lbl ) . (^. label)) compls
340+ @? " Should not contain completion: " ++ show lbl
0 commit comments