Skip to content

Commit 2cb5ff1

Browse files
committed
Add goto dependency type test
1 parent eb05e49 commit 2cb5ff1

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

ghcide/test/exe/Dependency.hs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import TestUtils (testSessionWithExtraFiles, kno
3232
tests :: TestTree
3333
tests =
3434
testGroup "gotoDefinition for dependencies"
35-
[ dependencyTest
35+
[ dependencyTermTest
36+
, dependencyTypeTest
3637
, transitiveDependencyTest
3738
, autogenDependencyTest
3839
]
@@ -53,8 +54,11 @@ fileDoneIndexing fpSuffix =
5354
fpSuffix `isSuffixOf` fpDirs
5455
other -> error $ "Failed to parse ghcide/reference/ready file: " <> show other
5556

56-
dependencyTest :: TestTree
57-
dependencyTest = testSessionWithExtraFiles "dependency" "gotoDefinition in async" $
57+
-- Tests that we can go to the definition of a term in a dependency.
58+
-- In this case, we are getting the definition of the data
59+
-- constructor AsyncCancelled.
60+
dependencyTermTest :: TestTree
61+
dependencyTermTest = testSessionWithExtraFiles "dependency" "gotoDefinition term in async" $
5862
\dir -> do
5963
doc <- openDoc (dir </> "Dependency" <.> "hs") "haskell"
6064
_hieFile <- fileDoneIndexing ["Control", "Concurrent", "Async.hie"]
@@ -76,6 +80,31 @@ dependencyTest = testSessionWithExtraFiles "dependency" "gotoDefinition in async
7680
assertFailure $ "Wrong location for AsyncCancelled: "
7781
++ show wrongLocation
7882

83+
-- Tests that we can go to the definition of a type in a dependency.
84+
-- In this case, we are getting the definition of the type AsyncCancelled.
85+
dependencyTypeTest :: TestTree
86+
dependencyTypeTest = testSessionWithExtraFiles "dependency" "gotoDefinition type in async" $
87+
\dir -> do
88+
doc <- openDoc (dir </> "Dependency" <.> "hs") "haskell"
89+
_hieFile <- fileDoneIndexing ["Control", "Concurrent", "Async.hie"]
90+
defs <- getDefinitions doc (Position 4 21)
91+
let expRange = Range (Position 430 0) (Position 435 5)
92+
case defs of
93+
InL (Definition (InR [Location fp actualRange])) ->
94+
liftIO $ do
95+
let locationDirectories :: [String]
96+
locationDirectories =
97+
maybe [] splitDirectories $
98+
uriToFilePath fp
99+
assertBool "AsyncCancelled found in a module that is not Control.Concurrent Async"
100+
$ ["Control", "Concurrent", "Async.hs"]
101+
`isSuffixOf` locationDirectories
102+
actualRange @?= expRange
103+
wrongLocation ->
104+
liftIO $
105+
assertFailure $ "Wrong location for AsyncCancelled: "
106+
++ show wrongLocation
107+
79108
-- Tests that we can go to the definition of a dependency, and then
80109
-- from the dependency file we can use gotoDefinition to see a
81110
-- tranisive dependency.

0 commit comments

Comments
 (0)