implemented Helpers.incParamBy
This commit is contained in:
parent
515109f45d
commit
06b768ce15
|
@ -29,6 +29,7 @@ module Helpers (
|
|||
editHost,
|
||||
dropParam,
|
||||
editParam,
|
||||
incParamBy,
|
||||
incStrBy
|
||||
) where
|
||||
|
||||
|
@ -119,6 +120,17 @@ editParam pName f url = do
|
|||
) $ params url
|
||||
Just url { params = params' }
|
||||
|
||||
-- | Increment a parameter of a 'Url' by a given amount (if possible)
|
||||
incParamBy
|
||||
:: Integer
|
||||
-- ^ the amount to increment by
|
||||
-> String
|
||||
-- ^ the parameter
|
||||
-> Url
|
||||
-- ^ the 'Url' to edit
|
||||
-> Maybe Url
|
||||
incParamBy n p = editParam p $ incStrBy n
|
||||
|
||||
-- | Increment a 'String' representation of an 'Integer' by a given
|
||||
-- amount (if possible)
|
||||
incStrBy
|
||||
|
|
|
@ -37,6 +37,7 @@ spec = do
|
|||
editHostSpec
|
||||
dropParamSpec
|
||||
editParamSpec
|
||||
incParamBySpec
|
||||
incStrBySpec
|
||||
|
||||
textToUrlSpec :: Spec
|
||||
|
@ -150,6 +151,29 @@ editParamSpec = describe "editParam" $ mapM_
|
|||
, ( "c", Nothing )
|
||||
]
|
||||
|
||||
incParamBySpec :: Spec
|
||||
incParamBySpec = describe "incParamBy" $ mapM_
|
||||
( \(desc, n, pName, expected) -> context desc $
|
||||
it ("should be " ++ show expected) $
|
||||
incParamBy n pName url `shouldBe` expected
|
||||
)
|
||||
|
||||
-- description, number, param, expected
|
||||
[ ( "+1", 1, "a", Just $ urlWith "3" )
|
||||
, ( "+2", 2, "a", Just $ urlWith "4" )
|
||||
, ( "non-numeric", 1, "c", Nothing )
|
||||
, ( "missing", 1, "d", Just url )
|
||||
]
|
||||
|
||||
where
|
||||
url = urlWith "2"
|
||||
urlWith n = simpleUrl { params = mkParams n }
|
||||
mkParams n =
|
||||
[ ( "a", Just n )
|
||||
, ( "b", Just "2" )
|
||||
, ( "c", Just "foo" )
|
||||
]
|
||||
|
||||
incStrBySpec :: Spec
|
||||
incStrBySpec = describe "incStrBy" $ mapM_
|
||||
( \(n, str, expected) ->
|
||||
|
|
Loading…
Reference in New Issue
Block a user