implemented decodeGemURL

This commit is contained in:
2021-10-24 22:04:56 -04:00
parent a5d0c25fc3
commit 00142e91d6
2 changed files with 90 additions and 1 deletions

View File

@@ -30,6 +30,7 @@ import Network.GemServ.Types
spec :: Spec
spec = describe "Network.GemServ" $ do
encodeGemURLSpec
decodeGemURLSpec
escapeStringSpec
unescapeStringSpec
@@ -68,6 +69,50 @@ encodeGemURLSpec = describe "encodeGemURL" $ mapM_
withEscapeExp = "gemini://example.com/foo%20bar?baz%20quux"
decodeGemURLSpec :: Spec
decodeGemURLSpec = describe "decodeGemURL" $ mapM_
( \(str, expected) -> context (show str) $
it ("should be " ++ show expected) $
decodeGemURL str `shouldBe` expected
)
-- URL string, expected
[ ( simpleStr, Just simpleURL )
, ( withSlashStr, Just simpleURL )
, ( withPathStr, Just withPathURL )
, ( withQueryStr, Just withQueryURL )
, ( pathQueryStr, Just pathQueryURL )
, ( blankQueryStr, Just blankQueryURL )
, ( withFragmentStr, Just simpleURL )
, ( escapedStr, Just escapedURL )
, ( httpStr, Nothing )
, ( malformed, Nothing )
, ( "", Nothing )
]
where
simpleStr = "gemini://example.com"
simpleURL = newGemURL "example.com"
withSlashStr = simpleStr ++ "/"
withPathStr = simpleStr ++ "/foo/bar"
withPathURL = simpleURL { gemPath = ["foo", "bar"] }
withQueryStr = simpleStr ++ "?foo"
withQueryURL = simpleURL { gemQuery = Just "foo" }
pathQueryStr = withPathStr ++ "?baz"
pathQueryURL = withPathURL { gemQuery = Just "baz" }
blankQueryStr = simpleStr ++"?"
blankQueryURL = simpleURL { gemQuery = Just "" }
withFragmentStr = simpleStr ++ "#foo"
escapedStr = simpleStr ++ "/foo%20bar/baz?quux%20stuff"
escapedURL = simpleURL
{ gemPath = ["foo bar", "baz"]
, gemQuery = Just "quux stuff"
}
httpStr = "http://example.com"
malformed = "foo"
escapeStringSpec :: Spec
escapeStringSpec = describe "escapeString" $ mapM_
( \(input, expected) -> context (show input) $