regex-posix-unittest 1.0 → 1.1
raw patch · 2 files changed
+29/−15 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- Main.hs +25/−13
- regex-posix-unittest.cabal +4/−2
Main.hs view
@@ -1,19 +1,18 @@ module Main where import Control.Monad-import Control.Monad.Error+import Control.Monad.Error() import Data.Array import Data.Bits((.|.)) import Data.List-import Data.Monoid+--import Data.Monoid import Data.Sequence(Seq) import Data.String import Data.Typeable-import Data.Version+import Data.Version() import System.Environment import Text.Regex.Base import qualified Data.Foldable as F-import qualified Data.Sequence as Seq import Paths_regex_posix_unittest(getDataFileName,version) import qualified Data.ByteString.Char8 as S@@ -32,8 +31,6 @@ dictionary :: [Char] dictionary = ['a'..'c']++['A'..'C']++"_" -instance IsString (Seq Char) where- fromString = Seq.fromList class StringIs a where toString :: a -> String instance StringIs [Char] where toString = id@@ -43,15 +40,19 @@ type A = Array Int (Int,Int) +maxItems :: Int+maxItems=100++testOne :: t -> (t -> t1 -> Array Int (Int, Int)) -> t1 -> String testOne s op r = let foo :: String- foo = concatMap (\(o,l) -> show (o,(o+l))) (elems (op s r :: Array Int (Int,Int)))+ foo = concatMap (\(o,l) -> show (o,(o+l))) (take maxItems $ elems (op s r :: Array Int (Int,Int))) in if null foo then "NOMATCH" else foo testOne' :: A -> String testOne' input = let foo :: String- foo = concatMap (\(o,l) -> show (o,(o+l))) (elems input)+ foo = concatMap (\(o,l) -> show (o,(o+l))) (take maxItems $ elems input) in if null foo then "NOMATCH" else foo toTest :: String -> (Int,String,String,String)@@ -72,6 +73,7 @@ regex' = if regex == "SAME" then oldRegex else regex in (regex',(read n,regex',input',noQ output)) +load,load' :: FilePath -> IO [(Int, String, String, String)] load x' = do text <- readFile x' return $ map toTest (lines text)@@ -119,20 +121,24 @@ vals <- liftM concat (mapM (checkTest opM) =<< load' filepath) return (filepath,vals) +checkTests :: (RType -> RSource -> Either String A) -> IO [(String, [Int])] checkTests opM = do- dataFiles <- return . lines =<< readFile =<< getDataFileName "test-manifest.txt"- mapM (checkFile opM) dataFiles+ dataFileList <- return . lines =<< readFile =<< getDataFileName "test-manifest.txt"+ mapM (checkFile opM) dataFileList +manifest :: String manifest="test-manifest.txt" +dataFiles :: [String] dataFiles=["basic3.txt","class.txt","right-assoc.txt","left-assoc.txt","forced-assoc.txt","nullsub3.txt","repetition2.txt","totest.txt"] type PFT a = RegexContext Posix.Regex RType a => RType -> RSource -> Either String a posix :: PFT a-posix x r = let q :: Either String Posix.Regex- q = makeRegexOptsM (defaultCompOpt .|. Posix.compIgnoreCase) defaultExecOpt r- in q >>= \ r -> return (match r x)+posix x reg =+ let q :: Either String Posix.Regex+ q = makeRegexOptsM (defaultCompOpt .|. Posix.compIgnoreCase) defaultExecOpt reg+ in q >>= \ s -> return (match s x) unN :: String -> String unN ('\\':'n':xs) = '\n':unN xs@@ -158,8 +164,14 @@ putStrLn $ "Count of matches = "++show c1 putStrLn $ "Matches found = "++show (length b1) mapM_ (putStrLn . testOne') b1+manual _ = error "wrong arguments to regex-posix-unittest's manual function" +main :: IO () main = do+ putStr "regex-posix-unittest version: "+ print version+ putStr "regex-posix-unittest testing Text.Regex.Posix version: "+ print Posix.getVersion_Text_Regex_Posix manifestFile <- getDataFileName manifest a <- getArgs if length a == 2
regex-posix-unittest.cabal view
@@ -1,5 +1,5 @@ name: regex-posix-unittest-version: 1.0+version: 1.1 cabal-version: >=1.2 license: BSD3 license-File: LICENSE@@ -17,7 +17,9 @@ basic3.txt,class.txt,forced-assoc.txt,nullsub3.txt,repetition2.txt,right-assoc.txt,totest.txt,left-assoc.txt,osx-bsd-critical.txt executable regex-posix-unittest- build-depends: regex-base >= 0.93.1, base >= 2.0, regex-posix >= 0.93, bytestring, containers, array, mtl+ build-depends: regex-base >= 0.93.1, base >=4 && < 5, regex-posix >= 0.93, bytestring, containers, array, mtl main-is: Main.hs other-modules: Paths_regex_posix_unittest extensions: FlexibleInstances, FlexibleContexts,Rank2Types+ GHC-Options: -Wall -O2 -funbox-strict-fields+ GHC-Prof-Options: -auto-all