git.iko.soy/typeable/http-api-data
on master help sign in
Merge pull request #6 from axel-angel/bool
9de36e9Greg Weber
Web/PathPieces.hs+7
@@ -45,6 +45,13 @@ instance PathPiece Int where
45 Left _ -> Nothing
45 Left _ -> Nothing
46 toPathPiece = S.pack . show
46 toPathPiece = S.pack . show
47
47
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+
48instance PathPiece Int64 where
55instance PathPiece Int64 where
49 fromPathPiece s =
56 fromPathPiece s =
50 case Data.Text.Read.signed Data.Text.Read.decimal s of
57 case Data.Text.Read.signed Data.Text.Read.decimal s of
test/main.hs+5
@@ -37,6 +37,11 @@ spec = do
37 Nothing -> False
37 Nothing -> False
38 Just pConverted -> p == pConverted
38 Just pConverted -> p == pConverted
39
39
40+ prop "toPathPiece <=> fromPathPiece String" $ \(p::Bool) ->
41+ case (fromPathPiece . toPathPiece) p of
42+ Nothing -> False
43+ Just pConverted -> p == pConverted
44+
40 describe "PathMultiPiece" $ do
45 describe "PathMultiPiece" $ do
41 prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
46 prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
42 p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
47 p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p