Revision da9e2aff test/hs/Test/Ganeti/Utils.hs
b/test/hs/Test/Ganeti/Utils.hs | ||
---|---|---|
32 | 32 |
import Test.HUnit |
33 | 33 |
|
34 | 34 |
import Data.Char (isSpace) |
35 |
import qualified Data.Either as Either |
|
35 | 36 |
import Data.List |
36 | 37 |
import System.Time |
37 | 38 |
import qualified Text.JSON as J |
... | ... | |
294 | 295 |
trim "" ==? "" |
295 | 296 |
] |
296 | 297 |
|
298 |
-- | Tests 'splitEithers' and 'recombineEithers'. |
|
299 |
prop_splitRecombineEithers :: [Either Int Int] -> Property |
|
300 |
prop_splitRecombineEithers es = |
|
301 |
conjoin |
|
302 |
[ printTestCase "only lefts are mapped correctly" $ |
|
303 |
splitEithers (map Left lefts) ==? (reverse lefts, emptylist, falses) |
|
304 |
, printTestCase "only rights are mapped correctly" $ |
|
305 |
splitEithers (map Right rights) ==? (emptylist, reverse rights, trues) |
|
306 |
, printTestCase "recombination is no-op" $ |
|
307 |
recombineEithers splitleft splitright trail ==? Ok es |
|
308 |
, printTestCase "fail on too long lefts" $ |
|
309 |
isBad (recombineEithers (0:splitleft) splitright trail) |
|
310 |
, printTestCase "fail on too long rights" $ |
|
311 |
isBad (recombineEithers splitleft (0:splitright) trail) |
|
312 |
, printTestCase "fail on too long trail" $ |
|
313 |
isBad (recombineEithers splitleft splitright (True:trail)) |
|
314 |
] |
|
315 |
where (lefts, rights) = Either.partitionEithers es |
|
316 |
falses = map (const False) lefts |
|
317 |
trues = map (const True) rights |
|
318 |
(splitleft, splitright, trail) = splitEithers es |
|
319 |
emptylist = []::[Int] |
|
320 |
|
|
297 | 321 |
-- | Test list for the Utils module. |
298 | 322 |
testSuite "Utils" |
299 | 323 |
[ 'prop_commaJoinSplit |
... | ... | |
319 | 343 |
, 'prop_chompPrefix_last |
320 | 344 |
, 'prop_chompPrefix_empty_string |
321 | 345 |
, 'prop_chompPrefix_nothing |
346 |
, 'prop_splitRecombineEithers |
|
322 | 347 |
] |
Also available in: Unified diff