implemented Handlers.i

This commit is contained in:
Jonathan Lamothe 2021-09-22 18:19:51 -04:00
parent 34ac2a2a00
commit 515109f45d
2 changed files with 29 additions and 1 deletions

View File

@ -28,7 +28,8 @@ module Helpers (
makeHttps, makeHttps,
editHost, editHost,
dropParam, dropParam,
editParam editParam,
incStrBy
) where ) where
import qualified Data.List as L import qualified Data.List as L
@ -118,6 +119,18 @@ editParam pName f url = do
) $ params url ) $ params url
Just url { params = params' } Just url { params = params' }
-- | Increment a 'String' representation of an 'Integer' by a given
-- amount (if possible)
incStrBy
:: Integer
-- ^ the amount to increment by
-> String
-- ^ the 'String' to increment
-> Maybe String
incStrBy n str = case reads str of
[(m, "")] -> Just $ show $ n + m
_ -> Nothing
subToUrl :: T.Text -> Maybe Url subToUrl :: T.Text -> Maybe Url
subToUrl text = case T.splitOn "://" text of subToUrl text = case T.splitOn "://" text of
[protT, raw] -> do [protT, raw] -> do

View File

@ -37,6 +37,7 @@ spec = do
editHostSpec editHostSpec
dropParamSpec dropParamSpec
editParamSpec editParamSpec
incStrBySpec
textToUrlSpec :: Spec textToUrlSpec :: Spec
textToUrlSpec = describe "textToUrl" $ mapM_ textToUrlSpec = describe "textToUrl" $ mapM_
@ -149,6 +150,20 @@ editParamSpec = describe "editParam" $ mapM_
, ( "c", Nothing ) , ( "c", Nothing )
] ]
incStrBySpec :: Spec
incStrBySpec = describe "incStrBy" $ mapM_
( \(n, str, expected) ->
context (show str ++ " + " ++ show n) $
it ("should be " ++ show expected) $
incStrBy n str `shouldBe` expected
)
-- number, string, expected
[ ( 2, "3", Just "5" )
, ( 2, "foo", Nothing )
, ( 2, "", Nothing )
]
simpleTxt :: T.Text simpleTxt :: T.Text
simpleTxt = "http://example.com/" simpleTxt = "http://example.com/"