]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/hs/src/Thrift/Arbitraries.hs
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / hs / src / Thrift / Arbitraries.hs
CommitLineData
f67539c2
TL
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2
3module Thrift.Arbitraries where
4
5import Data.Bits()
6
7import Test.QuickCheck.Arbitrary
8
9import Control.Applicative ((<$>))
10import Data.Map (Map)
11import qualified Data.Map as Map
12import qualified Data.Set as Set
13import qualified Data.Vector as Vector
14import qualified Data.Text.Lazy as Text
15import qualified Data.HashSet as HSet
16import qualified Data.HashMap.Strict as HMap
17import Data.Hashable (Hashable)
18
19import Data.ByteString.Lazy (ByteString)
20import qualified Data.ByteString.Lazy as BS
21
22-- String has an Arbitrary instance already
23-- Bool has an Arbitrary instance already
24-- A Thrift 'list' is a Vector.
25
26instance Arbitrary ByteString where
27 arbitrary = BS.pack . filter (/= 0) <$> arbitrary
28
29instance (Arbitrary k) => Arbitrary (Vector.Vector k) where
30 arbitrary = Vector.fromList <$> arbitrary
31
32instance Arbitrary Text.Text where
33 arbitrary = Text.pack . filter (/= '\0') <$> arbitrary
34
35instance (Eq k, Hashable k, Arbitrary k) => Arbitrary (HSet.HashSet k) where
36 arbitrary = HSet.fromList <$> arbitrary
37
38instance (Eq k, Hashable k, Arbitrary k, Arbitrary v) =>
39 Arbitrary (HMap.HashMap k v) where
40 arbitrary = HMap.fromList <$> arbitrary
41
42{-
43 To handle Thrift 'enum' we would ideally use something like:
44
45instance (Enum a, Bounded a) => Arbitrary a
46 where arbitrary = elements (enumFromTo minBound maxBound)
47
48Unfortunately this doesn't play nicely with the type system.
49Instead we'll generate an arbitrary instance along with the code.
50-}
51
52{-
53 There might be some way to introspect on the Haskell structure of a
54 Thrift 'struct' or 'exception' but generating the code directly is simpler.
55-}