File: GRead.hs

package info (click to toggle)
haskell-syb 0.7.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: haskell: 2,264; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{-# LANGUAGE DeriveDataTypeable #-}

module GRead (tests) where

{-

The following examples achieve branch coverage for the various
productions in the definition of gread. Also, negative test cases are
provided; see str2 and str3. Also, the potential of heading or
trailing spaces as well incomplete parsing of the input is exercised;
see str5.

-}

import Test.Tasty.HUnit

import Data.Generics

str1 = "(True)"     -- reads fine as a Bool
str2 = "(Treu)"     -- invalid constructor
str3 = "True"       -- lacks parentheses
str4 = "(1)"        -- could be an Int
str5 = "( 2 ) ..."  -- could be an Int with some trailing left-over
str6 = "([])"       -- test empty list
str7 = "((:)" ++ " " ++ str4 ++ " " ++ str6 ++ ")"

tests = show ( ( [ gread str1,
                   gread str2,
                   gread str3
                 ]
               , [ gread str4,
                   gread str5
                 ]
               , [ gread str6,
                   gread str7
                 ]
               )
             :: ( [[(Bool,  String)]]
                , [[(Int,   String)]]
                , [[([Int], String)]]
                )
             ) @=? output

output = show
           ([[(True,"")],[],[]],[[(1,"")],[(2,"...")]],[[([],"")],[([1],"")]])