@@ -33,6 +33,7 @@ import Data.Maybe (fromJust)
3333import qualified Data.Text as T
3434import Development.IDE.Plugin.Test (TestRequest (.. ),
3535 WaitForIdeRuleResult )
36+ import Development.IDE.Test.Diagnostic
3637import Language.LSP.Test hiding (message )
3738import qualified Language.LSP.Test as LspTest
3839import Language.LSP.Types
@@ -41,31 +42,14 @@ import System.Directory (canonicalizePath)
4142import System.Time.Extra
4243import Test.Tasty.HUnit
4344
44- -- | (0-based line number, 0-based column number)
45- type Cursor = (Int , Int )
46-
47- cursorPosition :: Cursor -> Position
48- cursorPosition (line, col) = Position line col
49-
50- requireDiagnostic :: HasCallStack => List Diagnostic -> (DiagnosticSeverity , Cursor , T. Text , Maybe DiagnosticTag ) -> Assertion
51- requireDiagnostic actuals expected@ (severity, cursor, expectedMsg, expectedTag) = do
52- unless (any match actuals) $
53- assertFailure $
54- " Could not find " <> show expected <>
55- " in " <> show actuals
56- where
57- match :: Diagnostic -> Bool
58- match d =
59- Just severity == _severity d
60- && cursorPosition cursor == d ^. range . start
61- && standardizeQuotes (T. toLower expectedMsg) `T.isInfixOf`
62- standardizeQuotes (T. toLower $ d ^. message)
63- && hasTag expectedTag (d ^. tags)
64-
65- hasTag :: Maybe DiagnosticTag -> Maybe (List DiagnosticTag ) -> Bool
66- hasTag Nothing _ = True
67- hasTag (Just _) Nothing = False
68- hasTag (Just actualTag) (Just (List tags)) = actualTag `elem` tags
45+ requireDiagnosticM
46+ :: (Foldable f , Show (f Diagnostic ), HasCallStack )
47+ => f Diagnostic
48+ -> (DiagnosticSeverity , Cursor , T. Text , Maybe DiagnosticTag )
49+ -> Assertion
50+ requireDiagnosticM actuals expected = case requireDiagnostic actuals expected of
51+ Nothing -> pure ()
52+ Just err -> assertFailure err
6953
7054-- | wait for @timeout@ seconds and report an assertion failure
7155-- if any diagnostic messages arrive in that period
@@ -154,7 +138,7 @@ expectDiagnosticsWithTags' next expected = go expected
154138 <> " got "
155139 <> show actual
156140 Just expected -> do
157- liftIO $ mapM_ (requireDiagnostic actual) expected
141+ liftIO $ mapM_ (requireDiagnosticM actual) expected
158142 liftIO $
159143 unless (length expected == length actual) $
160144 assertFailure $
@@ -182,14 +166,6 @@ canonicalizeUri uri = filePathToUri <$> canonicalizePath (fromJust (uriToFilePat
182166diagnostic :: Session (NotificationMessage TextDocumentPublishDiagnostics )
183167diagnostic = LspTest. message STextDocumentPublishDiagnostics
184168
185- standardizeQuotes :: T. Text -> T. Text
186- standardizeQuotes msg = let
187- repl ' ‘' = ' \' '
188- repl ' ’' = ' \' '
189- repl ' `' = ' \' '
190- repl c = c
191- in T. map repl msg
192-
193169waitForAction :: String -> TextDocumentIdentifier -> Session (Either ResponseError WaitForIdeRuleResult )
194170waitForAction key TextDocumentIdentifier {_uri} = do
195171 let cm = SCustomMethod " test"
0 commit comments