Skip to content

Commit fdefb6b

Browse files
committed
Add a test for removing an unused module
1 parent 14b0b16 commit fdefb6b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/exe/Main.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ codeActionTests :: TestTree
212212
codeActionTests = testGroup "code actions"
213213
[ renameActionTests
214214
, typeWildCardActionTests
215+
, removeImportTests
215216
]
216217

217218
renameActionTests :: TestTree
@@ -360,6 +361,34 @@ typeWildCardActionTests = testGroup "type wildcard actions"
360361
liftIO $ expectedContentAfterAction @=? contentAfterAction
361362
]
362363

364+
removeImportTests :: TestTree
365+
removeImportTests = testGroup "remove import actions"
366+
[ testSession "redundant" $ do
367+
let contentA = T.unlines
368+
[ "module ModuleA where"
369+
]
370+
docA <- openDoc' "ModuleA.hs" "haskell" contentA
371+
let contentB = T.unlines
372+
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
373+
, "module ModuleB where"
374+
, "import ModuleA"
375+
, "stuffB = 123"
376+
]
377+
docB <- openDoc' "ModuleB.hs" "haskell" contentB
378+
_ <- waitForDiagnostics
379+
[CACodeAction action@CodeAction { _title = actionTitle }]
380+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
381+
liftIO $ "Remove import" @=? actionTitle
382+
executeCodeAction action
383+
contentAfterAction <- documentContents docB
384+
let expectedContentAfterAction = T.unlines
385+
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
386+
, "module ModuleB where"
387+
, "stuffB = 123"
388+
]
389+
liftIO $ expectedContentAfterAction @=? contentAfterAction
390+
]
391+
363392
----------------------------------------------------------------------
364393
-- Utils
365394

0 commit comments

Comments
 (0)