1{-# OPTIONS -fglasgow-exts #-} 2 3module GRead (tests) where 4 5{- 6 7The following examples achieve branch coverage for the various 8productions in the definition of gread. Also, negative test cases are 9provided; see str2 and str3. Also, the potential of heading or 10trailing spaces as well incomplete parsing of the input is exercised; 11see str5. 12 13-} 14 15import Test.HUnit 16 17import Data.Generics 18 19str1 = "(True)" -- reads fine as a Bool 20str2 = "(Treu)" -- invalid constructor 21str3 = "True" -- lacks parentheses 22str4 = "(1)" -- could be an Int 23str5 = "( 2 ) ..." -- could be an Int with some trailing left-over 24str6 = "([])" -- test empty list 25str7 = "((:)" ++ " " ++ str4 ++ " " ++ str6 ++ ")" 26 27tests = show ( ( [ gread str1, 28 gread str2, 29 gread str3 30 ] 31 , [ gread str4, 32 gread str5 33 ] 34 , [ gread str6, 35 gread str7 36 ] 37 ) 38 :: ( [[(Bool, String)]] 39 , [[(Int, String)]] 40 , [[([Int], String)]] 41 ) 42 ) ~=? output 43 44output = show 45 ([[(True,"")],[],[]],[[(1,"")],[(2,"...")]],[[([],"")],[([1],"")]]) 46