Instance PathPiece Bool with tests
commit6646817f0725baa272a6b184b8db6e38d632e20b
authorAxel Angel <axel+git@vneko.ch>
dateSun 13 Apr 2014, 17:30 (13 years ago)
parentcc938d3
Web/PathPieces.hs+7
@@ -45,6 +45,13 @@ instance PathPiece Int where
4545 Left _ -> Nothing
4646 toPathPiece = S.pack . show
4747
48+instance PathPiece Bool where
49+ fromPathPiece t =
50+ case reads $ S.unpack t of
51+ [(a,"")] -> Just a
52+ _ -> Nothing
53+ toPathPiece = S.pack . show
54+
4855instance PathPiece Int64 where
4956 fromPathPiece s =
5057 case Data.Text.Read.signed Data.Text.Read.decimal s of
test/main.hs+5
@@ -37,6 +37,11 @@ spec = do
3737 Nothing -> False
3838 Just pConverted -> p == pConverted
3939
40+ prop "toPathPiece <=> fromPathPiece String" $ \(p::Bool) ->
41+ case (fromPathPiece . toPathPiece) p of
42+ Nothing -> False
43+ Just pConverted -> p == pConverted
44+
4045 describe "PathMultiPiece" $ do
4146 prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
4247 p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p