Skip to content

Commit 274ae10

Browse files
committed
WIP: Tests
1 parent 366f1f0 commit 274ae10

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Dependencies.hs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module Ide.Plugin.Cabal.Dependencies (dependencyVersionHints, collectPackageDepe
55

66
import Data.Array ((!))
77
import Data.ByteString (ByteString)
8-
import qualified Data.Char as Char
9-
import qualified Data.List as List
108
import qualified Data.Maybe as Maybe
119
import qualified Data.Text as T
1210
import qualified Data.Text.Encoding as Encoding
@@ -21,7 +19,6 @@ import qualified Distribution.Parsec.Position as Syntax
2119
import qualified Ide.Plugin.Cabal.Completion.Types as Types
2220
import Language.LSP.Protocol.Types (CodeLens (..), Command (..),
2321
InlayHint (..),
24-
InlayHintLabelPart (InlayHintLabelPart),
2522
Range (..), type (|?) (..))
2623
import Text.Regex.TDFA (Regex, makeRegex,
2724
matchAllText)
@@ -43,16 +40,15 @@ dependencyVersionHints cabalFields = fmap mkHint . collectPackageDependencyVersi
4340
where
4441
mkHint :: (Syntax.Position, Version) -> InlayHint
4542
mkHint (pos, dependencyVersion) =
46-
let mkInlayHintLabelPart = InlayHintLabelPart (" (" <> printVersion dependencyVersion <> ")") Nothing Nothing Nothing
47-
in InlayHint { _position = Types.cabalPositionToLSPPosition pos
48-
, _label = InR $ pure mkInlayHintLabelPart
49-
, _kind = Nothing
50-
, _textEdits = Nothing
51-
, _tooltip = Nothing
52-
, _paddingLeft = Nothing
53-
, _paddingRight = Nothing
54-
, _data_ = Nothing
55-
}
43+
InlayHint { _position = Types.cabalPositionToLSPPosition pos
44+
, _label = InL $ " (" <> printVersion dependencyVersion <> ")"
45+
, _kind = Nothing
46+
, _textEdits = Nothing
47+
, _tooltip = Nothing
48+
, _paddingLeft = Nothing
49+
, _paddingRight = Nothing
50+
, _data_ = Nothing
51+
}
5652

5753
collectPackageDependencyVersions :: [Syntax.Field Syntax.Position] -> HscEnv -> [(Syntax.Position, Version)]
5854
collectPackageDependencyVersions cabalFields hscEnv = cabalFields >>= collectPackageVersions

plugins/hls-cabal-plugin/test/CabalAdd.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ cabalAddTests =
175175
, _data_ = Nothing
176176
}
177177

178-
179178
generatePackageYAMLTestSession :: FilePath -> Session ()
180179
generatePackageYAMLTestSession haskellFile = do
181180
hsdoc <- openDoc haskellFile "haskell"

plugins/hls-cabal-plugin/test/Main.hs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Main (
99
import CabalAdd (cabalAddTests)
1010
import Completer (completerTests)
1111
import Context (contextTests)
12-
import Control.Lens ((^.))
12+
import Control.Lens ((^.), preview, _Just, view)
1313
import Control.Lens.Fold ((^?))
1414
import Control.Monad (guard)
1515
import qualified Data.ByteString as BS
@@ -39,6 +39,7 @@ main = do
3939
, codeActionTests
4040
, gotoDefinitionTests
4141
, hoverTests
42+
, codeLensTests
4243
]
4344

4445
-- ------------------------------------------------------------------------
@@ -259,3 +260,27 @@ hoverOnDependencyTests = testGroup "Hover Dependency"
259260
h <- getHover doc pos
260261
liftIO $ assertBool ("Found hover `" <> show h <> "`") $ Maybe.isNothing h
261262
closeDoc doc
263+
264+
-- ----------------------------------------------------------------------------
265+
-- Code Lens Tests
266+
-- ----------------------------------------------------------------------------
267+
268+
codeLensTests :: TestTree
269+
codeLensTests = testGroup "Code Lens"
270+
[ dependencyVersionLenses
271+
, dependencyVersionInlayHints
272+
]
273+
where
274+
dependencyVersionLenses =
275+
runCabalTestCaseSession "Code Lens Test" "hover" $ do
276+
doc <- openDoc "hover-deps.cabal" "cabal"
277+
lenses <- getCodeLenses doc
278+
liftIO $ map (preview $ L.command . _Just . L.title) lenses @?= [Just "Refresh..."]
279+
closeDoc doc
280+
dependencyVersionInlayHints =
281+
runCabalTestCaseSession "InlayHints tests" "hover" $ do
282+
doc <- openDoc "hover-deps.cabal" "cabal"
283+
let range = Range (Position 0 0) (Position 1000 1000)
284+
hints <- getInlayHints doc range
285+
liftIO $ map (view L.label) hints @?= [InL " (4.19.2.0)"]
286+
closeDoc doc

0 commit comments

Comments
 (0)