1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
{-# Language ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main where
import Test.Hspec
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 = hspec spec
spec :: Spec
spec = do
describe "PathPiece" $ do
prop "toPathPiece <=> fromPathPiece String" $ \(p::String) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> null p
Just pConverted -> p == pConverted
prop "toPathPiece <=> fromPathPiece Text" $ \(p::T.Text) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> T.null p
Just pConverted -> p == pConverted
prop "toPathPiece <=> fromPathPiece Int" $ \(p::Int) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> False
Just pConverted -> p == pConverted
prop "toPathPiece <=> fromPathPiece Bool" $ \(p::Bool) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> False
Just pConverted -> p == pConverted
prop "toPathPiece <=> fromPathPiece Maybe String" $ \(p::Maybe String) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> False
Just pConverted -> p == pConverted
describe "PathMultiPiece" $ do
prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
prop "toPathMultiPiece <=> fromPathMultiPiece Text" $ \(p::[T.Text]) ->
p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
describe "SinglePiece" $ do
prop "toPathPiece <=> fromPathPiece String" $ \(p::String) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> null p
Just pConverted -> p == pConverted
prop "toPathPiece <=> fromPathPiece Text" $ \(p::T.Text) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> T.null p
Just pConverted -> p == pConverted
prop "toPathPiece <=> fromPathPiece Int" $ \(p::Int) ->
case (fromPathPiece . toPathPiece) p of
Nothing -> p < 0
Just pConverted -> p == pConverted
describe "MultiPiece" $ do
prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
prop "toPathMultiPiece <=> fromPathMultiPiece Text" $ \(p::[T.Text]) ->
p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
it "bad ints are rejected" $ fromPathPiece (T.pack "123hello")
`shouldBe` (Nothing :: Maybe Int)
|