From c4ec73caf11acd7e2c1b3c28bfafc8c5cdb1fca2 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 3 Aug 2021 17:46:33 +0200 Subject: add basic tests for renderResponse & parseResponse --- test/Cana/ProtocolSpec.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/Cana/ProtocolSpec.hs diff --git a/test/Cana/ProtocolSpec.hs b/test/Cana/ProtocolSpec.hs new file mode 100644 index 0000000..6effd25 --- /dev/null +++ b/test/Cana/ProtocolSpec.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE OverloadedStrings #-} +module Cana.ProtocolSpec where + +import Cana.Protocol +import Test.Hspec + +spec :: Spec +spec = do + describe "renderResponse" $ do + it "correctly renders a success response" $ do + let response = GeminiResponse + { responseStatus = codeSuccess + , responseMeta = "text/gemini" + , responseData = "# Hello World!" + } + wanted = "20 text/gemini\r\n# Hello World!" + renderResponse response `shouldBe` wanted + + describe "parseResponse" $ do + it "correctly parses a success response" $ do + let response = GeminiResponse + { responseStatus = codeSuccess + , responseMeta = "text/gemini" + , responseData = "# Hello World!" + } + wanted = "20 text/gemini\r\n# Hello World!" + parseResponse wanted `shouldBe` Just response -- cgit v1.2.3