diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-18 21:59:00 +0000 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-18 21:59:00 +0000 |
| commit | 55074a07fdb847749e4f57c6c2eac4ffab1d48b6 (patch) | |
| tree | 5cd211775cf84fffa934a17ce276be2d6b3990f6 /spec | |
| parent | 2d16ad6786e6047fc61b34e6bd7e59e794a9d5a3 (diff) | |
| download | thermoprint-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.hs | 17 |
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 | ||
| 51 | import Data.Encoding.Exception (EncodingException(..)) | 51 | import Data.Encoding.Exception (EncodingException(..)) |
| 52 | 52 | ||
| 53 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary(..)) | ||
| 54 | import Test.QuickCheck.Gen (scale, variant, oneof) | ||
| 55 | import Test.QuickCheck.Instances | ||
| 56 | |||
| 53 | instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where | 57 | instance (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 | ||
| 82 | instance Arbitrary PrintingError where | ||
| 83 | arbitrary = IOError <$> arbitrary | ||
| 84 | |||
| 85 | instance CoArbitrary PrintingError where | ||
| 86 | coarbitrary (IOError _) = variant 0 | ||
| 87 | coarbitrary (EncError _) = variant 1 | ||
| 88 | |||
| 78 | instance Exception PrintingError | 89 | instance Exception PrintingError |
| 79 | 90 | ||
| 80 | type DraftTitle = Text | 91 | type DraftTitle = Text |
| @@ -87,6 +98,12 @@ instance ToText UTCTime where | |||
| 87 | 98 | ||
| 88 | data Range a = Min a | Max a | Through a a | 99 | data Range a = Min a | Max a | Through a a |
| 89 | 100 | ||
| 101 | instance Arbitrary a => Arbitrary (Range a) where | ||
| 102 | arbitrary = oneof [ Min <$> arbitrary | ||
| 103 | , Max <$> arbitrary | ||
| 104 | , Through <$> arbitrary <*> arbitrary | ||
| 105 | ] | ||
| 106 | |||
| 90 | contains :: Ord a => Range a -> a -> Bool | 107 | contains :: Ord a => Range a -> a -> Bool |
| 91 | -- ^ Check if a 'Range' contains a point | 108 | -- ^ Check if a 'Range' contains a point |
| 92 | contains (Min min) x = min <= x | 109 | contains (Min min) x = min <= x |
