Skip to content

Commit 1a7a370

Browse files
committed
Tests: hint location, package import, qualified import
1 parent 79fbbaa commit 1a7a370

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

plugins/hls-explicit-imports-plugin/test/Main.hs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,27 @@ main = defaultTestRunner $ testGroup "import-actions"
107107
o = "(Athing, Bthing, ... (4 items))"
108108
in ExplicitImports.abbreviateImportTitleWithoutModule i @?= o
109109
]
110-
]]
110+
],
111+
testGroup
112+
"Import package inlay hints"
113+
[ testGroup "Without package imports"
114+
[ inlayHintsTestWithCap "ImportUsual" 2 $ (@=?)
115+
[mkInlayHintNoTextEdit (Position 2 6) "\"base\""]
116+
, inlayHintsTestWithCap "ImportUsual" 3 $ (@=?)
117+
[mkInlayHintNoTextEdit (Position 3 16) "\"containers\""]
118+
, inlayHintsTestWithCap "ImportUsual" 4 $ (@=?) []
119+
, inlayHintsTestWithoutCap "ImportUsual" 2 $ (@=?) []
120+
, inlayHintsTestWithoutCap "ImportUsual" 3 $ (@=?) []
121+
, inlayHintsTestWithoutCap "ImportUsual" 4 $ (@=?) []
122+
], testGroup "With package imports"
123+
[ inlayHintsTestWithCap "ImportWithPackageImport" 3 $ (@=?) []
124+
, inlayHintsTestWithCap "ImportWithPackageImport" 4 $ (@=?)
125+
[mkInlayHintNoTextEdit (Position 4 16) "\"containers\""]
126+
, inlayHintsTestWithCap "ImportWithPackageImport" 5 $ (@=?) []
127+
, inlayHintsTestWithoutCap "ImportWithPackageImport" 3 $ (@=?) []
128+
, inlayHintsTestWithoutCap "ImportWithPackageImport" 4 $ (@=?) []
129+
, inlayHintsTestWithoutCap "ImportWithPackageImport" 5 $ (@=?) []
130+
]]]
111131

112132
-- code action tests
113133

@@ -252,6 +272,19 @@ mkInlayHint pos label textEdit =
252272
, _data_ = Nothing
253273
}
254274

275+
mkInlayHintNoTextEdit :: Position -> Text -> InlayHint
276+
mkInlayHintNoTextEdit pos label =
277+
InlayHint
278+
{ _position = pos
279+
, _label = InL label
280+
, _kind = Nothing
281+
, _textEdits = Nothing
282+
, _tooltip = Nothing
283+
, _paddingLeft = Just True
284+
, _paddingRight = Nothing
285+
, _data_ = Nothing
286+
}
287+
255288
-- Execute command and wait for result
256289
executeCmd :: Command -> Session ()
257290
executeCmd cmd = do
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module ImportUsual where
2+
3+
import Data.List (intersperse)
4+
import qualified Data.Map as Map
5+
import ExplicitA ( a1, a2 )
6+
7+
ordinaryMap :: Map.Map String String
8+
ordinaryMap = Map.fromList [(a1, a2)]
9+
10+
main :: IO ()
11+
main =
12+
putStrLn (concat (intersperse " " ["hello", "world", name, "!"]))
13+
where
14+
name =
15+
Map.findWithDefault "default" a1 ordinaryMap
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-# LANGUAGE PackageImports #-}
2+
module ImportWithPackageImport where
3+
4+
import "base" Data.List (intersperse)
5+
import qualified Data.Map as Map
6+
import ExplicitA ( a1, a2 )
7+
8+
ordinaryMap :: Map.Map String String
9+
ordinaryMap = Map.fromList [(a1, a2)]
10+
11+
main :: IO ()
12+
main =
13+
putStrLn (concat (intersperse " " ["hello", "world", name, "!"]))
14+
where
15+
name =
16+
Map.findWithDefault "default" a1 ordinaryMap

0 commit comments

Comments
 (0)