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

Commit 32415b8

Browse files
committed
Fix tests
1 parent d6dedd3 commit 32415b8

File tree

1 file changed

+72
-64
lines changed

1 file changed

+72
-64
lines changed

test/functional/FunctionalCodeActionsSpec.hs

+72-64
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ spec = describe "code actions" $ do
139139
, "main = when True $ putStrLn \"hello\""
140140
]
141141
, -- Multiple import lists, should not introduce multiple newlines.
142-
[ "import Data.Maybe ( fromMaybe )"
143-
, "import Control.Monad ( when )"
144-
, "import System.IO ( hPutStrLn"
145-
, " , stdout"
142+
[ "import System.IO ( stdout"
143+
, " , hPutStrLn"
146144
, " )"
145+
, "import Control.Monad ( when )"
146+
, "import Data.Maybe ( fromMaybe )"
147+
, "main :: IO ()"
147148
, "main ="
148149
, " when True"
149150
, " $ hPutStrLn stdout"
@@ -164,9 +165,10 @@ spec = describe "code actions" $ do
164165
, "main = when True $ putStrLn \"hello\""
165166
]
166167
, -- Multiple import lists, should not introduce multiple newlines.
167-
[ "import Data.Maybe (fromMaybe)"
168+
[ "import System.IO (stdout, hPutStrLn)"
168169
, "import Control.Monad (when)"
169-
, "import System.IO (hPutStrLn, stdout)"
170+
, "import Data.Maybe (fromMaybe)"
171+
, "main :: IO ()"
170172
, "main ="
171173
, " when True"
172174
, " $ hPutStrLn stdout"
@@ -469,7 +471,7 @@ spec = describe "code actions" $ do
469471
-- Parameterized HsImport Spec.
470472
-- ---------------------------------------------------------------------
471473
hsImportSpec :: T.Text -> [[T.Text]]-> Spec
472-
hsImportSpec formatterName [e1, e2, _] =
474+
hsImportSpec formatterName [e1, e2, e3] =
473475
describe ("Execute HsImport with formatter " <> T.unpack formatterName) $ do
474476
it "works with 3.8 code action kinds" $ runSession hieCommand fullCaps "test/testdata" $ do
475477
doc <- openDoc "CodeActionImport.hs" "haskell"
@@ -529,50 +531,48 @@ hsImportSpec formatterName [e1, e2, _] =
529531
contents <- getDocumentEdit doc
530532
liftIO $ T.lines contents `shouldMatchList` e2
531533

532-
-- it "multiple import-list formats" $ runSession hieCommand fullCaps "test/testdata" $ do
533-
-- doc <- openDoc "CodeActionImportList.hs" "haskell"
534-
-- _ <- waitForDiagnosticsSource "ghcmod"
535-
536-
-- let config = def { formattingProvider = formatterName }
537-
-- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
538-
539-
-- let wantedCodeActionTitles = [ "Import module System.IO (hPutStrLn)"
540-
-- , "Import module System.IO (stdout)"
541-
-- , "Import module Control.Monad (when)"
542-
-- , "Import module Data.Maybe (fromMaybe)"
543-
-- ]
544-
545-
-- mapM_ (const (executeCodeActionByName doc wantedCodeActionTitles)) wantedCodeActionTitles
546-
547-
-- contents <- getDocumentEdit doc
548-
-- liftIO $ T.lines contents `shouldBe` e3
549-
550-
-- it "respects format config, multiple import-list" $ runSession hieCommand fullCaps "test/testdata" $ do
551-
-- doc <- openDoc "CodeActionImportList.hs" "haskell"
552-
-- _ <- waitForDiagnosticsSource "ghcmod"
553-
554-
-- let config = def { formatOnImportOn = False, formattingProvider = formatterName }
555-
-- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
556-
557-
-- let wantedCodeActionTitles = [ "Import module System.IO (hPutStrLn)"
558-
-- , "Import module System.IO (stdout)"
559-
-- , "Import module Control.Monad (when)"
560-
-- , "Import module Data.Maybe (fromMaybe)"
561-
-- ]
562-
563-
-- mapM_ (const (executeCodeActionByName doc wantedCodeActionTitles)) wantedCodeActionTitles
564-
565-
-- contents <- getDocumentEdit doc
566-
-- liftIO $ T.lines contents `shouldBe`
567-
-- [ "import Data.Maybe (fromMaybe)"
568-
-- , "import Control.Monad (when)"
569-
-- , "import System.IO (hPutStrLn, stdout)"
570-
-- , "main :: IO ()"
571-
-- , "main ="
572-
-- , "when True"
573-
-- , " $ hPutStrLn stdout"
574-
-- , " $ fromMaybe \"Good night, World!\" (Just \"Hello, World!\")]"
575-
-- ]
534+
it "multiple import-list formats" $ runSession hieCommand fullCaps "test/testdata" $ do
535+
doc <- openDoc "CodeActionImportList.hs" "haskell"
536+
537+
let config = def { formattingProvider = formatterName }
538+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
539+
540+
let wantedCodeActionTitles = [ "Import module System.IO (hPutStrLn)"
541+
, "Import module System.IO (stdout)"
542+
, "Import module Control.Monad (when)"
543+
, "Import module Data.Maybe (fromMaybe)"
544+
]
545+
546+
executeAllCodeActions doc wantedCodeActionTitles
547+
548+
contents <- documentContents doc
549+
liftIO $ T.lines contents `shouldBe` e3
550+
551+
it "respects format config, multiple import-list" $ runSession hieCommand fullCaps "test/testdata" $ do
552+
doc <- openDoc "CodeActionImportList.hs" "haskell"
553+
554+
let config = def { formatOnImportOn = False, formattingProvider = formatterName }
555+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
556+
557+
let wantedCodeActionTitles = [ "Import module System.IO (hPutStrLn)"
558+
, "Import module System.IO (stdout)"
559+
, "Import module Control.Monad (when)"
560+
, "Import module Data.Maybe (fromMaybe)"
561+
]
562+
563+
executeAllCodeActions doc wantedCodeActionTitles
564+
565+
contents <- documentContents doc
566+
liftIO $ T.lines contents `shouldBe`
567+
[ "import System.IO (stdout, hPutStrLn)"
568+
, "import Control.Monad (when)"
569+
, "import Data.Maybe (fromMaybe)"
570+
, "main :: IO ()"
571+
, "main ="
572+
, " when True"
573+
, " $ hPutStrLn stdout"
574+
, " $ fromMaybe \"Good night, World!\" (Just \"Hello, World!\")"
575+
]
576576
it "respects format config" $ runSession hieCommand fullCaps "test/testdata" $ do
577577
doc <- openDoc "CodeActionImportBrittany.hs" "haskell"
578578
_ <- waitForDiagnosticsSource "ghcmod"
@@ -610,19 +610,27 @@ hsImportSpec formatterName [e1, e2, _] =
610610
l2 `shouldBe` "import Control.Monad (when)"
611611
l3 `shouldBe` "main :: IO ()"
612612
l4 `shouldBe` "main = when True $ putStrLn \"hello\""
613-
-- where
614-
-- executeCodeActionByName :: TextDocumentIdentifier -> [T.Text] -> Session ()
615-
-- executeCodeActionByName doc names = do
616-
-- actionsOrCommands <- getAllCodeActions doc
617-
-- let allActions = map fromAction actionsOrCommands
618-
-- let actions = filter (\actn -> actn ^. L.title `elem` names) allActions
619-
-- case actions of
620-
-- (action:_) -> executeCodeAction action
621-
-- xs ->
622-
-- error
623-
-- $ "Found an unexpected amount of action. Expected 1, but got: "
624-
-- ++ show (length xs)
625-
-- ++ "\n. Titles: " ++ show (map (^. L.title) allActions)
613+
where
614+
executeAllCodeActions :: TextDocumentIdentifier -> [T.Text] -> Session ()
615+
executeAllCodeActions doc names =
616+
replicateM_ (length names) $ do
617+
_ <- waitForDiagnosticsSource "ghcmod"
618+
executeCodeActionByName doc names
619+
_ <- skipManyTill publishDiagnosticsNotification $ getDocumentEdit doc
620+
waitForDiagnosticsSource "ghcmod"
621+
622+
executeCodeActionByName :: TextDocumentIdentifier -> [T.Text] -> Session ()
623+
executeCodeActionByName doc names = do
624+
actionsOrCommands <- getAllCodeActions doc
625+
let allActions = map fromAction actionsOrCommands
626+
let actions = filter (\actn -> actn ^. L.title `elem` names) allActions
627+
case actions of
628+
(action:_) -> executeCodeAction action
629+
xs ->
630+
error
631+
$ "Found an unexpected amount of action. Expected 1, but got: "
632+
++ show (length xs)
633+
++ "\n. Titles: " ++ show (map (^. L.title) allActions)
626634

627635
-- Silence warnings
628636
hsImportSpec formatter args =

0 commit comments

Comments
 (0)