gemcap/test/Network/GemServSpec.hs
Jonathan Lamothe d56116d4c9 implemented encodeRequest
Note: this does not yet handle percent-escaped characters
2021-10-22 14:29:15 -04:00

59 lines
1.8 KiB
Haskell

{-
gemserv
Cooyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see
<https://www.gnu.org/licenses/>.
-}
module Network.GemServSpec (spec) where
import Test.Hspec (Spec, context, describe, it, shouldBe)
import Network.GemServ
import Network.GemServ.Types
spec :: Spec
spec = describe "Network.GemServ"
encodeRequestSpec
encodeRequestSpec :: Spec
encodeRequestSpec = describe "encodeRequest" $ mapM_
( \(desc, req, expected) -> context desc $
it ("should be " ++ show expected) $
encodeRequest req `shouldBe` expected
)
-- description, request, expected
[ ( "simple", simpleReq, simpleExp )
, ( "with port", withPortReq, withPortExp )
, ( "with path", withPathReq, withPathExp )
, ( "with query", withQueryReq, withQueryExp )
]
where
simpleReq = newRequest "example.com"
simpleExp = "gemini://example.com/"
withPortReq = simpleReq { reqPort = Just 1965 }
withPortExp = "gemini://example.com:1965/"
withPathReq = simpleReq { reqPath = ["foo", "bar"] }
withPathExp = "gemini://example.com/foo/bar"
withQueryReq = simpleReq { reqQuery = "foo" }
withQueryExp = "gemini://example.com/?foo"
--jl