@@ -4615,6 +4615,7 @@ completionTests
4615
4615
, testGroup " package" packageCompletionTests
4616
4616
, testGroup " project" projectCompletionTests
4617
4617
, testGroup " other" otherCompletionTests
4618
+ , testGroup " doc" completionDocTests
4618
4619
]
4619
4620
4620
4621
completionTest :: String -> [T. Text ] -> Position -> [(T. Text , CompletionItemKind , T. Text , Bool , Bool , Maybe (List TextEdit ))] -> TestTree
@@ -5230,6 +5231,87 @@ projectCompletionTests =
5230
5231
item ^. L. label @?= " anidentifier"
5231
5232
]
5232
5233
5234
+ completionDocTests :: [TestTree ]
5235
+ completionDocTests =
5236
+ [ testSession " local define" $ do
5237
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5238
+ [ " module A where"
5239
+ , " foo = ()"
5240
+ , " bar = fo"
5241
+ ]
5242
+ let expected = " *Defined at line 2, column 1 in this module*\n "
5243
+ test doc (Position 2 8 ) " foo" (Just $ T. length expected) [expected]
5244
+ , testSession " local empty doc" $ do
5245
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5246
+ [ " module A where"
5247
+ , " foo = ()"
5248
+ , " bar = fo"
5249
+ ]
5250
+ test doc (Position 2 8 ) " foo" Nothing [" *Defined at line 2, column 1 in this module*\n " ]
5251
+ , broken $ testSession " local single line doc without '\\ n'" $ do
5252
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5253
+ [ " module A where"
5254
+ , " -- |docdoc"
5255
+ , " foo = ()"
5256
+ , " bar = fo"
5257
+ ]
5258
+ test doc (Position 3 8 ) " foo" Nothing [" *Defined at line 3, column 1 in this module*\n * * *\n docdoc\n " ]
5259
+ , broken $ testSession " local multi line doc with '\\ n'" $ do
5260
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5261
+ [ " module A where"
5262
+ , " -- | abcabc"
5263
+ , " --"
5264
+ , " foo = ()"
5265
+ , " bar = fo"
5266
+ ]
5267
+ test doc (Position 4 8 ) " foo" Nothing [" *Defined at line 4, column 1 in this module*\n * * *\n abcabc\n " ]
5268
+ , broken $ testSession " local multi line doc without '\\ n'" $ do
5269
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5270
+ [ " module A where"
5271
+ , " -- | abcabc"
5272
+ , " --"
5273
+ , " --def"
5274
+ , " foo = ()"
5275
+ , " bar = fo"
5276
+ ]
5277
+ test doc (Position 5 8 ) " foo" Nothing [" *Defined at line 5, column 1 in this module*\n * * *\n abcabc\n\n def\n " ]
5278
+ , testSession " extern empty doc" $ do
5279
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5280
+ [ " module A where"
5281
+ , " foo = od"
5282
+ ]
5283
+ let expected = " *Imported from 'Prelude'*\n * * *\n [Documentation](file:"
5284
+ test doc (Position 1 8 ) " odd" (Just $ T. length expected) [expected]
5285
+ , broken $ testSession " extern single line doc without '\\ n'" $ do
5286
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5287
+ [ " module A where"
5288
+ , " foo = no"
5289
+ ]
5290
+ let expected = " *Imported from 'Prelude'*\n * * *\n\n\n Boolean \" not\"\n * * *\n [Documentation](file:"
5291
+ test doc (Position 1 8 ) " not" (Just $ T. length expected) [expected]
5292
+ , broken $ testSession " extern mulit line doc" $ do
5293
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
5294
+ [ " module A where"
5295
+ , " foo = i"
5296
+ ]
5297
+ let expected = " *Imported from 'Prelude'*\n * * *\n\n\n Identity function. \n ```haskell\n id x = x\n ```\n * * *\n [Documentation](file:"
5298
+ test doc (Position 1 7 ) " id" (Just $ T. length expected) [expected]
5299
+ ]
5300
+ where
5301
+ broken = knownBrokenForGhcVersions [GHC90 , GHC92 ] " Completion doc doesn't support ghc9"
5302
+ test doc pos label mn expected = do
5303
+ _ <- waitForDiagnostics
5304
+ compls <- getCompletions doc pos
5305
+ let compls' = [
5306
+ -- We ignore doc uris since it points to the local path which determined by specific machines
5307
+ case mn of
5308
+ Nothing -> txt
5309
+ Just n -> T. take n txt
5310
+ | CompletionItem {_documentation = Just (CompletionDocMarkup (MarkupContent MkMarkdown txt)), .. } <- compls
5311
+ , _label == label
5312
+ ]
5313
+ liftIO $ compls' @?= expected
5314
+
5233
5315
highlightTests :: TestTree
5234
5316
highlightTests = testGroup " highlight"
5235
5317
[ testSessionWait " value" $ do
0 commit comments