@@ -33,6 +33,7 @@ import Data.Maybe (fromJust)
33
33
import qualified Data.Text as T
34
34
import Development.IDE.Plugin.Test (TestRequest (.. ),
35
35
WaitForIdeRuleResult )
36
+ import Development.IDE.Test.Diagnostic
36
37
import Language.LSP.Test hiding (message )
37
38
import qualified Language.LSP.Test as LspTest
38
39
import Language.LSP.Types
@@ -41,31 +42,14 @@ import System.Directory (canonicalizePath)
41
42
import System.Time.Extra
42
43
import Test.Tasty.HUnit
43
44
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
69
53
70
54
-- | wait for @timeout@ seconds and report an assertion failure
71
55
-- if any diagnostic messages arrive in that period
@@ -154,7 +138,7 @@ expectDiagnosticsWithTags' next expected = go expected
154
138
<> " got "
155
139
<> show actual
156
140
Just expected -> do
157
- liftIO $ mapM_ (requireDiagnostic actual) expected
141
+ liftIO $ mapM_ (requireDiagnosticM actual) expected
158
142
liftIO $
159
143
unless (length expected == length actual) $
160
144
assertFailure $
@@ -182,14 +166,6 @@ canonicalizeUri uri = filePathToUri <$> canonicalizePath (fromJust (uriToFilePat
182
166
diagnostic :: Session (NotificationMessage TextDocumentPublishDiagnostics )
183
167
diagnostic = LspTest. message STextDocumentPublishDiagnostics
184
168
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
-
193
169
waitForAction :: String -> TextDocumentIdentifier -> Session (Either ResponseError WaitForIdeRuleResult )
194
170
waitForAction key TextDocumentIdentifier {_uri} = do
195
171
let cm = SCustomMethod " test"
0 commit comments