path-pieces 0.1.0 → 0.1.1
raw patch · 3 files changed
+9/−72 lines, 3 filesdep +time
Dependencies added: time
Files
- Web/PathPieces.hs +7/−0
- path-pieces.cabal +2/−2
- test/main.hs +0/−70
Web/PathPieces.hs view
@@ -13,6 +13,7 @@ import qualified Data.Text as S import qualified Data.Text.Lazy as L import qualified Data.Text.Read+import Data.Time (Day) class PathPiece s where fromPathPiece :: S.Text -> Maybe s@@ -51,6 +52,12 @@ Left _ -> Nothing toPathPiece = S.pack . show +instance PathPiece Day where+ fromPathPiece t =+ case reads $ S.unpack t of+ [(a,"")] -> Just a+ _ -> Nothing+ toPathPiece = S.pack . show class PathMultiPiece s where fromPathMultiPiece :: [S.Text] -> Maybe s
path-pieces.cabal view
@@ -1,5 +1,5 @@ name: path-pieces-version: 0.1.0+version: 0.1.1 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -10,11 +10,11 @@ cabal-version: >= 1.8 build-type: Simple homepage: http://github.com/snoyberg/path-pieces-extra-source-files: test/main.hs library build-depends: base >= 4 && < 5 , text >= 0.5 && < 0.12+ , time exposed-modules: Web.PathPieces ghc-options: -Wall
− test/main.hs
@@ -1,70 +0,0 @@-{-# Language ScopedTypeVariables #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-module Main where--import Test.Hspec.Monadic (Specs, describe, hspecX)-import Test.Hspec.HUnit()-import Test.Hspec.QuickCheck(prop)-import Test.QuickCheck--import Web.PathPieces-import qualified Data.Text as T-import Data.Maybe (fromJust)---- import FileLocation (debug)--instance Arbitrary T.Text where- arbitrary = fmap T.pack arbitrary---main :: IO ()-main = hspecX specs--specs :: Specs-specs = do- describe "RoutePiece" $ do- prop "toRoutePiece <=> fromSinglePiece String" $ \(p::String) ->- case (fromRoutePiece . toSinglePiece) p of- Nothing -> null p- Just pConverted -> p == pConverted-- prop "toRoutePiece <=> fromSinglePiece String" $ \(p::T.Text) ->- case (fromRoutePiece . toSinglePiece) p of- Nothing -> T.null p- Just pConverted -> p == pConverted-- prop "toRoutePiece <=> fromSinglePiece String" $ \(p::Int) ->- case (fromRoutePiece . toSinglePiece) p of- Nothing -> p < 0- Just pConverted -> p == pConverted-- describe "RouteMultiPiece" $ do- prop "toRouteMultiPiece <=> fromMultiPiece String" $ \(p::[String]) ->- p == (fromJust . fromRouteMultiPiece . toMultiPiece) p-- prop "toRouteMultiPiece <=> fromMultiPiece String" $ \(p::[T.Text]) ->- p == (fromJust . fromRouteMultiPiece . toMultiPiece) p--- describe "SinglePiece" $ do- prop "toSinglePiece <=> fromSinglePiece String" $ \(p::String) ->- case (fromSinglePiece . toSinglePiece) p of- Nothing -> null p- Just pConverted -> p == pConverted-- prop "toSinglePiece <=> fromSinglePiece String" $ \(p::T.Text) ->- case (fromSinglePiece . toSinglePiece) p of- Nothing -> T.null p- Just pConverted -> p == pConverted-- prop "toSinglePiece <=> fromSinglePiece String" $ \(p::Int) ->- case (fromSinglePiece . toSinglePiece) p of- Nothing -> p < 0- Just pConverted -> p == pConverted-- describe "MultiPiece" $ do- prop "toMultiPiece <=> fromMultiPiece String" $ \(p::[String]) ->- p == (fromJust . fromMultiPiece . toMultiPiece) p-- prop "toMultiPiece <=> fromMultiPiece String" $ \(p::[T.Text]) ->- p == (fromJust . fromMultiPiece . toMultiPiece) p