Revision 6879dfd2

b/src/Ganeti/JSON.hs
313 313
-- semantics of Maybe and JSON in our calls. Does not produce needless
314 314
-- and confusing dictionaries.
315 315
newtype MaybeForJSON a = MaybeForJSON { unMaybeForJSON :: Maybe a }
316
  deriving (Show, Eq, Ord)
316 317
instance (J.JSON a) => J.JSON (MaybeForJSON a) where
317
  readJSON = J.readJSON
318
  readJSON J.JSNull = return $ MaybeForJSON Nothing
319
  readJSON x        = (MaybeForJSON . Just) `liftM` J.readJSON x
318 320
  showJSON (MaybeForJSON (Just x)) = J.showJSON x
319 321
  showJSON (MaybeForJSON Nothing)  = J.JSNull
320 322

  
b/test/hs/Test/Ganeti/JSON.hs
41 41
import qualified Ganeti.BasicTypes as BasicTypes
42 42
import qualified Ganeti.JSON as JSON
43 43

  
44
instance (Arbitrary a) => Arbitrary (JSON.MaybeForJSON a) where
45
  arbitrary = liftM JSON.MaybeForJSON arbitrary
46

  
44 47
instance Arbitrary JSON.TimeAsDoubleJSON where
45 48
  arbitrary = liftM JSON.TimeAsDoubleJSON arbitrary
46 49

  
......
81 84
                                , Data.List.isInfixOf k e ==? True
82 85
                                ]
83 86

  
87
prop_MaybeForJSON_serialisation :: JSON.MaybeForJSON String -> Property
88
prop_MaybeForJSON_serialisation = testSerialisation
89

  
84 90
prop_TimeAsDoubleJSON_serialisation :: JSON.TimeAsDoubleJSON -> Property
85 91
prop_TimeAsDoubleJSON_serialisation = testSerialisation
86 92

  
......
89 95
          , 'prop_toArrayFail
90 96
          , 'prop_arrayMaybeFromObj
91 97
          , 'prop_arrayMaybeFromObjFail
98
          , 'prop_MaybeForJSON_serialisation
92 99
          , 'prop_TimeAsDoubleJSON_serialisation
93 100
          ]

Also available in: Unified diff