Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 2120fd0

Browse files
committed
Add and fix tests for import code action
1 parent 6ce959a commit 2120fd0

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

test/functional/FunctionalCodeActionsSpec.hs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,16 @@ spec = describe "code actions" $ do
136136
let actns = map fromAction actionsOrCommands
137137

138138
liftIO $ do
139-
head actns ^. L.title `shouldBe` "Import module Control.Monad"
139+
head actns ^. L.title `shouldBe` "Import module Control.Monad"
140+
head (tail actns) ^. L.title `shouldBe` "Import module Control.Monad (when)"
140141
forM_ actns $ \a -> do
141142
a ^. L.kind `shouldBe` Just CodeActionQuickFix
142143
a ^. L.command `shouldSatisfy` isJust
143144
a ^. L.edit `shouldBe` Nothing
144145
let hasOneDiag (Just (List [_])) = True
145146
hasOneDiag _ = False
146147
a ^. L.diagnostics `shouldSatisfy` hasOneDiag
147-
length actns `shouldBe` 5
148+
length actns `shouldBe` 10
148149

149150
executeCodeAction (head actns)
150151

@@ -160,9 +161,39 @@ spec = describe "code actions" $ do
160161

161162
contents <- getDocumentEdit doc
162163
liftIO $ do
163-
let l1:l2:_ = T.lines contents
164+
let l1:l2:l3:_ = T.lines contents
164165
l1 `shouldBe` "import qualified Data.Maybe"
165166
l2 `shouldBe` "import Control.Monad"
167+
l3 `shouldBe` "main :: IO ()"
168+
it "import-list formats with brittany" $ runSession hieCommand fullCaps "test/testdata" $ do
169+
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
170+
_ <- waitForDiagnosticsSource "ghcmod"
171+
172+
actionsOrCommands <- getAllCodeActions doc
173+
let _:action:_ = map fromAction actionsOrCommands
174+
executeCodeAction action
175+
176+
contents <- getDocumentEdit doc
177+
liftIO $ do
178+
let l1:l2:l3:_ = T.lines contents
179+
l1 `shouldBe` "import qualified Data.Maybe"
180+
l2 `shouldBe` "import Control.Monad ( when )"
181+
l3 `shouldBe` "main :: IO ()"
182+
it "import-list formats with floskell" $ runSession hieCommand fullCaps "test/testdata" $ do
183+
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
184+
_ <- waitForDiagnosticsSource "ghcmod"
185+
186+
actionsOrCommands <- getAllCodeActions doc
187+
let _:action:_ = map fromAction actionsOrCommands
188+
executeCodeAction action
189+
190+
contents <- getDocumentEdit doc
191+
liftIO $ do
192+
let l1:l2:l3:_ = T.lines contents
193+
l1 `shouldBe` "import qualified Data.Maybe"
194+
l2 `shouldBe` "import Control.Monad (when)"
195+
l3 `shouldBe` "main :: IO ()"
196+
-- TODO: repeated code actions
166197
it "respects format config" $ runSession hieCommand fullCaps "test/testdata" $ do
167198
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
168199
_ <- waitForDiagnosticsSource "ghcmod"
@@ -179,7 +210,22 @@ spec = describe "code actions" $ do
179210
let l1:l2:_ = T.lines contents
180211
l1 `shouldBe` "import qualified Data.Maybe"
181212
l2 `shouldBe` "import Control.Monad"
213+
it "import-list respects format config" $ runSession hieCommand fullCaps "test/testdata" $ do
214+
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
215+
_ <- waitForDiagnosticsSource "ghcmod"
216+
217+
let config = def { formatOnImportOn = False }
218+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
182219

220+
actionsOrCommands <- getAllCodeActions doc
221+
let _:action:_ = map fromAction actionsOrCommands
222+
executeCodeAction action
223+
224+
contents <- getDocumentEdit doc
225+
liftIO $ do
226+
let l1:l2:_ = T.lines contents
227+
l1 `shouldBe` "import qualified Data.Maybe"
228+
l2 `shouldBe` "import Control.Monad (when)"
183229
describe "add package suggestions" $ do
184230
it "adds to .cabal files" $ runSession hieCommand fullCaps "test/testdata/addPackageTest/cabal" $ do
185231
doc <- openDoc "AddPackage.hs" "haskell"

0 commit comments

Comments
 (0)