-
Notifications
You must be signed in to change notification settings - Fork 0
/
haskell-src.hs
58 lines (50 loc) · 1.94 KB
/
haskell-src.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{-# LANGUAGE TemplateHaskell, StandaloneDeriving #-}
import Test.FitSpec
import Language.Haskell.Parser
import Language.Haskell.Pretty as P
import Language.Haskell.Syntax
import Data.Ratio
import Data.List (intercalate)
import Data.Function (on)
import Data.Char
deriving instance Eq HsModule -- needed for Mutable
deriveMutableCascading ''HsModule
-- change ``take 5'' below to ``take n'' where n `elem` [1,2,3,4]
-- to see surviving mutants for different refinements
--
-- All 5 properties should be reported as ``apparently complete''
-- so no surviving mutants.
properties :: (HsModule -> String) -> [Property]
properties prettyPrint = take 5
[ property $
\nm loc -> (prettyPrint $ HsModule loc (Module nm) Nothing [] [])
== "module " ++ nm ++ " where"
, property $
\nm loc -> (prettyPrint $ HsModule loc (Module nm) (Just []) [] [])
== "module " ++ nm ++ " () where"
, property $
\nm loc -> (prettyPrint $ HsModule loc (Module nm) Nothing [] [HsFunBind []])
== "module " ++ nm ++ " where"
, property $
\nm loc imports decls ->
(prettyPrint $ HsModule loc (Module nm) Nothing imports decls)
=== unlines (("module " ++ nm ++ " where")
:(map P.prettyPrint imports
++ map P.prettyPrint decls))
, property $
\nm loc imports exports decls ->
(prettyPrint $ HsModule loc (Module nm) (Just exports) imports decls)
=== unlines (["module " ++ nm ++ " ("
++ intercalate ", " (map P.prettyPrint exports)
++ ") where"]
++ map P.prettyPrint imports
++ map P.prettyPrint decls)
]
where
(===) :: String -> String -> Bool
(===) = (==) `on` (filter (not . null) . lines)
main = mainWith args { names = ["prettyPrint"]
, timeout = 0
}
prettyPrint
properties