Merge pull request #6 from axel-angel/bool
Instance PathPiece Bool with tests
commit9de36e94b0fe88086f7cb4417d904c6bc28010fd
authorGreg Weber <greg@gregweber.info>
dateWed 16 Apr 2014, 08:30 (13 years ago)
parentcc938d36646817
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