Skip to content

Commit 8f9ce65

Browse files
committed
Add tests
1 parent 5936154 commit 8f9ce65

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

ghcide/test/exe/Main.hs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,6 +4615,7 @@ completionTests
46154615
, testGroup "package" packageCompletionTests
46164616
, testGroup "project" projectCompletionTests
46174617
, testGroup "other" otherCompletionTests
4618+
, testGroup "doc" completionDocTests
46184619
]
46194620

46204621
completionTest :: String -> [T.Text] -> Position -> [(T.Text, CompletionItemKind, T.Text, Bool, Bool, Maybe (List TextEdit))] -> TestTree
@@ -5230,6 +5231,87 @@ projectCompletionTests =
52305231
item ^. L.label @?= "anidentifier"
52315232
]
52325233

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* * *\ndocdoc\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\ndef\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\nBoolean \"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\nIdentity function. \n```haskell\nid 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+
52335315
highlightTests :: TestTree
52345316
highlightTests = testGroup "highlight"
52355317
[ testSessionWait "value" $ do

0 commit comments

Comments
 (0)