1 {-# LANGUAGE TemplateHaskell #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 {-| Unittests for ganeti-htools.
10 Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 module Test.Ganeti.JSON (testJSON) where
31 import Test.QuickCheck
33 import qualified Text.JSON as J
35 import Test.Ganeti.TestHelper
36 import Test.Ganeti.TestCommon
38 import qualified Ganeti.BasicTypes as BasicTypes
39 import qualified Ganeti.JSON as JSON
41 prop_toArray :: [Int] -> Property
43 let arr = map J.showJSON intarr in
44 case JSON.toArray (J.JSArray arr) of
45 BasicTypes.Ok arr' -> arr ==? arr'
46 BasicTypes.Bad err -> failTest $ "Failed to parse array: " ++ err
48 prop_toArrayFail :: Int -> String -> Bool -> Property
49 prop_toArrayFail i s b =
50 -- poor man's instance Arbitrary JSValue
51 forAll (elements [J.showJSON i, J.showJSON s, J.showJSON b]) $ \item ->
52 case JSON.toArray item of
53 BasicTypes.Bad _ -> passTest
54 BasicTypes.Ok result -> failTest $ "Unexpected parse, got " ++ show result