test-framework-th-prime 0.0.9 → 0.0.10
raw patch · 2 files changed
+33/−12 lines, 2 files
Files
Test/Framework/TH/Prime/Parser.hs view
@@ -8,10 +8,22 @@ import Data.List import Language.Haskell.Exts.Extension import Language.Haskell.Exts.Parser+#if MIN_VERSION_haskell_src_exts(1, 18, 0)+import Language.Haskell.Exts.SrcLoc+#endif import Language.Haskell.Exts.Syntax hiding (VarName, Exp) import Language.Haskell.TH hiding (Match, Extension (..)) import Language.Preprocessor.Cpphs hiding (Ident) +#if MIN_VERSION_haskell_src_exts(1, 18, 0)+-- location field for haskell-src-exts-1.18+#define L SrcSpanInfo+#define loc _+#else+#define L+#define loc+#endif+ ---------------------------------------------------------------- symbol :: String -> Exp@@ -43,7 +55,11 @@ getTests :: FilePath -> IO ([String], [String]) getTests file = do+#if MIN_VERSION_haskell_src_exts(1, 18, 0)+ ParseOk (Module _ _ _ _ decls) <- parseTest file+#else ParseOk (Module _ _ _ _ _ _ decls) <- parseTest file+#endif let funs = map fromFunBind $ filter isFunBind decls pats = map fromPatBind $ filter isPatBind decls names = funs ++ pats@@ -52,7 +68,7 @@ isProp = ("prop_" `isPrefixOf`) isCase = ("case_" `isPrefixOf`) -parseTest :: FilePath -> IO (ParseResult Module)+parseTest :: FilePath -> IO (ParseResult (Module L)) parseTest file = do raw <- readFile file parseModuleWithMode (opt raw) . pack <$> go raw@@ -72,8 +88,8 @@ #else toExtention = read . toStr #endif- toStr (Ident str) = str- toStr (Symbol str) = str+ toStr (Ident loc str) = str+ toStr (Symbol loc str) = str opt raw = defaultParseMode { #if MIN_VERSION_haskell_src_exts(1, 14, 0) extensions = nub $ EnableExtension TemplateHaskell : exts raw@@ -86,25 +102,30 @@ ---------------------------------------------------------------- -isFunBind :: Decl -> Bool-isFunBind (FunBind _) = True-isFunBind _ = False+isFunBind :: Decl L -> Bool+isFunBind (FunBind loc _) = True+isFunBind _ = False -isPatBind :: Decl -> Bool+isPatBind :: Decl L -> Bool isPatBind PatBind{} = True isPatBind _ = False -fromPatBind :: Decl -> String+fromPatBind :: Decl L -> String #if MIN_VERSION_haskell_src_exts(1, 16, 0)-fromPatBind (PatBind _ (PVar (Ident name)) _ _) = name-fromPatBind (PatBind _ (PVar (Symbol name)) _ _) = name+fromPatBind (PatBind _ (PVar loc (Ident loc name)) _ _) = name+fromPatBind (PatBind _ (PVar loc (Symbol loc name)) _ _) = name #else fromPatBind (PatBind _ (PVar (Ident name)) _ _ _) = name fromPatBind (PatBind _ (PVar (Symbol name)) _ _ _) = name #endif fromPatBind _ = error "fromPatBind" -fromFunBind :: Decl -> String+fromFunBind :: Decl L -> String+#if MIN_VERSION_haskell_src_exts(1, 18, 0)+fromFunBind (FunBind _floc (Match _ (Ident _iloc name) _ _ _:_)) = name+fromFunBind (FunBind _floc (Match _ (Symbol _sloc name) _ _ _:_)) = name+#else fromFunBind (FunBind (Match _ (Ident name) _ _ _ _:_)) = name fromFunBind (FunBind (Match _ (Symbol name) _ _ _ _:_)) = name+#endif fromFunBind _ = error "fromFunBind"
test-framework-th-prime.cabal view
@@ -1,5 +1,5 @@ Name: test-framework-th-prime-Version: 0.0.9+Version: 0.0.10 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3