@@ -16,6 +16,7 @@ import "unordered-containers" Data.HashSet (HashSet)
16import qualified "unordered-containers" Data.HashSet as HashSet
16import qualified "unordered-containers" Data.HashSet as HashSet
17import Data.HashMap.Strict (HashMap)
17import Data.HashMap.Strict (HashMap)
18import qualified Data.HashMap.Strict as HashMap
18import qualified Data.HashMap.Strict as HashMap
19+import Data.List.NonEmpty (NonEmpty(..), nonEmpty)
19import Data.Map (Map)
20import Data.Map (Map)
20import Data.Monoid (mempty)
21import Data.Monoid (mempty)
21import Data.Proxy
22import Data.Proxy
@@ -32,6 +33,7 @@ import Data.Swagger.Declare
32import Test.Hspec
33import Test.Hspec
33import Test.Hspec.QuickCheck
34import Test.Hspec.QuickCheck
34import Test.QuickCheck
35import Test.QuickCheck
36+import Test.QuickCheck.Instances ()
36shouldValidate :: (ToJSON a, ToSchema a) => Proxy a -> a -> Bool
38shouldValidate :: (ToJSON a, ToSchema a) => Proxy a -> a -> Bool
37shouldValidate _ x = validateToJSON x == []
39shouldValidate _ x = validateToJSON x == []
@@ -69,6 +71,7 @@ spec = do
69 -- prop "(Maybe [Int])" $ shouldValidate (Proxy :: Proxy (Maybe [Int]))
71 -- prop "(Maybe [Int])" $ shouldValidate (Proxy :: Proxy (Maybe [Int]))
70 prop "(IntMap String)" $ shouldValidate (Proxy :: Proxy (IntMap String))
72 prop "(IntMap String)" $ shouldValidate (Proxy :: Proxy (IntMap String))
71 prop "(Set Bool)" $ shouldValidate (Proxy :: Proxy (Set Bool))
73 prop "(Set Bool)" $ shouldValidate (Proxy :: Proxy (Set Bool))
74+ prop "(NonEmpty Bool)" $ shouldValidate (Proxy :: Proxy (NonEmpty Bool))
72 prop "(HashSet Bool)" $ shouldValidate (Proxy :: Proxy (HashSet Bool))
75 prop "(HashSet Bool)" $ shouldValidate (Proxy :: Proxy (HashSet Bool))
73 prop "(Either Int String)" $ shouldValidate (Proxy :: Proxy (Either Int String))
76 prop "(Either Int String)" $ shouldValidate (Proxy :: Proxy (Either Int String))
74 prop "(Int, String)" $ shouldValidate (Proxy :: Proxy (Int, String))
77 prop "(Int, String)" $ shouldValidate (Proxy :: Proxy (Int, String))
@@ -228,35 +231,5 @@ invalidButtonImagesToJSON = genericToJSON defaultOptions
228instance Arbitrary ButtonImages where
231instance Arbitrary ButtonImages where
229 arbitrary = ButtonImages <$> arbitrary
232 arbitrary = ButtonImages <$> arbitrary
231−-- Arbitrary instances for common types
233−instance (Eq k, Hashable k, Arbitrary k, Arbitrary v) => Arbitrary (HashMap k v) where
234− arbitrary = HashMap.fromList <$> arbitrary
236−instance (Eq a, Hashable a, Arbitrary a) => Arbitrary (HashSet a) where
237− arbitrary = HashSet.fromList <$> arbitrary
239−instance Arbitrary T.Text where
240− arbitrary = T.pack <$> arbitrary
242−instance Arbitrary TL.Text where
243− arbitrary = TL.pack <$> arbitrary
245−instance Arbitrary Day where
246− arbitrary = liftA3 fromGregorian (fmap ((+ 1) . abs) arbitrary) arbitrary arbitrary
248−instance Arbitrary LocalTime where
249− arbitrary = LocalTime
251− <*> liftA3 TimeOfDay (choose (0, 23)) (choose (0, 59)) (fromInteger <$> choose (0, 60))
253instance Eq ZonedTime where
234instance Eq ZonedTime where
254 ZonedTime t (TimeZone x _ _) == ZonedTime t' (TimeZone y _ _) = t == t' && x == y
235 ZonedTime t (TimeZone x _ _) == ZonedTime t' (TimeZone y _ _) = t == t' && x == y
256−instance Arbitrary ZonedTime where
257− arbitrary = ZonedTime
259− <*> liftA3 TimeZone arbitrary arbitrary (vectorOf 3 (elements ['A'..'Z']))
261−instance Arbitrary UTCTime where
262− arbitrary = UTCTime <$> arbitrary <*> fmap fromInteger (choose (0, 86400))