Debian Codegraph @

test/hs/Test/Ganeti/Storage/Drbd/Parser.hs

raw
1 {-# LANGUAGE TemplateHaskell #-}
2
3 {-| Unittests for the DRBD Parser -}
4
5 {-
6
7 Copyright (C) 2012 Google Inc.
8 All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are
12 met:
13
14 1. Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 -}
34
35 module Test.Ganeti.Storage.Drbd.Parser (testBlock_Drbd_Parser) where
36
37 import Test.QuickCheck as QuickCheck hiding (Result)
38 import Test.HUnit
39
40 import Test.Ganeti.TestHelper
41 import Test.Ganeti.TestCommon
42
43 import qualified Data.Attoparsec.Text as A
44 import Data.List (intercalate)
45 import Data.Text (pack)
46
47 import Ganeti.Storage.Drbd.Parser (drbdStatusParser, commaIntParser)
48 import Ganeti.Storage.Drbd.Types
49
50 {-# ANN module "HLint: ignore Use camelCase" #-}
51
52 -- | Test a DRBD 8.0 file with an empty line inside.
53 case_drbd80_emptyline :: Assertion
54 case_drbd80_emptyline = testParser (drbdStatusParser [])
55 "proc_drbd80-emptyline.txt" $ DRBDStatus
56 ( VersionInfo (Just "8.0.12") (Just "86") (Just "86") Nothing
57 (Just "5c9f89594553e32adb87d9638dce591782f947e3")
58 (Just "[email protected], 2009-05-22 12:47:52")
59 )
60 [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
61 (LocalRemote UpToDate UpToDate) 'C' "r---"
62 (PerfIndicators 78728316 0 77675644 1277039 254 270 0 0 0 0
63 Nothing Nothing Nothing)
64 Nothing
65 (Just $ AdditionalInfo 0 61 65657 135 0 0 135)
66 (Just $ AdditionalInfo 0 257 11378843 254 0 0 254)
67 Nothing,
68 UnconfiguredDevice 1,
69 UnconfiguredDevice 2,
70 UnconfiguredDevice 5,
71 UnconfiguredDevice 6
72 ]
73
74 -- | Test a DRBD 8.0 file with an empty version.
75 case_drbd80_emptyversion :: Assertion
76 case_drbd80_emptyversion = testParser (drbdStatusParser [])
77 "proc_drbd80-emptyversion.txt" $ DRBDStatus
78 ( VersionInfo Nothing Nothing Nothing Nothing
79 (Just "5c9f89594553e32adb87d9638dce591782f947e3")
80 (Just "[email protected], 2009-05-22 12:47:52")
81 )
82 [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
83 (LocalRemote UpToDate UpToDate) 'C' "r---"
84 (PerfIndicators 78728316 0 77675644 1277039 254 270 0 0 0 0
85 Nothing Nothing Nothing)
86 Nothing
87 (Just $ AdditionalInfo 0 61 65657 135 0 0 135)
88 (Just $ AdditionalInfo 0 257 11378843 254 0 0 254)
89 Nothing,
90 UnconfiguredDevice 1,
91 UnconfiguredDevice 2,
92 UnconfiguredDevice 5,
93 UnconfiguredDevice 6
94 ]
95
96 -- | Test a DRBD 8.4 file with an ongoing synchronization.
97 case_drbd84_sync :: Assertion
98 case_drbd84_sync = testParser (drbdStatusParser []) "proc_drbd84_sync.txt" $
99 DRBDStatus
100 ( VersionInfo (Just "8.4.2") (Just "1") (Just "86-101") Nothing
101 (Just "7ad5f850d711223713d6dcadc3dd48860321070c")
102 (Just "[email protected], 2013-04-10 07:45:25")
103 )
104 [ DeviceInfo 0 StandAlone (LocalRemote Primary Unknown)
105 (LocalRemote UpToDate DUnknown) ' ' "r-----"
106 (PerfIndicators 0 0 33318 730 15 0 0 0 0 0 (Just 1)
107 (Just 'd') (Just 1048320))
108 Nothing
109 Nothing
110 Nothing
111 Nothing,
112 UnconfiguredDevice 3,
113 DeviceInfo 5 SyncSource (LocalRemote Secondary Secondary)
114 (LocalRemote UpToDate Inconsistent) 'C' "r---n-"
115 (PerfIndicators 716992 0 0 719432 0 43 0 33 18 0 (Just 1)
116 (Just 'f') (Just 335744))
117 (Just $ SyncStatus 68.5 335744 1048576 KiloByte (Time 0 0 5) 64800
118 Nothing KiloByte Second)
119 Nothing
120 Nothing
121 Nothing
122 ]
123
124 -- | Test a DRBD 8.4 file.
125 case_drbd84 :: Assertion
126 case_drbd84 = testParser (drbdStatusParser []) "proc_drbd84.txt" $
127 DRBDStatus
128 ( VersionInfo (Just "8.4.2") (Just "1") (Just "86-101") Nothing
129 (Just "7ad5f850d711223713d6dcadc3dd48860321070c")
130 (Just "[email protected], 2013-04-10 07:45:25")
131 )
132 [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
133 (LocalRemote UpToDate UpToDate) 'C' "r-----"
134 (PerfIndicators 1048576 0 0 1048776 0 64 0 0 0 0 (Just 1)
135 (Just 'f') (Just 0))
136 Nothing
137 Nothing
138 Nothing
139 Nothing,
140 DeviceInfo 1 Connected (LocalRemote Secondary Primary)
141 (LocalRemote UpToDate UpToDate) 'C' "r-----"
142 (PerfIndicators 0 1048576 1048576 0 0 64 0 0 0 0 (Just 1)
143 (Just 'f') (Just 0))
144 Nothing
145 Nothing
146 Nothing
147 Nothing,
148 UnconfiguredDevice 2,
149 DeviceInfo 4 WFConnection (LocalRemote Primary Unknown)
150 (LocalRemote UpToDate DUnknown) 'C' "r-----"
151 (PerfIndicators 0 0 0 200 0 0 0 0 0 0 (Just 1)
152 (Just 'f') (Just 1048320))
153 Nothing
154 Nothing
155 Nothing
156 Nothing,
157 DeviceInfo 6 Connected (LocalRemote Secondary Primary)
158 (LocalRemote Diskless UpToDate) 'C' "r-----"
159 (PerfIndicators 0 0 0 0 0 0 0 0 0 0 (Just 1) (Just 'b')
160 (Just 0))
161 Nothing
162 Nothing
163 Nothing
164 Nothing,
165 DeviceInfo 8 StandAlone (LocalRemote Secondary Unknown)
166 (LocalRemote UpToDate DUnknown) ' ' "r-----"
167 (PerfIndicators 0 0 0 200 0 0 0 0 0 0 (Just 1)
168 (Just 'f') (Just 1048320))
169 Nothing
170 Nothing
171 Nothing
172 Nothing
173 ]
174
175 -- | Test a DRBD 8.4 file with the first resource empty.
176 case_drbd84_emptyfirst :: Assertion
177 case_drbd84_emptyfirst = testParser (drbdStatusParser [])
178 "proc_drbd84_emptyfirst.txt" $ DRBDStatus
179 ( VersionInfo (Just "8.4.2") (Just "1") (Just "86-101") Nothing
180 (Just "7ad5f850d711223713d6dcadc3dd48860321070c")
181 (Just "[email protected], 2013-04-10 07:45:25")
182 )
183 [ DeviceInfo 1 Connected (LocalRemote Secondary Primary)
184 (LocalRemote UpToDate UpToDate) 'C' "r-----"
185 (PerfIndicators 0 1048576 1048576 0 0 64 0 0 0 0 (Just 1)
186 (Just 'f') (Just 0))
187 Nothing
188 Nothing
189 Nothing
190 Nothing,
191 UnconfiguredDevice 2,
192 DeviceInfo 4 WFConnection (LocalRemote Primary Unknown)
193 (LocalRemote UpToDate DUnknown) 'C' "r-----"
194 (PerfIndicators 0 0 0 200 0 0 0 0 0 0 (Just 1)
195 (Just 'f') (Just 1048320))
196 Nothing
197 Nothing
198 Nothing
199 Nothing,
200 DeviceInfo 6 Connected (LocalRemote Secondary Primary)
201 (LocalRemote Diskless UpToDate) 'C' "r-----"
202 (PerfIndicators 0 0 0 0 0 0 0 0 0 0 (Just 1) (Just 'b')
203 (Just 0))
204 Nothing
205 Nothing
206 Nothing
207 Nothing,
208 DeviceInfo 8 StandAlone (LocalRemote Secondary Unknown)
209 (LocalRemote UpToDate DUnknown) ' ' "r-----"
210 (PerfIndicators 0 0 0 200 0 0 0 0 0 0 (Just 1)
211 (Just 'f') (Just 1048320))
212 Nothing
213 Nothing
214 Nothing
215 Nothing
216 ]
217
218 -- | Test a DRBD 8.3 file with a NULL caracter inside.
219 case_drbd83_sync_krnl2_6_39 :: Assertion
220 case_drbd83_sync_krnl2_6_39 = testParser (drbdStatusParser [])
221 "proc_drbd83_sync_krnl2.6.39.txt" $ DRBDStatus
222 ( VersionInfo (Just "8.3.1") (Just "88") (Just "86-89") Nothing
223 (Just "fd40f4a8f9104941537d1afc8521e584a6d3003c")
224 (Just "phil@fat-tyre, 2009-03-27 12:19:49")
225 )
226 [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
227 (LocalRemote UpToDate UpToDate) 'C' "r----"
228 (PerfIndicators 140978 0 9906 131533 27 8 0 0 0 0 (Just 1)
229 (Just 'b') (Just 0))
230 Nothing
231 Nothing
232 Nothing
233 Nothing,
234 DeviceInfo 1 Connected (LocalRemote Secondary Primary)
235 (LocalRemote UpToDate UpToDate) 'C' "r---"
236 (PerfIndicators 0 140980 140980 0 0 8 0 0 0 0 (Just 1) (Just 'f')
237 (Just 0))
238 Nothing
239 Nothing
240 Nothing
241 Nothing,
242 UnconfiguredDevice 2,
243 DeviceInfo 3 SyncSource (LocalRemote Primary Secondary)
244 (LocalRemote UpToDate Inconsistent) 'A' "r-----"
245 (PerfIndicators 373888 0 0 374088 0 22 7 27 7 0 (Just 1)
246 (Just 'f') (Just 15358208))
247 (Just $ SyncStatus 2.4 14996 15360 MegaByte (Time 0 4 8) 61736 Nothing
248 KiloByte Second)
249 Nothing
250 Nothing
251 Nothing,
252 DeviceInfo 4 WFConnection (LocalRemote Primary Unknown)
253 (LocalRemote UpToDate DUnknown) 'C' "r----"
254 (PerfIndicators 140978 0 9906 131534 27 8 0 0 0 0 (Just 1)
255 (Just 'b') (Just 0))
256 Nothing
257 Nothing
258 Nothing
259 Nothing
260 ]
261
262 -- | Test a DRBD 8.3 file with an ongoing synchronization.
263 case_drbd83_sync :: Assertion
264 case_drbd83_sync = testParser (drbdStatusParser []) "proc_drbd83_sync.txt" $
265 DRBDStatus
266 ( VersionInfo (Just "8.3.1") (Just "88") (Just "86-89") Nothing
267 (Just "fd40f4a8f9104941537d1afc8521e584a6d3003c")
268 (Just "phil@fat-tyre, 2009-03-27 12:19:49")
269 )
270 [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
271 (LocalRemote UpToDate UpToDate) 'C' "r----"
272 (PerfIndicators 140978 0 9906 131533 27 8 0 0 0 0 (Just 1)
273 (Just 'b') (Just 0))
274 Nothing
275 Nothing
276 Nothing
277 Nothing,
278 DeviceInfo 1 Connected (LocalRemote Secondary Primary)
279 (LocalRemote UpToDate UpToDate) 'C' "r---"
280 (PerfIndicators 0 140980 140980 0 0 8 0 0 0 0 (Just 1) (Just 'f')
281 (Just 0))
282 Nothing
283 Nothing
284 Nothing
285 Nothing,
286 UnconfiguredDevice 2,
287 DeviceInfo 3 SyncTarget (LocalRemote Primary Secondary)
288 (LocalRemote Inconsistent UpToDate) 'C' "r----"
289 (PerfIndicators 0 178176 178176 0 104 42 0 0 0 0 (Just 1)
290 (Just 'b') (Just 346112))
291 (Just $ SyncStatus 34.9 346112 524288 MegaByte (Time 0 0 5) 59392
292 Nothing KiloByte Second)
293 Nothing
294 Nothing
295 Nothing,
296 DeviceInfo 4 WFConnection (LocalRemote Primary Unknown)
297 (LocalRemote UpToDate DUnknown) 'C' "r----"
298 (PerfIndicators 140978 0 9906 131534 27 8 0 0 0 0 (Just 1)
299 (Just 'b') (Just 0))
300 Nothing
301 Nothing
302 Nothing
303 Nothing
304 ]
305
306 -- | Test a DRBD 8.3 file not from git sources, with an ongoing synchronization
307 -- and the "want" field
308 case_drbd83_sync_want :: Assertion
309 case_drbd83_sync_want = testParser (drbdStatusParser [])
310 "proc_drbd83_sync_want.txt" $ DRBDStatus
311 ( VersionInfo (Just "8.3.11") (Just "88") (Just "86-96")
312 (Just "2D876214BAAD53B31ADC1D6")
313 Nothing Nothing
314 )
315 [ DeviceInfo 0 SyncTarget (LocalRemote Secondary Primary)
316 (LocalRemote Inconsistent UpToDate) 'C' "r-----"
317 (PerfIndicators 0 460288 460160 0 0 28 2 4 1 0 (Just 1)
318 (Just 'f') (Just 588416))
319 (Just $ SyncStatus 44.4 588416 1048576 KiloByte (Time 0 0 8) 65736
320 (Just 61440) KiloByte Second)
321 Nothing
322 Nothing
323 Nothing,
324 UnconfiguredDevice 1,
325 UnconfiguredDevice 2,
326 UnconfiguredDevice 3
327 ]
328
329 -- | Test a DRBD 8.3 file.
330 case_drbd83 :: Assertion
331 case_drbd83 = testParser (drbdStatusParser []) "proc_drbd83.txt" $
332 DRBDStatus
333 ( VersionInfo (Just "8.3.1") (Just "88") (Just "86-89")
334 Nothing
335 (Just "fd40f4a8f9104941537d1afc8521e584a6d3003c")
336 (Just "phil@fat-tyre, 2009-03-27 12:19:49")
337 )
338 [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
339 (LocalRemote UpToDate UpToDate) 'C' "r----"
340 (PerfIndicators 140978 0 9906 131533 27 8 0 0 0 0 (Just 1)
341 (Just 'b') (Just 0))
342 Nothing
343 Nothing
344 Nothing
345 Nothing,
346 DeviceInfo 1 Connected (LocalRemote Secondary Primary)
347 (LocalRemote UpToDate UpToDate) 'C' "r---"
348 (PerfIndicators 0 140980 140980 0 0 8 0 0 0 0 (Just 1) (Just 'f')
349 (Just 0))
350 Nothing
351 Nothing
352 Nothing
353 Nothing,
354 UnconfiguredDevice 2,
355 DeviceInfo 4 WFConnection (LocalRemote Primary Unknown)
356 (LocalRemote UpToDate DUnknown) 'C' "r----"
357 (PerfIndicators 140978 0 9906 131534 27 8 0 0 0 0 (Just 1)
358 (Just 'b') (Just 0))
359 Nothing
360 Nothing
361 Nothing
362 Nothing,
363 DeviceInfo 5 Connected (LocalRemote Primary Secondary)
364 (LocalRemote UpToDate Diskless) 'C' "r----"
365 (PerfIndicators 140978 0 9906 131533 19 8 0 0 0 0 (Just 1)
366 (Just 'b') (Just 0))
367 Nothing
368 Nothing
369 Nothing
370 Nothing,
371 DeviceInfo 6 Connected (LocalRemote Secondary Primary)
372 (LocalRemote Diskless UpToDate) 'C' "r---"
373 (PerfIndicators 0 140978 140978 0 0 8 0 0 0 0 (Just 1) (Just 'f')
374 (Just 0))
375 Nothing
376 Nothing
377 Nothing
378 Nothing,
379 DeviceInfo 7 WFConnection (LocalRemote Secondary Unknown)
380 (LocalRemote UpToDate DUnknown) 'C' "r---"
381 (PerfIndicators 0 140978 140978 0 0 8 0 0 0 0 (Just 1) (Just 'f')
382 (Just 0))
383 Nothing
384 Nothing
385 Nothing
386 Nothing,
387 DeviceInfo 8 StandAlone (LocalRemote Secondary Unknown)
388 (LocalRemote UpToDate DUnknown) ' ' "r---"
389 (PerfIndicators 0 140978 140978 0 0 8 0 0 0 0 (Just 1)
390 (Just 'f') (Just 0))
391 Nothing
392 Nothing
393 Nothing
394 Nothing
395 ]
396
397 -- | Test a DRBD 8.0 file with a missing device.
398 case_drbd8 :: Assertion
399 case_drbd8 = testParser (drbdStatusParser []) "proc_drbd8.txt" $
400 DRBDStatus
401 ( VersionInfo (Just "8.0.12") (Just "86") (Just "86") Nothing
402 (Just "5c9f89594553e32adb87d9638dce591782f947e3")
403 (Just "XXX")
404 )
405 [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
406 (LocalRemote UpToDate UpToDate) 'C' "r---"
407 (PerfIndicators 4375577 0 4446279 674 1067 69 0 0 0 0 Nothing
408 Nothing Nothing)
409 Nothing
410 (Just $ AdditionalInfo 0 61 0 0 0 0 0)
411 (Just $ AdditionalInfo 0 257 793749 1067 0 0 1067)
412 Nothing,
413 DeviceInfo 1 Connected (LocalRemote Secondary Primary)
414 (LocalRemote UpToDate UpToDate) 'C' "r---"
415 (PerfIndicators 738320 0 738320 554400 67 0 0 0 0 0 Nothing
416 Nothing Nothing)
417 Nothing
418 (Just $ AdditionalInfo 0 61 0 0 0 0 0)
419 (Just $ AdditionalInfo 0 257 92464 67 0 0 67)
420 Nothing,
421 UnconfiguredDevice 2,
422 DeviceInfo 4 WFConnection (LocalRemote Primary Unknown)
423 (LocalRemote UpToDate DUnknown) 'C' "r---"
424 (PerfIndicators 738320 0 738320 554400 67 0 0 0 0 0 Nothing
425 Nothing Nothing)
426 Nothing
427 (Just $ AdditionalInfo 0 61 0 0 0 0 0)
428 (Just $ AdditionalInfo 0 257 92464 67 0 0 67)
429 Nothing,
430 DeviceInfo 5 Connected (LocalRemote Primary Secondary)
431 (LocalRemote UpToDate Diskless) 'C' "r---"
432 (PerfIndicators 4375581 0 4446283 674 1069 69 0 0 0 0 Nothing
433 Nothing Nothing)
434 Nothing
435 (Just $ AdditionalInfo 0 61 0 0 0 0 0)
436 (Just $ AdditionalInfo 0 257 793750 1069 0 0 1069)
437 Nothing,
438 DeviceInfo 6 Connected (LocalRemote Secondary Primary)
439 (LocalRemote Diskless UpToDate) 'C' "r---"
440 (PerfIndicators 0 4375581 5186925 327 75 214 0 0 0 0 Nothing
441 Nothing Nothing)
442 Nothing
443 Nothing
444 Nothing
445 Nothing,
446 DeviceInfo 7 WFConnection (LocalRemote Secondary Unknown)
447 (LocalRemote UpToDate DUnknown) 'C' "r---"
448 (PerfIndicators 0 0 0 0 0 0 0 0 0 0 Nothing Nothing Nothing)
449 Nothing
450 (Just $ AdditionalInfo 0 61 0 0 0 0 0)
451 (Just $ AdditionalInfo 0 257 0 0 0 0 0)
452 Nothing,
453 DeviceInfo 8 StandAlone (LocalRemote Secondary Unknown)
454 (LocalRemote UpToDate DUnknown) ' ' "r---"
455 (PerfIndicators 0 0 0 0 0 0 0 0 0 0 Nothing Nothing Nothing)
456 Nothing
457 (Just $ AdditionalInfo 0 61 0 0 0 0 0)
458 (Just $ AdditionalInfo 0 257 0 0 0 0 0)
459 Nothing
460 ]
461
462 -- | Function for splitting a list in chunks of a given size.
463 -- FIXME: an equivalent function exists in Data.List.Split, but it seems
464 -- pointless to add this package as a dependence just for this single
465 -- use. In case it is ever added, just remove this function definition
466 -- and use the one from the package.
467 splitEvery :: Int -> [e] -> [[e]]
468 splitEvery i l = map (take i) (splitter l (:) []) where
469 splitter [] _ n = n
470 splitter li c n = li `c` splitter (drop i li) c n
471
472 -- | Function for testing whether a single comma-separated integer is
473 -- parsed correctly.
474 testCommaInt :: String -> Int -> Assertion
475 testCommaInt numString expectedResult =
476 case A.parseOnly commaIntParser $ pack numString of
477 Left msg -> assertFailure $ "Parsing failed: " ++ msg
478 Right obtained -> assertEqual numString expectedResult obtained
479
480 -- | Generate a property test for CommaInt numbers in a given range.
481 gen_prop_CommaInt :: Int -> Int -> Property
482 gen_prop_CommaInt minVal maxVal =
483 forAll (choose (minVal, maxVal)) $ \i ->
484 case A.parseOnly commaIntParser $ pack (generateCommaInt i) of
485 Left msg -> failTest $ "Parsing failed: " ++ msg
486 Right obtained -> i ==? obtained
487 where generateCommaInt x =
488 ((reverse . intercalate ",") . splitEvery 3) . reverse $ show x
489
490 -- | Test if <4 digit integers are recognized correctly.
491 prop_commaInt_noCommas :: Property
492 prop_commaInt_noCommas = gen_prop_CommaInt 0 999
493
494 -- | Test if integers with 1 comma are recognized correctly.
495 prop_commaInt_1Comma :: Property
496 prop_commaInt_1Comma = gen_prop_CommaInt 1000 999999
497
498 -- | Test if integers with multiple commas are recognized correctly.
499 prop_commaInt_multipleCommas :: Property
500 prop_commaInt_multipleCommas = gen_prop_CommaInt 1000000 (maxBound ::
501 Int)
502
503 -- | Test whether the parser is actually able to behave as intended with
504 -- numbers without commas. That is, if a number with more than 3 digits
505 -- is parsed, only up to the first 3 digits are considered (because they
506 -- are a valid commaInt), and the rest is ignored.
507 -- e.g.: parse "1234" = 123
508 prop_commaInt_max3WithoutComma :: Property
509 prop_commaInt_max3WithoutComma =
510 forAll (choose (0, maxBound :: Int)) $ \i ->
511 case A.parseOnly commaIntParser $ pack (show i) of
512 Left msg -> failTest $ "Parsing failed: " ++ msg
513 Right obtained ->
514 obtained < 1000 .&&.
515 getFirst3Digits i ==? obtained
516 where getFirst3Digits x =
517 if x >= 1000
518 then getFirst3Digits $ x `div` 10
519 else x
520
521 -- | Test if non-triplets are handled correctly (they are assumed NOT being part
522 -- of the number).
523 case_commaInt_non_triplet :: Assertion
524 case_commaInt_non_triplet = testCommaInt "61,736,12" 61736
525
526
527 testSuite "Block/Drbd/Parser"
528 [ 'case_drbd80_emptyline,
529 'case_drbd80_emptyversion,
530 'case_drbd84_sync,
531 'case_drbd84,
532 'case_drbd84_emptyfirst,
533 'case_drbd83_sync_krnl2_6_39,
534 'case_drbd83_sync,
535 'case_drbd83_sync_want,
536 'case_drbd83,
537 'case_drbd8,
538 'case_commaInt_non_triplet,
539 'prop_commaInt_noCommas,
540 'prop_commaInt_1Comma,
541 'prop_commaInt_multipleCommas,
542 'prop_commaInt_max3WithoutComma
543 ]