implemented editAnchor
This commit is contained in:
parent
06b768ce15
commit
994e2777c3
|
@ -29,6 +29,7 @@ module Helpers (
|
||||||
editHost,
|
editHost,
|
||||||
dropParam,
|
dropParam,
|
||||||
editParam,
|
editParam,
|
||||||
|
editAnchor,
|
||||||
incParamBy,
|
incParamBy,
|
||||||
incStrBy
|
incStrBy
|
||||||
) where
|
) where
|
||||||
|
@ -120,6 +121,19 @@ editParam pName f url = do
|
||||||
) $ params url
|
) $ params url
|
||||||
Just url { params = params' }
|
Just url { params = params' }
|
||||||
|
|
||||||
|
-- | Edit an anchor
|
||||||
|
editAnchor
|
||||||
|
:: (String -> Maybe String)
|
||||||
|
-- ^ the transformation function
|
||||||
|
-> Url
|
||||||
|
-- ^ the 'Url' being edited
|
||||||
|
-> Maybe Url
|
||||||
|
editAnchor f url = case anchor url of
|
||||||
|
Just a -> do
|
||||||
|
a' <- f a
|
||||||
|
Just url { anchor = Just a' }
|
||||||
|
Nothing -> Just url
|
||||||
|
|
||||||
-- | Increment a parameter of a 'Url' by a given amount (if possible)
|
-- | Increment a parameter of a 'Url' by a given amount (if possible)
|
||||||
incParamBy
|
incParamBy
|
||||||
:: Integer
|
:: Integer
|
||||||
|
|
|
@ -37,6 +37,7 @@ spec = do
|
||||||
editHostSpec
|
editHostSpec
|
||||||
dropParamSpec
|
dropParamSpec
|
||||||
editParamSpec
|
editParamSpec
|
||||||
|
editAnchorSpec
|
||||||
incParamBySpec
|
incParamBySpec
|
||||||
incStrBySpec
|
incStrBySpec
|
||||||
|
|
||||||
|
@ -151,6 +152,25 @@ editParamSpec = describe "editParam" $ mapM_
|
||||||
, ( "c", Nothing )
|
, ( "c", Nothing )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
editAnchorSpec :: Spec
|
||||||
|
editAnchorSpec = describe "editAnchor" $ mapM_
|
||||||
|
( \(desc, f, url, expected) -> context desc $
|
||||||
|
it ("should be " ++ show url) $
|
||||||
|
editAnchor f url `shouldBe` expected
|
||||||
|
)
|
||||||
|
|
||||||
|
-- description, function, url, expected
|
||||||
|
[ ( "reverse", Just . reverse, fooUrl, Just reversedUrl )
|
||||||
|
, ( "fail", const Nothing, fooUrl, Nothing )
|
||||||
|
, ( "reverse empty", Just . reverse, simpleUrl, Just simpleUrl )
|
||||||
|
, ( "fail empty", const Nothing, simpleUrl, Just simpleUrl )
|
||||||
|
]
|
||||||
|
|
||||||
|
where
|
||||||
|
fooUrl = urlWith "foo"
|
||||||
|
reversedUrl = urlWith "oof"
|
||||||
|
urlWith a = simpleUrl { anchor = Just a }
|
||||||
|
|
||||||
incParamBySpec :: Spec
|
incParamBySpec :: Spec
|
||||||
incParamBySpec = describe "incParamBy" $ mapM_
|
incParamBySpec = describe "incParamBy" $ mapM_
|
||||||
( \(desc, n, pName, expected) -> context desc $
|
( \(desc, n, pName, expected) -> context desc $
|
||||||
|
|
Loading…
Reference in New Issue
Block a user