Revision 3ad57194 htools/Ganeti/HTools/QC.hs

b/htools/Ganeti/HTools/QC.hs
39 39
  , testLoader
40 40
  , testTypes
41 41
  , testCLI
42
  , testJSON
42 43
  ) where
43 44

  
44 45
import Test.QuickCheck
......
1634 1635
          , 'prop_CLI_StringArg
1635 1636
          , 'prop_CLI_stdopts
1636 1637
          ]
1638

  
1639
-- * JSON tests
1640

  
1641
prop_JSON_toArray :: [Int] -> Property
1642
prop_JSON_toArray intarr =
1643
  let arr = map J.showJSON intarr in
1644
  case JSON.toArray (J.JSArray arr) of
1645
    Types.Ok arr' -> arr ==? arr'
1646
    Types.Bad err -> failTest $ "Failed to parse array: " ++ err
1647

  
1648
prop_JSON_toArrayFail :: Int -> String -> Bool -> Property
1649
prop_JSON_toArrayFail i s b =
1650
  -- poor man's instance Arbitrary JSValue
1651
  forAll (elements [J.showJSON i, J.showJSON s, J.showJSON b]) $ \item ->
1652
  case JSON.toArray item of
1653
    Types.Bad _ -> property True
1654
    Types.Ok result -> failTest $ "Unexpected parse, got " ++ show result
1655

  
1656
testSuite "JSON"
1657
          [ 'prop_JSON_toArray
1658
          , 'prop_JSON_toArrayFail
1659
          ]

Also available in: Unified diff