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

Commit fe8ed0c

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

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

test/functional/FunctionalCodeActionsSpec.hs

Lines changed: 69 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,59 @@ 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 "formats with floskell" $ runSession hieCommand fullCaps "test/testdata" $ do
169+
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
170+
_ <- waitForDiagnosticsSource "ghcmod"
171+
172+
let config = def { formattingProvider = "floskell" }
173+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
174+
175+
actionsOrCommands <- getAllCodeActions doc
176+
let action:_ = map fromAction actionsOrCommands
177+
executeCodeAction action
178+
179+
contents <- getDocumentEdit doc
180+
liftIO $ do
181+
let l1:l2:l3:_ = T.lines contents
182+
l1 `shouldBe` "import qualified Data.Maybe"
183+
l2 `shouldBe` "import Control.Monad"
184+
l3 `shouldBe` "main :: IO ()"
185+
it "import-list formats with brittany" $ runSession hieCommand fullCaps "test/testdata" $ do
186+
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
187+
_ <- waitForDiagnosticsSource "ghcmod"
188+
189+
actionsOrCommands <- getAllCodeActions doc
190+
let _:action:_ = map fromAction actionsOrCommands
191+
executeCodeAction action
192+
193+
contents <- getDocumentEdit doc
194+
liftIO $ do
195+
let l1:l2:l3:_ = T.lines contents
196+
l1 `shouldBe` "import qualified Data.Maybe"
197+
l2 `shouldBe` "import Control.Monad ( when )"
198+
l3 `shouldBe` "main :: IO ()"
199+
it "import-list formats with floskell" $ runSession hieCommand fullCaps "test/testdata" $ do
200+
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
201+
_ <- waitForDiagnosticsSource "ghcmod"
202+
203+
let config = def { formattingProvider = "floskell" }
204+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
205+
206+
actionsOrCommands <- getAllCodeActions doc
207+
let _:action:_ = map fromAction actionsOrCommands
208+
executeCodeAction action
209+
210+
contents <- getDocumentEdit doc
211+
liftIO $ do
212+
let l1:l2:l3:_ = T.lines contents
213+
l1 `shouldBe` "import qualified Data.Maybe"
214+
l2 `shouldBe` "import Control.Monad (when)"
215+
l3 `shouldBe` "main :: IO ()"
216+
-- TODO: repeated code actions
166217
it "respects format config" $ runSession hieCommand fullCaps "test/testdata" $ do
167218
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
168219
_ <- waitForDiagnosticsSource "ghcmod"
@@ -179,7 +230,22 @@ spec = describe "code actions" $ do
179230
let l1:l2:_ = T.lines contents
180231
l1 `shouldBe` "import qualified Data.Maybe"
181232
l2 `shouldBe` "import Control.Monad"
233+
it "import-list respects format config" $ runSession hieCommand fullCaps "test/testdata" $ do
234+
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
235+
_ <- waitForDiagnosticsSource "ghcmod"
236+
237+
let config = def { formatOnImportOn = False }
238+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
182239

240+
actionsOrCommands <- getAllCodeActions doc
241+
let _:action:_ = map fromAction actionsOrCommands
242+
executeCodeAction action
243+
244+
contents <- getDocumentEdit doc
245+
liftIO $ do
246+
let l1:l2:_ = T.lines contents
247+
l1 `shouldBe` "import qualified Data.Maybe"
248+
l2 `shouldBe` "import Control.Monad (when)"
183249
describe "add package suggestions" $ do
184250
it "adds to .cabal files" $ runSession hieCommand fullCaps "test/testdata/addPackageTest/cabal" $ do
185251
doc <- openDoc "AddPackage.hs" "haskell"

0 commit comments

Comments
 (0)