aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-02-18 21:59:00 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-02-18 21:59:00 +0000
commit55074a07fdb847749e4f57c6c2eac4ffab1d48b6 (patch)
tree5cd211775cf84fffa934a17ce276be2d6b3990f6 /spec
parent2d16ad6786e6047fc61b34e6bd7e59e794a9d5a3 (diff)
downloadthermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar
thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar.gz
thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar.bz2
thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar.xz
thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.zip
Api tests for Thermoprint.Server
Diffstat (limited to 'spec')
-rw-r--r--spec/src/Thermoprint/API.hs17
1 files changed, 17 insertions, 0 deletions
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
50 50
51import Data.Encoding.Exception (EncodingException(..)) 51import Data.Encoding.Exception (EncodingException(..))
52 52
53import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary(..))
54import Test.QuickCheck.Gen (scale, variant, oneof)
55import Test.QuickCheck.Instances
56
53instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where 57instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where
54 toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId) 58 toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId)
55 59
@@ -75,6 +79,13 @@ data PrintingError = IOError String -- ^ Not the actual error because we can't m
75 | EncError EncodingException -- ^ Could not encode some part of the 'Printout' 79 | EncError EncodingException -- ^ Could not encode some part of the 'Printout'
76 deriving (Typeable, Generic, NFData, Show, FromJSON, ToJSON) 80 deriving (Typeable, Generic, NFData, Show, FromJSON, ToJSON)
77 81
82instance Arbitrary PrintingError where
83 arbitrary = IOError <$> arbitrary
84
85instance CoArbitrary PrintingError where
86 coarbitrary (IOError _) = variant 0
87 coarbitrary (EncError _) = variant 1
88
78instance Exception PrintingError 89instance Exception PrintingError
79 90
80type DraftTitle = Text 91type DraftTitle = Text
@@ -87,6 +98,12 @@ instance ToText UTCTime where
87 98
88data Range a = Min a | Max a | Through a a 99data Range a = Min a | Max a | Through a a
89 100
101instance Arbitrary a => Arbitrary (Range a) where
102 arbitrary = oneof [ Min <$> arbitrary
103 , Max <$> arbitrary
104 , Through <$> arbitrary <*> arbitrary
105 ]
106
90contains :: Ord a => Range a -> a -> Bool 107contains :: Ord a => Range a -> a -> Bool
91-- ^ Check if a 'Range' contains a point 108-- ^ Check if a 'Range' contains a point
92contains (Min min) x = min <= x 109contains (Min min) x = min <= x