QuickCheck for testing a parsing function

Hi there, I have the following snippet: data Volume = Volume { name :: String , mount :: String , size :: String , fs :: String , mbr :: Bool } deriving (Show, Eq) defaultVolume :: Volume defaultVolume = Volume { name = "" , mount = "" , size = "" , fs = "ext4" , mbr = False } parseOptVols :: String -> Volume parseOptVols s = parseChain (defaultVolume, s) where parseChain = parseMBR . parseFS . parseSize . parseMount . parseName parseName (vol, s) = (vol {name = getThis s}, getNext s) parseMount (vol, s) = (vol {mount = getThis s}, getNext s) parseSize (vol, s) = (vol {size = getThis s}, getNext s) -- fs and mbr are optional parseFS (vol, "") = (vol, "") parseFS (vol, ',':s) = (vol, s) parseFS (vol, s) = (vol {fs = getThis s}, getNext s) parseMBR (vol, "t") = vol {mbr = True} parseMBR (vol, _ ) = vol getThis = takeWhile (',' /=) getNext = saveTail . dropWhile (',' /=) saveTail :: [a] -> [a] saveTail [] = [] saveTail (_:xs) = xs What it basically does is parse a string (handed over from the command line) like "boot,/boot,256M,ext3,t" and populates a Volume instance with this. The last two fields are optional. I like testing and coming from an object-oriented background unit testing is the most comfortable to me. But I wonder if there is some smart way to make QuickCheck produce test cases. I would need some generator for this which produces a pattern like "name,mount,size,fs,mbr" eventually leaving "fs" and/or "mbr" empty and sometimes omitting both commas or just one of them. And I also need access to these fields in order to be able to compare them with the resulting Volume instance. I can see how to achieve the former somehow, but I don't have any clue how to achieve the latter. Any hints? Or is this simply not a nail for the QuickCheck-hammer? Regards, Thomas Bach. PS: Any advice on how to improve the code above is highly appreciated as well.

On Sun, 16 Feb 2014 10:45:21 +0100, Thomas Bach
Hi there,
I have the following snippet: : Any hints? Or is this simply not a nail for the QuickCheck-hammer?
I am not a QuickCheck expert, but I think you need to generate the parts that you expect as output, than compose these parts into the string to be parsed. That way, you can check the result. Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --
participants (2)
-
Henk-Jan van Tuyl
-
Thomas Bach