git.iko.soy/typeable/http-api-data
on 2a9e081 help sign in
82 lines 2.7 kB history raw
1{-# Language ScopedTypeVariables #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
3module Main where
5import Test.Hspec
6import Test.Hspec.QuickCheck(prop)
7import Test.QuickCheck
9import Web.PathPieces
10import qualified Data.Text as T
11import Data.Maybe (fromJust)
13-- import FileLocation (debug)
15instance Arbitrary T.Text where
16 arbitrary = fmap T.pack arbitrary
19main :: IO ()
20main = hspec spec
22spec :: Spec
23spec = do
24 describe "PathPiece" $ do
25 prop "toPathPiece <=> fromPathPiece String" $ \(p::String) ->
26 case (fromPathPiece . toPathPiece) p of
27 Nothing -> null p
28 Just pConverted -> p == pConverted
30 prop "toPathPiece <=> fromPathPiece Text" $ \(p::T.Text) ->
31 case (fromPathPiece . toPathPiece) p of
32 Nothing -> T.null p
33 Just pConverted -> p == pConverted
35 prop "toPathPiece <=> fromPathPiece Int" $ \(p::Int) ->
36 case (fromPathPiece . toPathPiece) p of
37 Nothing -> False
38 Just pConverted -> p == pConverted
40 prop "toPathPiece <=> fromPathPiece Bool" $ \(p::Bool) ->
41 case (fromPathPiece . toPathPiece) p of
42 Nothing -> False
43 Just pConverted -> p == pConverted
45 prop "toPathPiece <=> fromPathPiece Maybe String" $ \(p::Maybe String) ->
46 case (fromPathPiece . toPathPiece) p of
47 Nothing -> False
48 Just pConverted -> p == pConverted
50 describe "PathMultiPiece" $ do
51 prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
52 p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
54 prop "toPathMultiPiece <=> fromPathMultiPiece Text" $ \(p::[T.Text]) ->
55 p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
58 describe "SinglePiece" $ do
59 prop "toPathPiece <=> fromPathPiece String" $ \(p::String) ->
60 case (fromPathPiece . toPathPiece) p of
61 Nothing -> null p
62 Just pConverted -> p == pConverted
64 prop "toPathPiece <=> fromPathPiece Text" $ \(p::T.Text) ->
65 case (fromPathPiece . toPathPiece) p of
66 Nothing -> T.null p
67 Just pConverted -> p == pConverted
69 prop "toPathPiece <=> fromPathPiece Int" $ \(p::Int) ->
70 case (fromPathPiece . toPathPiece) p of
71 Nothing -> p < 0
72 Just pConverted -> p == pConverted
74 describe "MultiPiece" $ do
75 prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
76 p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
78 prop "toPathMultiPiece <=> fromPathMultiPiece Text" $ \(p::[T.Text]) ->
79 p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
81 it "bad ints are rejected" $ fromPathPiece (T.pack "123hello")
82 `shouldBe` (Nothing :: Maybe Int)