From 55074a07fdb847749e4f57c6c2eac4ffab1d48b6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 18 Feb 2016 21:59:00 +0000 Subject: Api tests for Thermoprint.Server --- spec/src/Thermoprint/API.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec/src/Thermoprint/API.hs') diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index 5bfe431..3ffd239 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs @@ -50,6 +50,10 @@ import Data.Time.Format import Data.Encoding.Exception (EncodingException(..)) +import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary(..)) +import Test.QuickCheck.Gen (scale, variant, oneof) +import Test.QuickCheck.Instances + instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId) @@ -75,6 +79,13 @@ data PrintingError = IOError String -- ^ Not the actual error because we can't m | EncError EncodingException -- ^ Could not encode some part of the 'Printout' deriving (Typeable, Generic, NFData, Show, FromJSON, ToJSON) +instance Arbitrary PrintingError where + arbitrary = IOError <$> arbitrary + +instance CoArbitrary PrintingError where + coarbitrary (IOError _) = variant 0 + coarbitrary (EncError _) = variant 1 + instance Exception PrintingError type DraftTitle = Text @@ -87,6 +98,12 @@ instance ToText UTCTime where data Range a = Min a | Max a | Through a a +instance Arbitrary a => Arbitrary (Range a) where + arbitrary = oneof [ Min <$> arbitrary + , Max <$> arbitrary + , Through <$> arbitrary <*> arbitrary + ] + contains :: Ord a => Range a -> a -> Bool -- ^ Check if a 'Range' contains a point contains (Min min) x = min <= x -- cgit v1.2.3