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