X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=test%2FTest.hs;h=d83d03d5082b2cc138b2ea9bcfb86b984954cdfd;hb=f6e14409afddc74ea8ffb1d852c316a5374caf2c;hp=16c8d01cdb57be9f4710a98df48ad00c121c6fa3;hpb=edee40c4aba2607c652cace2da780c373612665f;p=opengl.git diff --git a/test/Test.hs b/test/Test.hs index 16c8d01..d83d03d 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1,11 +1,18 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveAnyClass #-} import Test.Hspec +import Data.Aeson +import Data.Default +import qualified Data.HashMap.Strict as HM import Data.Maybe import Control.Monad.IO.Class import Control.Lens hiding (List) +import GHC.Generics import Language.Haskell.LSP.Test import Language.Haskell.LSP.Test.Replay +import Language.Haskell.LSP.TH.ClientCapabilities import Language.Haskell.LSP.Types import ParsingTests @@ -36,6 +43,15 @@ main = hspec $ do skipMany loggingNotification anyRequest in session `shouldThrow` anyException + it "can get initialize response" $ runSession "hie --lsp" "test/data/renamePass" $ do + rsp <- getInitializeResponse + liftIO $ rsp ^. result `shouldNotBe` Nothing + + it "can register specific capabilities" $ do + let caps = def { _workspace = Just workspaceCaps } + workspaceCaps = def { _didChangeConfiguration = Just configCaps } + configCaps = DidChangeConfigurationClientCapabilities (Just True) + runSessionWithCapabilities caps "hie --lsp" "test/data/renamePass" $ return () describe "replay session" $ do it "passes a test" $ @@ -58,8 +74,39 @@ main = hspec $ do fooSymbol ^. name `shouldBe` "foo" fooSymbol ^. kind `shouldBe` SkFunction + describe "text document state" $ + it "sends back didChange notifications" $ + runSession "hie --lsp" "test/data/refactor" $ do + doc <- openDoc "Main.hs" "haskell" + + let args = toJSON $ AOP (doc ^. uri) + (Position 1 14) + "Redundant bracket" + reqParams = ExecuteCommandParams "applyrefact:applyOne" (Just (List [args])) + sendRequest WorkspaceExecuteCommand reqParams + skipMany anyNotification + _ <- response :: Session ExecuteCommandResponse + + editReq <- request :: Session ApplyWorkspaceEditRequest + liftIO $ do + let (Just cs) = editReq ^. params . edit . changes + [(u, List es)] = HM.toList cs + u `shouldBe` doc ^. uri + es `shouldBe` [TextEdit (Range (Position 1 0) (Position 1 18)) "main = return 42"] + + checkNoDiagnostics + + contents <- documentContents doc + liftIO $ contents `shouldBe` "main :: IO Int\nmain = return 42" + parsingSpec +data ApplyOneParams = AOP + { file :: Uri + , start_pos :: Position + , hintTitle :: String + } deriving (Generic, ToJSON) + checkNoDiagnostics :: Session () checkNoDiagnostics = do diagsNot <- notification :: Session PublishDiagnosticsNotification