|
1 | 1 | module TypeDefinition (tests) where
|
2 | 2 |
|
3 |
| -import Control.Lens ((^.)) |
4 | 3 | import Control.Monad.IO.Class
|
| 4 | +import Data.Tuple.Extra (first3) |
5 | 5 | import Language.Haskell.LSP.Test
|
6 | 6 | import Language.Haskell.LSP.Types
|
7 |
| -import qualified Language.Haskell.LSP.Types.Lens as L |
8 |
| -import System.Directory |
9 | 7 | import System.FilePath ((</>))
|
10 | 8 | import Test.Hls.Util
|
11 | 9 | import Test.Tasty
|
12 |
| -import Test.Tasty.ExpectedFailure (expectFailBecause) |
13 | 10 | import Test.Tasty.HUnit
|
14 | 11 |
|
15 | 12 | tests :: TestTree
|
16 | 13 | tests = testGroup "type definitions" [
|
17 | 14 | testCase "finds local definition of record variable"
|
18 |
| - $ getTypeDefinitionTest' (11, 23) 8 |
| 15 | + $ getTypeDefinitionTest' 10 23 7 0 |
19 | 16 | , testCase "finds local definition of newtype variable"
|
20 |
| - $ getTypeDefinitionTest' (16, 21) 13 |
| 17 | + $ getTypeDefinitionTest' 15 21 12 0 |
21 | 18 | , testCase "finds local definition of sum type variable"
|
22 |
| - $ getTypeDefinitionTest' (21, 13) 18 |
| 19 | + $ getTypeDefinitionTest' 20 13 17 0 |
23 | 20 | , knownBrokenForGhcVersions [GHC88] "Definition of sum type not found from data constructor in GHC 8.8.x" $
|
24 | 21 | testCase "finds local definition of sum type constructor"
|
25 |
| - $ getTypeDefinitionTest' (24, 7) 18 |
| 22 | + $ getTypeDefinitionTest' 23 7 17 0 |
26 | 23 | , testCase "finds non-local definition of type def"
|
27 |
| - $ getTypeDefinitionTest' (30, 17) 27 |
| 24 | + $ getTypeDefinitionTest' 29 17 26 0 |
28 | 25 | , testCase "find local definition of type def"
|
29 |
| - $ getTypeDefinitionTest' (35, 16) 32 |
| 26 | + $ getTypeDefinitionTest' 34 16 31 0 |
30 | 27 | , testCase "find type-definition of type def in component"
|
31 |
| - $ getTypeDefinitionTest "src/Lib2.hs" (13, 20) "src/Lib.hs" 8 |
32 |
| - , expectFailBecause "Why is this failing?" $ |
33 |
| - testCase "find definition of parameterized data type" |
34 |
| - $ getTypeDefinitionTest' (40, 19) 37 |
| 28 | + $ getTypeDefinitionTest ("src/Lib2.hs", 12, 20) [("src/Lib.hs", 7, 0)] |
| 29 | + , testCase "find definition of parameterized data type" |
| 30 | + $ getTypeDefinitionTest ("src/Lib.hs", 39, 19) [ ("src/Lib.hs", 36, 0) |
| 31 | + , ("src/Lib.hs", 38, 0)] |
35 | 32 | ]
|
36 | 33 |
|
37 |
| -getTypeDefinitionTest :: String -> (Int, Int) -> String -> Int -> Assertion |
38 |
| -getTypeDefinitionTest symbolFile symbolPosition definitionFile definitionLine = |
39 |
| - failIfSessionTimeout . runSession hlsCommand fullCaps "test/testdata/gototest" $ do |
40 |
| - doc <- openDoc symbolFile "haskell" |
41 |
| - _ <- openDoc definitionFile "haskell" |
42 |
| - defs <- getTypeDefinitions doc $ toPos symbolPosition |
43 |
| - fp <- liftIO $ canonicalizePath $ "test/testdata/gototest" </> definitionFile |
44 |
| - liftIO $ do |
45 |
| - length defs == 1 @? "Expecting a list containing one location, but got: " ++ show defs |
46 |
| - let [def] = defs |
47 |
| - def ^. L.uri @?= filePathToUri fp |
48 |
| - def ^. L.range . L.start . L.line @?= definitionLine - 1 |
49 |
| - def ^. L.range . L.end . L.line @?= definitionLine - 1 |
| 34 | +definitionsPath :: FilePath |
| 35 | +definitionsPath = "test/testdata/gototest" |
50 | 36 |
|
51 |
| -getTypeDefinitionTest' :: (Int, Int) -> Int -> Assertion |
52 |
| -getTypeDefinitionTest' symbolPosition definitionLine = |
53 |
| - getTypeDefinitionTest "src/Lib.hs" symbolPosition "src/Lib.hs" definitionLine |
| 37 | +getTypeDefinitionTest :: SymbolLocation -> [SymbolLocation] -> Assertion |
| 38 | +getTypeDefinitionTest (symbolFile, symbolLine, symbolCol) definitionLocations = |
| 39 | + failIfSessionTimeout . runSession hlsCommand fullCaps definitionsPath $ do |
| 40 | + doc <- openDoc symbolFile "haskell" |
| 41 | + defs <- getTypeDefinitions doc $ Position symbolLine symbolCol |
| 42 | + liftIO $ defs `expectSameLocations` map (first3 (definitionsPath </>)) definitionLocations |
54 | 43 |
|
55 |
| ---NOTE: copied from Haskell.Ide.Engine.ArtifactMap |
56 |
| -toPos :: (Int,Int) -> Position |
57 |
| -toPos (l,c) = Position (l-1) (c-1) |
| 44 | +getTypeDefinitionTest' :: Int -> Int -> Int -> Int -> Assertion |
| 45 | +getTypeDefinitionTest' symbolLine symbolCol definitionLine definitionCol = |
| 46 | + getTypeDefinitionTest ("src/Lib.hs", symbolLine, symbolCol) |
| 47 | + [("src/Lib.hs", definitionLine, definitionCol)] |
0 commit comments