2022-01-11 08:50:44 +00:00
|
|
|
-- {-# LANGUAGE OverloadedLists #-}
|
|
|
|
-- {-# LANGUAGE OverloadedStrings #-}
|
2021-07-04 18:42:24 +01:00
|
|
|
|
|
|
|
module ProtocolTests where
|
|
|
|
|
2022-01-11 08:50:44 +00:00
|
|
|
-- import Data.ByteString.Char8 (ByteString)
|
|
|
|
-- import Simplex.Chat.Protocol.Legacy
|
|
|
|
-- import Simplex.Messaging.Parsers (parseAll)
|
|
|
|
-- import Test.Hspec
|
2021-07-04 18:42:24 +01:00
|
|
|
|
2022-01-11 08:50:44 +00:00
|
|
|
-- protocolTests :: Spec
|
|
|
|
-- protocolTests = do
|
|
|
|
-- parseChatMessageTest
|
2021-07-04 18:42:24 +01:00
|
|
|
|
2022-01-11 08:50:44 +00:00
|
|
|
-- (#==) :: ByteString -> RawChatMessage -> Expectation
|
|
|
|
-- s #== msg = parseAll rawChatMessageP s `shouldBe` Right msg
|
2021-07-04 18:42:24 +01:00
|
|
|
|
2022-01-11 08:50:44 +00:00
|
|
|
-- parseChatMessageTest :: Spec
|
|
|
|
-- parseChatMessageTest = describe "Raw chat message format" $ do
|
|
|
|
-- it "no parameters and content" $
|
|
|
|
-- "5 x.grp.mem.leave " #== RawChatMessage "x.grp.mem.leave" [] []
|
|
|
|
-- it "one parameter, no content" $
|
|
|
|
-- "6 x.msg.del 3 " #== RawChatMessage "x.msg.del" ["3"] []
|
|
|
|
-- it "with content that fits the message" $
|
|
|
|
-- "7 x.msg.new c.text x.text:11 hello there "
|
|
|
|
-- #== RawChatMessage
|
|
|
|
-- "x.msg.new"
|
|
|
|
-- ["c.text"]
|
|
|
|
-- [RawMsgBodyContent (RawContentType "x" "text") "hello there"]
|
|
|
|
-- it "with DAG reference and partial content" $
|
|
|
|
-- "8 x.msg.new c.image x.dag:16,x.text:7,m.image/jpg:6 0123456789012345 picture abcdef "
|
|
|
|
-- #== RawChatMessage
|
|
|
|
-- "x.msg.new"
|
|
|
|
-- ["c.image"]
|
|
|
|
-- [ RawMsgBodyContent (RawContentType "x" "dag") "0123456789012345",
|
|
|
|
-- RawMsgBodyContent (RawContentType "x" "text") "picture",
|
|
|
|
-- RawMsgBodyContent (RawContentType "m" "image/jpg") "abcdef"
|
|
|
|
-- ]
|
|
|
|
-- it "without message id" $
|
|
|
|
-- " x.grp.mem.inv 23456,123 x.json:46 {\"contactRef\":\"john\",\"displayName\":\"John Doe\"} "
|
|
|
|
-- #== RawChatMessage
|
|
|
|
-- "x.grp.mem.inv"
|
|
|
|
-- ["23456", "123"]
|
|
|
|
-- [RawMsgBodyContent (RawContentType "x" "json") "{\"contactRef\":\"john\",\"displayName\":\"John Doe\"}"]
|