@@ -41,7 +41,9 @@ main = hspec spec
4141spec :: Spec
4242spec = do
4343 describe " dispatcher" jsonSpec
44- describe " ResponseMessage" responseMessageSpec
44+ describe " RequestMessage" requestMessageSpec
45+ describe " ResponseMessage" responseMessageSpec
46+ describe " NotificationMesssage" notificationMessageSpec
4547
4648-- ---------------------------------------------------------------------
4749
@@ -61,16 +63,20 @@ jsonSpec = do
6163 `shouldNotBe` Nothing
6264
6365
66+ requestMessageSpec :: Spec
67+ requestMessageSpec = do
68+ describe " edge cases" $ do
69+ it " handles missing params field" $ do
70+ J. eitherDecode " { \" jsonrpc\" : \" 2.0\" , \" id\" : 15, \" method\" : \" shutdown\" }"
71+ `shouldBe` Right (TRequestMessage " 2.0" (IdInt 15 ) SMethod_Shutdown Nothing )
72+
6473responseMessageSpec :: Spec
6574responseMessageSpec = do
6675 describe " edge cases" $ do
6776 it " decodes result = null" $ do
6877 let input = " {\" jsonrpc\" : \" 2.0\" , \" id\" : 123, \" result\" : null}"
6978 in J. decode input `shouldBe` Just
7079 ((TResponseMessage " 2.0" (Just (IdInt 123 )) (Right $ InL J. Null )) :: TResponseMessage 'Method_WorkspaceExecuteCommand)
71- it " handles missing params field" $ do
72- J. eitherDecode " { \" jsonrpc\" : \" 2.0\" , \" id\" : 15, \" method\" : \" shutdown\" }"
73- `shouldBe` Right (TRequestMessage " 2.0" (IdInt 15 ) SMethod_Shutdown Nothing )
7480 describe " invalid JSON" $ do
7581 it " throws if neither result nor error is present" $ do
7682 (J. eitherDecode " {\" jsonrpc\" :\" 2.0\" ,\" id\" :1}" :: Either String (TResponseMessage 'Method_Initialize))
@@ -82,6 +88,13 @@ responseMessageSpec = do
8288 `shouldSatisfy `
8389 (either (\ err -> " Error in $: both error and result cannot be present" `isPrefixOf ` err ) (\ _ -> False ))
8490
91+ notificationMessageSpec :: Spec
92+ notificationMessageSpec = do
93+ describe " edge cases" $ do
94+ it " handles missing params field" $ do
95+ J. eitherDecode " { \" jsonrpc\" : \" 2.0\" , \" method\" : \" exit\" }"
96+ `shouldBe` Right (TNotificationMessage " 2.0" SMethod_Exit Nothing )
97+
8598-- ---------------------------------------------------------------------
8699
87100propertyJsonRoundtrip :: (Eq a , Show a , J. ToJSON a , J. FromJSON a ) => a -> Property
0 commit comments