implemented Handlers.i
This commit is contained in:
parent
34ac2a2a00
commit
515109f45d
|
@ -28,7 +28,8 @@ module Helpers (
|
|||
makeHttps,
|
||||
editHost,
|
||||
dropParam,
|
||||
editParam
|
||||
editParam,
|
||||
incStrBy
|
||||
) where
|
||||
|
||||
import qualified Data.List as L
|
||||
|
@ -118,6 +119,18 @@ editParam pName f url = do
|
|||
) $ params url
|
||||
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 text = case T.splitOn "://" text of
|
||||
[protT, raw] -> do
|
||||
|
|
|
@ -37,6 +37,7 @@ spec = do
|
|||
editHostSpec
|
||||
dropParamSpec
|
||||
editParamSpec
|
||||
incStrBySpec
|
||||
|
||||
textToUrlSpec :: Spec
|
||||
textToUrlSpec = describe "textToUrl" $ mapM_
|
||||
|
@ -149,6 +150,20 @@ editParamSpec = describe "editParam" $ mapM_
|
|||
, ( "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 = "http://example.com/"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user