Export satisfy 0.5.2.0
authorLuke Lau <luke_lau@icloud.com>
Sun, 28 Apr 2019 22:46:51 +0000 (23:46 +0100)
committerLuke Lau <luke_lau@icloud.com>
Sun, 28 Apr 2019 22:46:51 +0000 (23:46 +0100)
ChangeLog.md
lsp-test.cabal
src/Language/Haskell/LSP/Test.hs
src/Language/Haskell/LSP/Test/Parsing.hs
src/Language/Haskell/LSP/Test/Session.hs
test/Test.hs

index 3af75a6d1678271ad14bb4a4d868186ec4a8ef6d..9397bfde64d484a39456a7a6948e3d2d49588649 100644 (file)
@@ -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
index dd90f8bc379deb36ae1b1dba057128c522451198..a55bc40d3621927b2447c003770df47c9da32efb 100644 (file)
@@ -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
index 1b24fb74d11abea61c24c0b7e4f45bfd6b075419..4a1936db5e544a67ef57b7cb2db102f2252b5a18 100644 (file)
@@ -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
index 1fd394f3db1ee96a6810a25fa4e62e9be9f235e2..09006b67859957aedab3ac045a3926ad09598037 100644 (file)
@@ -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
index 700d9ccc84c233314f9c581bfd6bf8f810c8c1d5..291a3e0bcaa990327988f2bcbd9df6554a63f50f 100644 (file)
@@ -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
index 0fc2f53f73d2511b480a83b7ef770e83ba9acba9..377bb6d1f15fdedc36c3669e13263d2909322ab9 100644 (file)
@@ -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