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

Commit c54efd3

Browse files
committed
Adding tests
1 parent e5f9cfc commit c54efd3

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

test/functional/FunctionalCodeActionsSpec.hs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ import qualified Language.Haskell.LSP.Types.Capabilities as C
2020
import Test.Hspec
2121
import TestUtils
2222

23+
runSessionWithOnChange :: String -> C.ClientCapabilities -> FilePath -> Session a -> IO a
24+
runSessionWithOnChange cmd caps name test = runSession cmd caps name $ do
25+
let config = def { diagnosticsOnChange = True }
26+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
27+
test
28+
2329
spec :: Spec
2430
spec = describe "code actions" $ do
2531
describe "hlint suggestions" $ do
26-
it "provides 3.8 code actions" $ runSession hieCommand fullCaps "test/testdata" $ do
27-
doc <- openDoc "ApplyRefact2.hs" "haskell"
32+
it "provides 3.8 code actions" $ runSessionWithOnChange hieCommand fullCaps "test/testdata" $ do
2833

34+
doc <- openDoc "ApplyRefact2.hs" "haskell"
2935
diags@(reduceDiag:_) <- waitForDiagnostics
3036

3137
liftIO $ do
@@ -49,7 +55,7 @@ spec = describe "code actions" $ do
4955

5056
-- ---------------------------------
5157

52-
it "falls back to pre 3.8 code actions" $ runSession hieCommand noLiteralCaps "test/testdata" $ do
58+
it "falls back to pre 3.8 code actions" $ runSessionWithOnChange hieCommand noLiteralCaps "test/testdata" $ do
5359
doc <- openDoc "ApplyRefact2.hs" "haskell"
5460

5561
_ <- waitForDiagnostics
@@ -66,6 +72,33 @@ spec = describe "code actions" $ do
6672

6773
noDiagnostics
6874

75+
it "runs diagnostics on save" $ runSession hieCommand fullCaps "test/testdata" $ do
76+
let config = def { diagnosticsOnChange = False }
77+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
78+
79+
doc <- openDoc "ApplyRefact2.hs" "haskell"
80+
diags@(reduceDiag:_) <- waitForDiagnostics
81+
82+
liftIO $ do
83+
length diags `shouldBe` 2
84+
reduceDiag ^. L.range `shouldBe` Range (Position 1 0) (Position 1 12)
85+
reduceDiag ^. L.severity `shouldBe` Just DsInfo
86+
reduceDiag ^. L.code `shouldBe` Just "Eta reduce"
87+
reduceDiag ^. L.source `shouldBe` Just "hlint"
88+
89+
(CACodeAction ca:_) <- getAllCodeActions doc
90+
91+
-- Evaluate became redundant id in later hlint versions
92+
liftIO $ ["Apply hint:Redundant id", "Apply hint:Evaluate"] `shouldContain` [ca ^. L.title]
93+
94+
executeCodeAction ca
95+
96+
contents <- getDocumentEdit doc
97+
liftIO $ contents `shouldBe` "main = undefined\nfoo x = x\n"
98+
sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
99+
100+
noDiagnostics
101+
69102
-- -----------------------------------
70103

71104
describe "rename suggestions" $ do

0 commit comments

Comments
 (0)