From: Luke Lau Date: Sun, 28 Apr 2019 22:46:51 +0000 (+0100) Subject: Export satisfy X-Git-Tag: 0.5.2.0 X-Git-Url: http://git.lukelau.me/?p=lsp-test.git;a=commitdiff_plain;h=ae9d99b56df5468816e476059f59537da18fab9c Export satisfy --- diff --git a/ChangeLog.md b/ChangeLog.md index 3af75a6..9397bfd 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Revision history for lsp-test +## 0.5.2.0 -- 2019-04-28 + +* Add `satisfy` parser combinator + ## 0.5.1.0 -- 2019-04-22 * Fix unhandled `window/progress` server notifications diff --git a/lsp-test.cabal b/lsp-test.cabal index dd90f8b..a55bc40 100644 --- a/lsp-test.cabal +++ b/lsp-test.cabal @@ -1,5 +1,5 @@ name: lsp-test -version: 0.5.1.4 +version: 0.5.2.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 1b24fb7..4a1936d 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -351,7 +351,7 @@ waitForDiagnosticsSource src = do matches d = d ^. source == Just (T.pack src) -- | Expects a 'PublishDiagnosticsNotification' and throws an --- 'UnexpectedDiagnosticsException' if there are any diagnostics +-- 'UnexpectedDiagnostics' exception if there are any diagnostics -- returned. noDiagnostics :: Session () noDiagnostics = do diff --git a/src/Language/Haskell/LSP/Test/Parsing.hs b/src/Language/Haskell/LSP/Test/Parsing.hs index 1fd394f..09006b6 100644 --- a/src/Language/Haskell/LSP/Test/Parsing.hs +++ b/src/Language/Haskell/LSP/Test/Parsing.hs @@ -5,7 +5,8 @@ module Language.Haskell.LSP.Test.Parsing ( -- $receiving - message + satisfy + , message , anyRequest , anyResponse , anyNotification @@ -60,6 +61,9 @@ import Language.Haskell.LSP.Test.Session -- anyResponse -- @ +-- | Consumes and returns the next message, if it satisfies the specified predicate. +-- +-- @since 0.5.2.0 satisfy :: (FromServerMessage -> Bool) -> Session FromServerMessage satisfy pred = do @@ -85,7 +89,7 @@ satisfy pred = do return x else empty --- | Matches a message of type 'a'. +-- | Matches a message of type @a@. message :: forall a. (Typeable a, FromJSON a) => Session a message = let parser = decode . encodeMsg :: FromServerMessage -> Maybe a diff --git a/src/Language/Haskell/LSP/Test/Session.hs b/src/Language/Haskell/LSP/Test/Session.hs index 700d9cc..291a3e0 100644 --- a/src/Language/Haskell/LSP/Test/Session.hs +++ b/src/Language/Haskell/LSP/Test/Session.hs @@ -68,9 +68,10 @@ import System.IO -- | A session representing one instance of launching and connecting to a server. -- --- You can send and receive messages to the server within 'Session' via 'getMessage', --- 'sendRequest' and 'sendNotification'. --- +-- You can send and receive messages to the server within 'Session' via +-- 'Language.Haskell.LSP.Test.message', +-- 'Language.Haskell.LSP.Test.sendRequest' and +-- 'Language.Haskell.LSP.Test.sendNotification'. type Session = ParserStateReader FromServerMessage SessionState SessionContext IO @@ -296,7 +297,7 @@ sendMessage msg = do logMsg LogClient msg liftIO $ B.hPut h (addHeader $ encode msg) --- | Execute a block f that will throw a 'TimeoutException' +-- | Execute a block f that will throw a 'Timeout' exception -- after duration seconds. This will override the global timeout -- for waiting for messages to arrive defined in 'SessionConfig'. withTimeout :: Int -> Session a -> Session a diff --git a/test/Test.hs b/test/Test.hs index 0fc2f53..377bb6d 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -319,6 +319,13 @@ main = hspec $ do documentContents doc >>= liftIO . print in sesh `shouldThrow` anyException + describe "satisfy" $ + it "works" $ runSession "hie" fullCaps "test/data" $ do + openDoc "Format.hs" "haskell" + let pred (NotLogMessage _) = True + pred _ = False + void $ satisfy pred + mkRange sl sc el ec = Range (Position sl sc) (Position el ec) didChangeCaps :: ClientCapabilities