@@ -63,10 +63,13 @@ import System.FilePath (equalFilePath)
63
63
import System.Time.Extra
64
64
import Test.Tasty.HUnit
65
65
66
+ expectedDiagnosticWithNothing :: ExpectedDiagnostic -> ExpectedDiagnosticWithTag
67
+ expectedDiagnosticWithNothing (ds, c, t, code) = (ds, c, t, code, Nothing )
68
+
66
69
requireDiagnosticM
67
70
:: (Foldable f , Show (f Diagnostic ), HasCallStack )
68
71
=> f Diagnostic
69
- -> ( DiagnosticSeverity , Cursor , T. Text , Maybe T. Text , Maybe DiagnosticTag )
72
+ -> ExpectedDiagnosticWithTag
70
73
-> Assertion
71
74
requireDiagnosticM actuals expected = case requireDiagnostic actuals expected of
72
75
Nothing -> pure ()
@@ -114,15 +117,15 @@ flushMessages = do
114
117
--
115
118
-- Rather than trying to assert the absence of diagnostics, introduce an
116
119
-- expected diagnostic (e.g. a redundant import) and assert the singleton diagnostic.
117
- expectDiagnostics :: HasCallStack => [(FilePath , [( DiagnosticSeverity , Cursor , T. Text , Maybe T. Text ) ])] -> Session ()
120
+ expectDiagnostics :: HasCallStack => [(FilePath , [ExpectedDiagnostic ])] -> Session ()
118
121
expectDiagnostics
119
122
= expectDiagnosticsWithTags
120
- . map (second (map ( \ (ds, c, t, code) -> (ds, c, t, code, Nothing )) ))
123
+ . map (second (map expectedDiagnosticWithNothing ))
121
124
122
125
unwrapDiagnostic :: TServerMessage Method_TextDocumentPublishDiagnostics -> (Uri , [Diagnostic ])
123
126
unwrapDiagnostic diagsNot = (diagsNot^. L. params . L. uri, diagsNot^. L. params . L. diagnostics)
124
127
125
- expectDiagnosticsWithTags :: HasCallStack => [(String , [( DiagnosticSeverity , Cursor , T. Text , Maybe T. Text , Maybe DiagnosticTag ) ])] -> Session ()
128
+ expectDiagnosticsWithTags :: HasCallStack => [(String , [ExpectedDiagnosticWithTag ])] -> Session ()
126
129
expectDiagnosticsWithTags expected = do
127
130
let toSessionPath = getDocUri >=> liftIO . canonicalizeUri >=> pure . toNormalizedUri
128
131
next = unwrapDiagnostic <$> skipManyTill anyMessage diagnostic
@@ -132,7 +135,7 @@ expectDiagnosticsWithTags expected = do
132
135
expectDiagnosticsWithTags' ::
133
136
(HasCallStack , MonadIO m ) =>
134
137
m (Uri , [Diagnostic ]) ->
135
- Map. Map NormalizedUri [( DiagnosticSeverity , Cursor , T. Text , Maybe T. Text , Maybe DiagnosticTag ) ] ->
138
+ Map. Map NormalizedUri [ExpectedDiagnosticWithTag ] ->
136
139
m ()
137
140
expectDiagnosticsWithTags' next m | null m = do
138
141
(_,actual) <- next
@@ -170,14 +173,14 @@ expectDiagnosticsWithTags' next expected = go expected
170
173
<> show actual
171
174
go $ Map. delete canonUri m
172
175
173
- expectCurrentDiagnostics :: HasCallStack => TextDocumentIdentifier -> [( DiagnosticSeverity , Cursor , T. Text , Maybe T. Text ) ] -> Session ()
176
+ expectCurrentDiagnostics :: HasCallStack => TextDocumentIdentifier -> [ExpectedDiagnostic ] -> Session ()
174
177
expectCurrentDiagnostics doc expected = do
175
178
diags <- getCurrentDiagnostics doc
176
179
checkDiagnosticsForDoc doc expected diags
177
180
178
- checkDiagnosticsForDoc :: HasCallStack => TextDocumentIdentifier -> [( DiagnosticSeverity , Cursor , T. Text , Maybe T. Text ) ] -> [Diagnostic ] -> Session ()
181
+ checkDiagnosticsForDoc :: HasCallStack => TextDocumentIdentifier -> [ExpectedDiagnostic ] -> [Diagnostic ] -> Session ()
179
182
checkDiagnosticsForDoc TextDocumentIdentifier {_uri} expected obtained = do
180
- let expected' = Map. singleton nuri (map ( \ (ds, c, t, code) -> (ds, c, t, code, Nothing )) expected)
183
+ let expected' = Map. singleton nuri (map expectedDiagnosticWithNothing expected)
181
184
nuri = toNormalizedUri _uri
182
185
expectDiagnosticsWithTags' (return (_uri, obtained)) expected'
183
186
0 commit comments