@@ -10,6 +10,7 @@ module Test.Hls.Util
10
10
(
11
11
codeActionSupportCaps
12
12
, expectCodeAction
13
+ , dontExpectCodeAction
13
14
, expectDiagnostic
14
15
, expectNoMoreDiagnostics
15
16
, expectSameLocations
@@ -45,6 +46,7 @@ import Control.Lens ((^.))
45
46
import Control.Monad
46
47
import Control.Monad.IO.Class
47
48
import qualified Data.Aeson as A
49
+ import Data.Bool (bool )
48
50
import Data.Default
49
51
import Data.List (intercalate )
50
52
import Data.List.Extra (find )
@@ -315,6 +317,10 @@ fromCommand _ = error "Not a command"
315
317
onMatch :: [a ] -> (a -> Bool ) -> String -> IO a
316
318
onMatch as predicate err = maybe (fail err) return (find predicate as)
317
319
320
+ noMatch :: [a ] -> (a -> Bool ) -> String -> IO ()
321
+ noMatch [] _ _ = pure ()
322
+ noMatch as predicate err = bool (pure () ) (fail err) (any predicate as)
323
+
318
324
inspectDiagnostic :: [Diagnostic ] -> [T. Text ] -> IO Diagnostic
319
325
inspectDiagnostic diags s = onMatch diags (\ ca -> all (`T.isInfixOf` (ca ^. L. message)) s) err
320
326
where err = " expected diagnostic matching '" ++ show s ++ " ' but did not find one"
@@ -331,6 +337,14 @@ inspectCodeAction cars s = fromAction <$> onMatch cars predicate err
331
337
expectCodeAction :: [Command |? CodeAction ] -> [T. Text ] -> IO ()
332
338
expectCodeAction cars s = void $ inspectCodeAction cars s
333
339
340
+ dontExpectCodeAction :: [Command |? CodeAction ] -> [T. Text ] -> IO ()
341
+ dontExpectCodeAction cars s =
342
+ noMatch cars predicate err
343
+ where predicate (InR ca) = all (`T.isInfixOf` (ca ^. L. title)) s
344
+ predicate _ = False
345
+ err = " expected code action matching '" ++ show s ++ " ' but did not find one"
346
+
347
+
334
348
inspectCommand :: [Command |? CodeAction ] -> [T. Text ] -> IO Command
335
349
inspectCommand cars s = fromCommand <$> onMatch cars predicate err
336
350
where predicate (InL command) = all (`T.isInfixOf` (command ^. L. title)) s
0 commit comments