-
Notifications
You must be signed in to change notification settings - Fork 0
/
haskell-src-exts.hs
37 lines (33 loc) · 1.35 KB
/
haskell-src-exts.hs
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
{-# LANGUAGE TemplateHaskell #-}
import Test.FitSpec
import Language.Haskell.Exts
instance Eq a => Eq (ParseResult a) where
ParseOk x == ParseOk y = x == y
ParseFailed l1 s1 == ParseFailed l2 s2 = l1 == l2 && s1 == s2
_ == _ = False
deriveMutableCascading ''ParseResult
deriveMutableCascading ''Module
deriveMutableCascading ''SrcSpanInfo
properties :: (String -> ParseResult (Module SrcSpanInfo)
,Module SrcSpanInfo -> String)
-> [Property]
properties (parseFileContents,prettyPrint) =
[ property $ case parseFileContents "" of
ParseOk (Module _ _ _ _ _) -> True
_ -> False
, property $ case parseFileContents "a" of
ParseFailed (SrcLoc "<unknown>.hs" 2 1) _ -> True
_ -> False
, property $ \m -> case parseFileContents (prettyPrint m) of
ParseOk m' -> case parseFileContents (prettyPrint m') of
ParseOk m'' -> m' == m''
_ -> False
_ -> True
-- Not true:
--, property $ \s -> case parseFileContents s of
-- ParseOk m' -> prettyPrint m' == s
-- _ -> True
]
main = mainWith args { names = ["parseFileContents f", "prettyPrint m"] }
(parseFileContents,prettyPrint)
properties