Skip to content

Commit a516302

Browse files
committed
add tests
1 parent 96e3546 commit a516302

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{-# LANGUAGE CPP #-}
2+
#if __GLASGOW_HASKELL__ >= 902
3+
{-# LANGUAGE OverloadedRecordDot, DuplicateRecordFields, NoFieldSelectors #-}
4+
5+
module RecordDotSyntax ( module RecordDotSyntax) where
6+
7+
import qualified Data.Maybe as M
8+
9+
data MyRecord = MyRecord
10+
{ a :: String
11+
, b :: Integer
12+
, c :: MyChild
13+
} deriving (Eq, Show)
14+
15+
newtype MyChild = MyChild
16+
{ z :: String
17+
} deriving (Eq, Show)
18+
19+
x = MyRecord { a = "Hello", b = 12, c = MyChild { z = "there" } }
20+
y = x.a ++ show x.b ++ x.c.z
21+
#endif

ghcide/test/data/hover/hie.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cradle: {direct: {arguments: ["Foo", "Bar", "GotoHover"]}}
1+
cradle: {direct: {arguments: ["Foo", "Bar", "GotoHover", "RecordDotSyntax"]}}

ghcide/test/exe/Main.hs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,8 +4283,8 @@ canonicalizeLocation (Location uri range) = Location <$> canonicalizeUri uri <*>
42834283
findDefinitionAndHoverTests :: TestTree
42844284
findDefinitionAndHoverTests = let
42854285

4286-
tst :: (TextDocumentIdentifier -> Position -> Session a, a -> Session [Expect] -> Session ()) -> Position -> Session [Expect] -> String -> TestTree
4287-
tst (get, check) pos targetRange title = testSessionWithExtraFiles "hover" title $ \dir -> do
4286+
tst :: (TextDocumentIdentifier -> Position -> Session a, a -> Session [Expect] -> Session ()) -> Position -> String -> Session [Expect] -> String -> TestTree
4287+
tst (get, check) pos sfp targetRange title = testSessionWithExtraFiles "hover" title $ \dir -> do
42884288

42894289
-- Dirty the cache to check that definitions work even in the presence of iface files
42904290
liftIO $ runInDir dir $ do
@@ -4294,7 +4294,7 @@ findDefinitionAndHoverTests = let
42944294
_ <- getHover fooDoc $ Position 4 3
42954295
closeDoc fooDoc
42964296

4297-
doc <- openTestDataDoc (dir </> sourceFilePath)
4297+
doc <- openTestDataDoc (dir </> sfp)
42984298
waitForProgressDone
42994299
found <- get doc pos
43004300
check found targetRange
@@ -4352,16 +4352,25 @@ findDefinitionAndHoverTests = let
43524352
[ ( "GotoHover.hs", [(DsError, (62, 7), "Found hole: _")])
43534353
, ( "GotoHover.hs", [(DsError, (65, 8), "Found hole: _")])
43544354
]
4355-
, testGroup "type-definition" typeDefinitionTests ]
4356-
4357-
typeDefinitionTests = [ tst (getTypeDefinitions, checkDefs) aaaL14 (pure tcData) "Saturated data con"
4358-
, tst (getTypeDefinitions, checkDefs) aL20 (pure [ExpectNoDefinitions]) "Polymorphic variable"]
4355+
, testGroup "type-definition" typeDefinitionTests
4356+
, testGroup "hover-record-dot-syntax" recordDotSyntaxTests ]
4357+
4358+
typeDefinitionTests = [ tst (getTypeDefinitions, checkDefs) aaaL14 sourceFilePath (pure tcData) "Saturated data con"
4359+
, tst (getTypeDefinitions, checkDefs) aL20 sourceFilePath (pure [ExpectNoDefinitions]) "Polymorphic variable"]
4360+
4361+
recordDotSyntaxTests
4362+
| ghcVersion == GHC92 =
4363+
[ tst (getHover, checkHover) (Position 19 24) (T.unpack "RecordDotSyntax.hs") (pure [ExpectHoverText ["x :: MyRecord"]]) "hover over parent"
4364+
, tst (getHover, checkHover) (Position 19 25) (T.unpack "RecordDotSyntax.hs") (pure [ExpectHoverText ["_ :: MyChild"]]) "hover over dot shows child"
4365+
, tst (getHover, checkHover) (Position 19 26) (T.unpack "RecordDotSyntax.hs") (pure [ExpectHoverText ["_ :: MyChild"]]) "hover over child"
4366+
]
4367+
| otherwise = []
43594368

43604369
test runDef runHover look expect = testM runDef runHover look (return expect)
43614370

43624371
testM runDef runHover look expect title =
4363-
( runDef $ tst def look expect title
4364-
, runHover $ tst hover look expect title ) where
4372+
( runDef $ tst def look sourceFilePath expect title
4373+
, runHover $ tst hover look sourceFilePath expect title ) where
43654374
def = (getDefinitions, checkDefs)
43664375
hover = (getHover , checkHover)
43674376

0 commit comments

Comments
 (0)