03cb4f01c074f5bb410af865c3d4b4f15bf1447e
[darcs-mirrors/vector.git] / tests / Boilerplater.hs
1 module Boilerplater where
2
3 import Test.Framework.Providers.QuickCheck
4
5 import Language.Haskell.TH
6
7
8 testProperties :: [Name] -> Q Exp
9 testProperties nms = fmap ListE $ sequence [[| testProperty $(stringE prop_name) $(varE nm) |]
10 | nm <- nms
11 , Just prop_name <- [stripPrefix_maybe "prop_" (nameBase nm)]]
12
13 -- This nice clean solution doesn't quite work since I need to use lexically-scoped type
14 -- variables, which aren't supported by Template Haskell. Argh!
15 -- testProperties :: Q [Dec] -> Q Exp
16 -- testProperties mdecs = do
17 -- decs <- mdecs
18 -- property_exprs <- sequence [[| testProperty "$prop_name" $(return $ VarE nm) |]
19 -- | FunD nm _clauses <- decs
20 -- , Just prop_name <- [stripPrefix_maybe "prop_" (nameBase nm)]]
21 -- return $ LetE decs (ListE property_exprs)
22
23 stripPrefix_maybe :: String -> String -> Maybe String
24 stripPrefix_maybe prefix what
25 | what_start == prefix = Just what_end
26 | otherwise = Nothing
27 where (what_start, what_end) = splitAt (length prefix) what