git.iko.soy/typeable/http-api-data
on master help sign in
Clean up tests, add tests for more types
commitc1834ae4648c12fb4accfb7ec8b2227b8497ded6 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSun 4 Oct 2015, 03:58 (11 years ago) parent4e21977
2 files changed+38−58
http-api-data.cabal+1 test/main.hs+37−58
http-api-data.cabal+1
@@ -37,6 +37,7 @@ test-suite test
3737 , QuickCheck
3838 , http-api-data
3939 , text
40+ , time
4041
4142source-repository head
4243 type: git
test/main.hs+37−58
@@ -2,81 +2,60 @@
22{-# OPTIONS_GHC -fno-warn-orphans #-}
33module Main where
44
5+import Control.Applicative
6+
7+import Data.Int
8+import Data.Word
9+import Data.Time
10+import qualified Data.Text as T
11+import qualified Data.Text.Lazy as L
12+
513import Test.Hspec
614import Test.Hspec.QuickCheck(prop)
715import Test.QuickCheck
816
917import Web.PathPieces
10−import qualified Data.Text as T
11−import Data.Maybe (fromJust)
12−
13−-- import FileLocation (debug)
1418
1519instance Arbitrary T.Text where
16− arbitrary = fmap T.pack arbitrary
20+ arbitrary = T.pack <$> arbitrary
1721
22+instance Arbitrary L.Text where
23+ arbitrary = L.pack <$> arbitrary
24+
25+instance Arbitrary Day where
26+ arbitrary = liftA3 fromGregorian (fmap abs arbitrary) arbitrary arbitrary
1827
1928main :: IO ()
2029main = hspec spec
2130
31+(<=>) :: Eq a => (a -> b) -> (b -> Maybe a) -> a -> Bool
32+(f <=> g) x = g (f x) == Just x
33+
2234spec :: Spec
2335spec = do
2436 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
29−
30− prop "toPathPiece <=> fromPathPiece Text" $ \(p::T.Text) ->
31− case (fromPathPiece . toPathPiece) p of
32− Nothing -> T.null p
33− Just pConverted -> p == pConverted
34−
35− prop "toPathPiece <=> fromPathPiece Int" $ \(p::Int) ->
36− case (fromPathPiece . toPathPiece) p of
37− Nothing -> False
38− Just pConverted -> p == pConverted
39−
40− prop "toPathPiece <=> fromPathPiece Bool" $ \(p::Bool) ->
41− case (fromPathPiece . toPathPiece) p of
42− Nothing -> False
43− Just pConverted -> p == pConverted
44−
45− prop "toPathPiece <=> fromPathPiece Maybe String" $ \(p::Maybe String) ->
46− case (fromPathPiece . toPathPiece) p of
47− Nothing -> False
48− Just pConverted -> p == pConverted
37+ prop "toPathPiece <=> fromPathPiece Bool" $ \(p :: Bool) -> (toPathPiece <=> fromPathPiece) p
38+ prop "toPathPiece <=> fromPathPiece Int" $ \(p :: Int) -> (toPathPiece <=> fromPathPiece) p
39+ prop "toPathPiece <=> fromPathPiece Int8" $ \(p :: Int8) -> (toPathPiece <=> fromPathPiece) p
40+ prop "toPathPiece <=> fromPathPiece Int16" $ \(p :: Int16) -> (toPathPiece <=> fromPathPiece) p
41+ prop "toPathPiece <=> fromPathPiece Int32" $ \(p :: Int32) -> (toPathPiece <=> fromPathPiece) p
42+ prop "toPathPiece <=> fromPathPiece Word" $ \(p :: Word) -> (toPathPiece <=> fromPathPiece) p
43+ prop "toPathPiece <=> fromPathPiece Word8" $ \(p :: Word8) -> (toPathPiece <=> fromPathPiece) p
44+ prop "toPathPiece <=> fromPathPiece Word16" $ \(p :: Word16) -> (toPathPiece <=> fromPathPiece) p
45+ prop "toPathPiece <=> fromPathPiece Word32" $ \(p :: Word32) -> (toPathPiece <=> fromPathPiece) p
46+ prop "toPathPiece <=> fromPathPiece Word64" $ \(p :: Word64) -> (toPathPiece <=> fromPathPiece) p
47+ prop "toPathPiece <=> fromPathPiece Word64" $ \(p :: Word64) -> (toPathPiece <=> fromPathPiece) p
48+ prop "toPathPiece <=> fromPathPiece String" $ \(p :: String) -> (toPathPiece <=> fromPathPiece) p
49+ prop "toPathPiece <=> fromPathPiece Text.Strict" $ \(p :: T.Text) -> (toPathPiece <=> fromPathPiece) p
50+ prop "toPathPiece <=> fromPathPiece Text.Lazy" $ \(p :: L.Text) -> (toPathPiece <=> fromPathPiece) p
51+ prop "toPathPiece <=> fromPathPiece Day" $ \(p :: Day) -> (toPathPiece <=> fromPathPiece) p
52+
53+ prop "toPathPiece <=> fromPathPiece Maybe String" $ \(p::Maybe String) -> (toPathPiece <=> fromPathPiece) p
4954
5055 describe "PathMultiPiece" $ do
51− prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
52− p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
53−
54− prop "toPathMultiPiece <=> fromPathMultiPiece Text" $ \(p::[T.Text]) ->
55− p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
56−
57−
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
63−
64− prop "toPathPiece <=> fromPathPiece Text" $ \(p::T.Text) ->
65− case (fromPathPiece . toPathPiece) p of
66− Nothing -> T.null p
67− Just pConverted -> p == pConverted
68−
69− prop "toPathPiece <=> fromPathPiece Int" $ \(p::Int) ->
70− case (fromPathPiece . toPathPiece) p of
71− Nothing -> p < 0
72− Just pConverted -> p == pConverted
73−
74− describe "MultiPiece" $ do
75− prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) ->
76− p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
77−
78− prop "toPathMultiPiece <=> fromPathMultiPiece Text" $ \(p::[T.Text]) ->
79− p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p
56+ prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) -> (toPathMultiPiece <=> fromPathMultiPiece) p
57+ prop "toPathMultiPiece <=> fromPathMultiPiece Text" $ \(p::[T.Text]) -> (toPathMultiPiece <=> fromPathMultiPiece) p
8058
8159 it "bad ints are rejected" $ fromPathPiece (T.pack "123hello")
8260 `shouldBe` (Nothing :: Maybe Int)
61+