regex-do 1.5 → 1.6
raw patch · 12 files changed
+241/−225 lines, 12 files
Files
- regex-do.cabal +4/−2
- src/Text/Regex/Do/Format.hs +1/−10
- src/Text/Regex/Do/Pad.hs +24/−0
- src/Text/Regex/Do/Pcre/Match.hs +51/−67
- src/Text/Regex/Do/Pcre/Matchf.hs +19/−0
- src/Text/Regex/Do/Pcre/Replace.hs +17/−19
- src/Text/Regex/Do/Pcre/Result.hs +1/−6
- src/Text/Regex/Do/Split.hs +60/−43
- src/Text/Regex/Do/TypeDo.hs +15/−0
- test/TestRegex/TestFormat.hs +8/−8
- test/TestRegex/TestPcre.hs +18/−47
- test/TestRegex/TestSplit.hs +23/−23
regex-do.cabal view
@@ -1,5 +1,5 @@ name: regex-do-version: 1.5+version: 1.6 synopsis: PCRE wrapper description: format, search, replace (String | ByteString) with PCRE regex. Utf8-safe author: Imants Cekusins@@ -17,14 +17,16 @@ Text.Regex.Do.Pcre.Match Text.Regex.Do.Pcre.Option Text.Regex.Do.Pcre.Replace- Text.Regex.Do.Pcre.Result Text.Regex.Do.Split Text.Regex.Do.Format Text.Regex.Do.TypeDo Text.Regex.Do.TypeRegex Text.Regex.Do.Convert+ Text.Regex.Do.Pad other-modules:+ Text.Regex.Do.Pcre.Matchf+ Text.Regex.Do.Pcre.Result ghc-options: -fwarn-unused-imports
src/Text/Regex/Do/Format.hs view
@@ -1,6 +1,5 @@ module Text.Regex.Do.Format- (pad,- Format(..)) where+ (Format(..)) where import Prelude as P import Text.Regex.Do.TypeDo@@ -49,14 +48,6 @@ repl1 = Replacement $ toByteString v bs1 = S.replace pat1 repl1 $ Body $ toByteString body --- | pad String with Char to total length of Int------ >>> pad '-' 5 "abc"--- "--abc"----pad::Char -> Int -> String -> String-pad c0 tot0 txt0 =- [const c0 p1 | p1 <- [1..(tot0 - (P.length txt0))]] ++ txt0 -- fold with index
+ src/Text/Regex/Do/Pad.hs view
@@ -0,0 +1,24 @@+module Text.Regex.Do.Pad+ (pad,pad') where+++{- | pad String with Char to total length of Int++ >>> pad '-' 5 "abc"++ "--abc" -}++pad::Char -> Int -> String -> String+pad c0 tot0 txt0 = p1 ++ txt0+ where p1 = pad_ c0 tot0 txt0++{- |>>> pad' '-' 5 "abc"++ "abc--" -}+pad'::Char -> Int -> String -> String+pad' c0 tot0 txt0 = txt0 ++ p1+ where p1 = pad_ c0 tot0 txt0+++pad_::Char -> Int -> String -> String+pad_ c0 tot0 txt0 = [const c0 p1 | p1 <- [1..(tot0 - (length txt0))]]
src/Text/Regex/Do/Pcre/Match.hs view
@@ -1,53 +1,75 @@ -- | see "Text.Regex.Base.RegexLike"-module Text.Regex.Do.Pcre.Match where+module Text.Regex.Do.Pcre.Match+ (Match(..),+ R.extract, -- | 'extract' is reexport from "Text.Regex.Base.RegexLike"+ makeRegexOpts) where import qualified Text.Regex.Base.RegexLike as R hiding (makeRegex)-import qualified Text.Regex.Base.RegexLike as R (makeRegex) import Text.Regex.Do.TypeDo import Text.Regex.Do.Pcre.Option as O import Text.Regex.Do.TypeRegex-import Data.ByteString-import Text.Regex.Do.Pcre.Result+import qualified Text.Regex.Do.Pcre.Result as R+import Text.Regex.Do.Pcre.Matchf -{- | 'match' covers all 'ExplicitMatch' funs+{- | 'match' covers all - compiler looks up the appropriate function depending on the result type -}-class ExplicitMatch n h => Match n h out where+ compiler looks up the appropriate function depending on the result type++ ('=~') is borrowed from "Text.Regex.Posix.Wrap",+ is a short version of 'match'. For those who put pattern & body in the right places.+ -}+class Match n h out where match::Pattern n -> Body h -> out+ (=~)::n -> h -> out+ (=~) n0 h0 = match (Pattern n0) (Body h0) --- | 'matchOnce'-instance ExplicitMatch n h => Match n h [h] where match = matchOnce--- | 'matchOnce''-instance ExplicitMatch n h => Match n h (Maybe MatchArray) where match = matchOnce'--- | 'matchTest'-instance ExplicitMatch n h => Match n h Bool where match = matchTest--- | 'matchAll'-instance ExplicitMatch n h => Match n h [[h]] where match = matchAll--- | 'matchAll''-instance ExplicitMatch n h => Match n h [MatchArray] where match = matchAll' +-- | match once+instance Rx_ n h => Match n h [h] where+ match = matchOnce+{- ^ >>> "^all" =~ "all the time"::[String] -class Rx_ n h =>- ExplicitMatch n h where+ \["all"\] -}+instance Rx_ n h => Match n h Bool where+ match = matchTest+{- ^ test - matchOnce::Pattern n -> Body h -> [h] -- ^ matched content- matchOnce r0 b0 = maybe [] id $ allMatches b0 $ matchOnce' r0 b0+ >>> "в" =~ "тихо в лесу"::Bool - matchOnce'::Pattern n -> Body h -> Maybe MatchArray -- ^ see "Text.Regex.Do.Pcre.Result"- matchOnce' r0 (Body b0) = R.matchOnce (r_ r0) b0+ True+ -} - matchTest::Pattern n -> Body h -> Bool- matchTest r0 (Body b0) = R.matchTest (r_ r0) b0+-- | match all+instance Rx_ n h => Match n h [[h]] where+ match = matchAll+{- ^ >>> "well" =~ "all is well that ends well"::[[ByteString]] - matchAll::Pattern n -> Body h -> [[h]] -- ^ matched content- matchAll r0 b0 = allMatches b0 $ matchAll' r0 b0+ \[["well"\],\["well"\]] -} - matchAll'::Pattern n -> Body h -> [MatchArray] -- ^ see "Text.Regex.Do.Pcre.Result"- matchAll' r0 (Body b0) = R.matchAll (r_ r0) b0+-- | match once+instance Rx_ n h => Match n h [PosLen] where+ match p0 b0 = maybe [] id $ poslen_ p0 b0+{- ^ >>> ("и"::String) =~ ("бывает и хуже"::String)::[PosLen] + \[(13,2)\] /Utf8/ -} +-- | match all+instance Rx_ n h => Match n h [[PosLen]] where+ match = poslen_ ++matchOnce::Rx_ n h => Pattern n -> Body h -> [h] -- ^ matched content+matchOnce r0 b0 = maybe [] id $ R.allMatches b0 $ marray_ r0 b0++matchTest::Rx_ n h => Pattern n -> Body h -> Bool+matchTest r0 (Body b0) = R.matchTest (r_ r0) b0++matchAll::Rx_ n h => Pattern n -> Body h -> [[h]] -- ^ matched content+matchAll r0 b0 = R.allMatches b0 $ marray_ r0 b0+++ -- | tweak Regex with options makeRegexOpts::Opt_ n => [O.Comp] -> [O.Exec] -> Pattern n -> Regex@@ -55,41 +77,3 @@ where c1 = O.comp comp0 e1 = O.exec exec0 rx1 = R.makeRegexOpts c1 e1 pat0---{- | accepts regex 'String'-- >>> matchTest (Pattern "^ab") (Body "abc")-- True--}-instance ExplicitMatch String String--- | accepts regex 'String'-instance ExplicitMatch String ByteString--- | accepts regex 'ByteString'-instance ExplicitMatch ByteString ByteString--- | accepts regex 'ByteString'-instance ExplicitMatch ByteString String--- | accepts 'Regex' made with 'makeRegexOpts'-instance ExplicitMatch Regex String--- | accepts 'Regex' made with 'makeRegexOpts'-instance ExplicitMatch Regex ByteString-----class Regex_ r where- r_::Pattern r -> Regex---instance Regex_ ByteString where- r_ (Pattern r0) = R.makeRegex r0--instance Regex_ String where- r_ (Pattern r0) = R.makeRegex r0--instance Regex_ Regex where- r_ (Pattern r0) = r0---type Rx_ n h = (R.Extract h, Regex_ n, R.RegexLike Regex h)
+ src/Text/Regex/Do/Pcre/Matchf.hs view
@@ -0,0 +1,19 @@+-- | __internal__ module, exposed only to show the instances+module Text.Regex.Do.Pcre.Matchf where++import Text.Regex.Do.TypeDo+import Text.Regex.Do.TypeRegex+import qualified Text.Regex.Do.Pcre.Result as R+import qualified Text.Regex.Base.RegexLike as R hiding (makeRegex)+++class (Rx_ n h, Functor f) => Matchf f n h where+ marray_::Pattern n -> Body h -> f MatchArray+ poslen_::Pattern n -> Body h -> f [PosLen]+ poslen_ r0 b0 = R.poslen $ marray_ r0 b0++instance Rx_ n h => Matchf Maybe n h where+ marray_ r0 (Body b0) = R.matchOnce (r_ r0) b0++instance Rx_ n h => Matchf [] n h where+ marray_ r0 (Body b0) = R.matchAll (r_ r0) b0
src/Text/Regex/Do/Pcre/Replace.hs view
@@ -14,16 +14,15 @@ import qualified Text.Regex.Do.Pcre.Option as O import qualified Text.Regex.Base.RegexLike as R import Text.Regex.Do.Convert-import Text.Regex.Do.Pcre.Match-import Text.Regex.Do.Pcre.Result+import Text.Regex.Do.Pcre.Match as M+import Text.Regex.Do.Pcre.Result as R import Text.Regex.Do.TypeDo import Text.Regex.Do.TypeRegex-+import Text.Regex.Do.Pcre.Matchf -class Replace a where- replace::Mr_ a =>- [ReplaceCase] -> Pattern a -> Replacement a -> Body a -> a+class Mr_ a [a] => Replace a where+ replace::[ReplaceCase] -> Pattern a -> Replacement a -> Body a -> a replace cases0 pat0 repl0 hay0 = if isUtf8 cases0 then utfFn2 else fn2 (pat2 pat0,repl0) hay0@@ -35,8 +34,7 @@ cOpt1 = comp cases0 - replaceGroup::Mr_ a =>- [ReplaceCase] -> Pattern a -> GroupReplacer a -> Body a -> a+ replaceGroup::[ReplaceCase] -> Pattern a -> GroupReplacer a -> Body a -> a replaceGroup cases0 pat0 repl0 = fn1 pat2 repl0 where pat2 = addOpt pat0 cOpt cOpt = comp cases0@@ -114,21 +112,21 @@ -- static-ronce::Mr_ a =>+ronce::Mr_ a [a] => (Pattern Regex, Replacement a) -> Body a -> a ronce (pat1, Replacement repl1) h1@(Body h0) =- let pl2 = let m1 = matchOnce' pat1 h1- in poslen m1+ let pl2 = let m1 = marray_ pat1 h1+ in R.poslen m1 in case pl2 of Nothing -> h0 Just lpl1 -> firstGroup lpl1 (repl1, h0) -rall::Mr_ a =>+rall::Mr_ a [a] => (Pattern Regex, Replacement a) -> Body a -> a rall (pat1, Replacement repl1) h1@(Body h0) =- let lpl1 = let m1 = matchAll' pat1 h1- in poslen m1::[[PosLen]]+ let lpl1 = let m1 = marray_ pat1 h1+ in R.poslen m1::[[PosLen]] foldFn1 lpl1 acc1 = firstGroup lpl1 (repl1,acc1) in P.foldr foldFn1 h0 lpl1 @@ -174,10 +172,10 @@ adjustPoslen (p0,l0) acc0 = (p0 + pos_adj acc0, l0) -ronceGroup::ExplicitMatch Regex a =>+ronceGroup::Rx_ a a => Pattern Regex -> GroupReplacer a -> Body a -> a ronceGroup pat0 repl0 h1@(Body h0) =- let m1 = matchOnce' pat0 h1::Maybe MatchArray+ let m1 = marray_ pat0 h1::Maybe MatchArray in case m1 of Nothing -> h0 Just ma1 -> let a1 = ReplaceAcc {@@ -187,10 +185,10 @@ in acc $ repl0 ma1 a1 -rallGroup::ExplicitMatch Regex a =>+rallGroup::Mr_ a [a] => Pattern Regex -> GroupReplacer a -> Body a -> a rallGroup pat0 repl0 b1@(Body b0) =- let ma1 = matchAll' pat0 b1::[MatchArray]+ let ma1 = marray_ pat0 b1::[MatchArray] acc1 = ReplaceAcc { acc = b0, pos_adj = 0 } in acc $ P.foldl (flip repl0) acc1 ma1 @@ -230,4 +228,4 @@ isUtf8 case0 = Utf8 `P.elem` case0 -type Mr_ a = (ExplicitMatch Regex a, Replace_ a, Opt_ a)+type Mr_ a out = (Match a a out, Rx_ a a, Replace_ a, Opt_ a)
src/Text/Regex/Do/Pcre/Result.hs view
@@ -1,9 +1,4 @@-module Text.Regex.Do.Pcre.Result- (poslen,- allMatches,- groupMatch,- R.extract -- | 'extract' is reexport from "Text.Regex.Base.RegexLike"- ) where+module Text.Regex.Do.Pcre.Result where import qualified Data.Array as A(elems) import Text.Regex.Base.RegexLike as R
src/Text/Regex/Do/Split.hs view
@@ -1,17 +1,12 @@ {- | see "Data.ByteString.Search" package - this module uses newtypes for args- regex is treated as ordinary String -} module Text.Regex.Do.Split (break,- breakFront,- breakEnd, replace, split,- splitEnd,- splitFront) where+ KeepNeedle(..)) where import qualified Data.ByteString.Search as S import Text.Regex.Do.TypeDo hiding (replace)@@ -19,89 +14,111 @@ import qualified Data.ByteString.Lazy as L import Prelude hiding (break) ++data KeepNeedle = Drop -- ^ needle between parts disappears+ | Front -- ^ needle sticks to front of next part+ | End -- ^ needle sticks to end of previous part++{- | >>> replace (Pattern "\n") (Replacement ",") (Body "a\nbc\nde")++ "a,bc,de" -}+replace::Pattern ByteString -> Replacement ByteString -> Body ByteString -> ByteString+replace (Pattern pat0)+ (Replacement replacement)+ (Body b0) = B.concat . L.toChunks $ l+ where l = S.replace pat1 replacement b0+ !pat1 = checkPattern pat0+++ -- ordinary: a b -- front: a \nb -- end: a\n b -{- | (front, end) : drop needle+{- | >>> break Drop (Pattern "\n") (Body "a\nbc\nde") - >>> break (Pattern ":") (Body "0123:oid:90")+ ("a", "bc\\nde") - ("0123", "oid:90") - >>> break (Pattern "\n") (Body "a\nbc\nde")+ >>> break Front (Pattern "\n") (Body "a\nbc\nde") - ("a", "bc\\nde") -}-break::Pattern ByteString -> Body ByteString -> (ByteString, ByteString)-break (Pattern pat0) (Body b0) = (h1,t2)+ ("a", "\\nbc\\nde")+++ >>> break End (Pattern "\n") (Body "a\nbc\nde")++ ("a\\n", "bc\\nde") -}++break::KeepNeedle ->+ Pattern ByteString -> Body ByteString ->+ (ByteString, ByteString)+break case0 = case case0 of+ Drop -> break'+ Front -> breakFront+ End -> breakEnd+++break'::Pattern ByteString -> Body ByteString -> (ByteString, ByteString)+break' (Pattern pat0) (Body b0) = (h1,t2) where (h1,t1) = S.breakOn pat1 b0 len1 = B.length pat1 t2 = B.drop len1 t1 !pat1 = checkPattern pat0 -{- | (front, needle + end)-- >>> breakFront (Pattern "\n") (Body "a\nbc\nde")-- ("a", "\\nbc\\nde") -} breakFront::Pattern ByteString -> Body ByteString -> (ByteString, ByteString) breakFront (Pattern pat0) (Body b0) = S.breakOn pat1 b0 where !pat1 = checkPattern pat0 -{- | (front + needle, end) - >>> breakEnd (Pattern "\n") (Body "a\nbc\nde")-- ("a\\n", "bc\\nde") -} breakEnd::Pattern ByteString -> Body ByteString -> (ByteString, ByteString) breakEnd (Pattern pat0) (Body b0) = S.breakAfter pat1 b0 where !pat1 = checkPattern pat0 -{- | >>> replace (Pattern "\n") (Replacement ",") (Body "a\nbc\nde") - "a,bc,de" -}-replace::Pattern ByteString -> Replacement ByteString -> Body ByteString -> ByteString-replace (Pattern pat0)- (Replacement replacement)- (Body b0) = B.concat . L.toChunks $ l- where l = S.replace pat1 replacement b0- !pat1 = checkPattern pat0 -{- | >>> split (Pattern "\n") (Body "a\nbc\nde")+{- | >>> split Drop (Pattern " ") (Body "a bc de") \["a", "bc", "de"] - >>> split (Pattern " ") (Body "a bc de")+ /space may be used/ - \["a", "bc", "de"]+ >>> split Front (Pattern "\n") (Body "a\nbc\nde") - >>> split (Pattern "\\s") (Body "abc de fghi ")+ \["a", "\\nbc", "\\nde"] - \["abc de fghi "] -}-split::Pattern ByteString -> Body ByteString -> [ByteString]-split (Pattern pat0)++ >>> split End (Pattern "\n") (Body "a\nbc\nde")++ \["a\\n", "bc\\n", "de"] -}++split::KeepNeedle ->+ Pattern ByteString -> Body ByteString ->+ [ByteString]+split case0 = case case0 of+ Drop -> split'+ Front -> splitFront+ End -> splitEnd+++split'::Pattern ByteString -> Body ByteString -> [ByteString]+split' (Pattern pat0) (Body b0) = S.split pat1 b0 where !pat1 = checkPattern pat0 -{- | >>> splitEnd (Pattern "\n") (Body "a\nbc\nde")-- \["a\\n", "bc\\n", "de"] -} splitEnd::Pattern ByteString -> Body ByteString -> [ByteString] splitEnd (Pattern pat0) (Body b0) = S.splitKeepEnd pat1 b0 where !pat1 = checkPattern pat0 -{- | >>> splitFront (Pattern "\n") (Body "a\nbc\nde")-- \["a", "\\nbc", "\\nde"] -} splitFront::Pattern ByteString -> Body ByteString -> [ByteString] splitFront (Pattern pat0) (Body b0) = S.splitKeepFront pat1 b0 where !pat1 = checkPattern pat0+ checkPattern::ByteString -> ByteString checkPattern bs0 = if bs0 == B.empty then error "empty pattern"
src/Text/Regex/Do/TypeDo.hs view
@@ -2,6 +2,7 @@ import Text.Regex.Base.RegexLike as R import Text.Regex.Do.TypeRegex+import Data.ByteString -- pcre@@ -34,3 +35,17 @@ type Opt_ n = R.RegexMaker Regex CompOption ExecOption n+type Rx_ n h = (R.Extract h, Regex_ n, R.RegexLike Regex h)+++class Regex_ r where+ r_::Pattern r -> Regex++instance Regex_ ByteString where+ r_ (Pattern r0) = R.makeRegex r0++instance Regex_ String where+ r_ (Pattern r0) = R.makeRegex r0++instance Regex_ Regex where+ r_ (Pattern r0) = r0
test/TestRegex/TestFormat.hs view
@@ -3,20 +3,20 @@ import Test.Hspec import Text.Regex.Do.Format+import Text.Regex.Do.Pad main::IO() main = hspec $ do describe "Habase.Bin.Format" $ do- it "list arg 0,0 repl []" $ do+ it "list arg 0,0 repl []" $ format "на первое {0}, на второе {0}" ([]::[String]) `shouldBe` "на первое {0}, на второе {0}"- it "list arg 0,0" $ do+ it "list arg 0,0" $ format "на первое {0}, на второе {0}" ["перловка"] `shouldBe` "на первое перловка, на второе перловка"- it "list arg 0,1" $ do+ it "list arg 0,1" $ format "Polly {0} a {1}" ["gets","cracker"] `shouldBe` "Polly gets a cracker"- it "map arg" $ do+ it "map arg" $ format "овчинка {a} не {b}" [("a","выделки"),("b","стоит")] `shouldBe` "овчинка выделки не стоит"- it "pad" $- pad '-' 5 "abc" `shouldBe` "--abc"- it "pad" $- pad '-' 3 "abcde" `shouldBe` "abcde"+ it "pad" $ pad '-' 5 "abc" `shouldBe` "--abc"+ it "pad'" $ pad' '-' 5 "abc" `shouldBe` "abc--"+ it "pad" $ pad '-' 3 "abcde" `shouldBe` "abcde"
test/TestRegex/TestPcre.hs view
@@ -1,60 +1,31 @@-{-# LANGUAGE FlexibleContexts, NoOverloadedStrings #-}+{-# LANGUAGE FlexibleContexts,+ TypeFamilies #-} module TestRegex.TestPcre where import Test.Hspec import Text.Regex.Do.TypeDo as M import Text.Regex.Do.Pcre.Match as M-import qualified Text.Regex.Do.Pcre.Result as R+import Text.Regex.Do.Pcre.Matchf as M import Text.Regex.Do.Convert-+import Data.ByteString main::IO()-main = do- test " ?String " Pattern id M.matchOnce'- test " [String] " Pattern id M.matchAll'- test " ?Bs " (Pattern . b) (b <$>) M.matchOnce'- test " [Bs] " (Pattern . b) (b <$>) M.matchAll'- hspec $ do- describe " matchTest " $ do- it " matchTest " $ do- M.matchTest (Pattern "^ша") (Body "шапка") `shouldBe` True- M.matchTest (Pattern "^cd") (Body "abcde") `shouldBe` False- M.matchTest (Pattern "^ab") (Body "abc") `shouldBe` True+main = hspec $ describe " matchTest " $ do+ it " ?String " $ (M.match (Pattern n) h::[String]) `shouldBe` ["d1"]+ it " [String] " $ (M.match (Pattern n) h::[[String]]) `shouldBe` [["d1"],["d1"]]+ it " ?ByteString " $ (M.match (Pattern $ b n) (b <$> h)::[ByteString]) `shouldBe` [b "d1"]+ it " [ByteString] " $ (M.match (Pattern $ b n) (b <$> h)::[[ByteString]]) `shouldBe` [[b "d1"],[b "d1"]]+ it " ша " $ M.match (Pattern ("^ша"::String)) (Body ("шапка"::String)) `shouldBe` True+ it " cd " $ M.match (Pattern ("^cd"::String)) (Body ("abcde"::String)) `shouldBe` False+ it " cd " $ M.poslen_ (Pattern ("^cd"::String)) (Body ("abcde"::String)) `shouldBe` []+ it " ab " $ M.match (Pattern ("^ab"::String)) (Body ("abc"::String)) `shouldBe` True+ it "doc 1" $ ("в"::ByteString) =~ ("тихо в лесу"::ByteString) `shouldBe` True+ it "doc 2" $ ("^all"::String) =~ ("all the time"::String) `shouldBe` (["all"]::[String])+ it "doc 3" $ ("^all"::ByteString) =~ ("all the time"::ByteString) `shouldBe` (["all"]::[ByteString])+ it "doc 4" $ ("well"::ByteString) =~ ("all is well that ends well"::ByteString) `shouldBe` ([["well"],["well"]]::[[ByteString]])+ it "doc 5" $ ("и"::String) =~ ("бывает и хуже"::String) `shouldBe` ([(13,2)]::[PosLen]) n = "d1" h = Body "abcd1efg d1hij" b = toByteString---test testCase patternCtor bodyCtor matchFn = hspec $ do- describe testCase $ do- it " val " $ do- R.allMatches h res `shouldSatisfy` check- it " tup " $- R.poslen res `shouldSatisfy` check- it " pl " $- R.poslen res `shouldSatisfy` check- where res = matchFn pat $ bodyCtor h- pat = patternCtor n----class Functor f => Pred f x where- check::f x -> Bool--instance Pred Maybe [String] where- check Nothing = False- check (Just _) = True--instance Pred [] [String] where- check [] = False- check (h:t) = True--instance Pred Maybe [PosLen] where- check Nothing = False- check (Just _) = True--instance Pred [] [PosLen] where- check [] = False- check (h:t) = True
test/TestRegex/TestSplit.hs view
@@ -13,42 +13,42 @@ main = hspec $ do describe "Habase.Regex.StringSearch.Search" $ do it "break :" $ do- break (Pattern ":") (Body "0123:oid:90") `shouldBe` ("0123", "oid:90")+ break Drop (Pattern ":") (Body "0123:oid:90") `shouldBe` ("0123", "oid:90") it "break" $ do- break (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ("a", "bc\nde")+ break Drop (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ("a", "bc\nde") it "break front" $ do- breakFront (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ("a", "\nbc\nde")+ break Front (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ("a", "\nbc\nde") it "break end" $ do- breakEnd (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ("a\n", "bc\nde")+ break End (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ("a\n", "bc\nde") it "replace" $ do S.replace (Pattern "\n") (Replacement ",") (Body "a\nbc\nde") `shouldBe` "a,bc,de" it "split" $ do- split (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ["a", "bc", "de"]+ split Drop (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ["a", "bc", "de"] it "split_sp" $ do- split (Pattern " ") (Body "a bc de") `shouldBe` ["a", "bc", "de"]+ split Drop (Pattern " ") (Body "a bc de") `shouldBe` ["a", "bc", "de"] it "split end" $ do- splitEnd (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ["a\n", "bc\n", "de"]+ split End (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ["a\n", "bc\n", "de"] it "split front" $ do- splitFront (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ["a", "\nbc", "\nde"]+ split Front (Pattern "\n") (Body "a\nbc\nde") `shouldBe` ["a", "\nbc", "\nde"] it "split regex" $ do- split (Pattern "\\s") (Body "abc de fghi ") `shouldBe` ["abc de fghi "]+ split Drop (Pattern "\\s") (Body "abc de fghi ") `shouldBe` ["abc de fghi "] describe "StringSearch.Search zerolength" $ do it "break" $ do- evaluate (errFn break) `shouldThrow` anyException+ evaluate (errFn $ break Drop) `shouldThrow` anyException it "break front" $ do- evaluate (errFn breakFront) `shouldThrow` anyException+ evaluate (errFn $ break Front) `shouldThrow` anyException it "break end" $ do- evaluate (errFn breakEnd) `shouldThrow` anyException+ evaluate (errFn $ break End) `shouldThrow` anyException it "replace" $ do evaluate (S.replace (Pattern B.empty) with body) `shouldThrow` anyException it "split" $ do- evaluate (errFn split) `shouldThrow` anyException+ evaluate (errFn $ split Drop) `shouldThrow` anyException it "split end" $ do- evaluate (errFn splitEnd) `shouldThrow` anyException+ evaluate (errFn $ split End) `shouldThrow` anyException it "split front" $ do- evaluate (errFn splitFront) `shouldThrow` anyException+ evaluate (errFn $ split Front) `shouldThrow` anyException describe "StringSearch.Search break delim not found" $ do it "delim not found" $ do@@ -59,16 +59,16 @@ body = Body "a\nbc\nde" body_sp = Body "a bc de" with = Replacement ","- break1 = break pat body- breakFront1 = breakFront pat body- breakEnd1 = breakEnd pat body+ break1 = break Drop pat body+ breakFront1 = break Front pat body+ breakEnd1 = break End pat body replace1 = S.replace pat with body- split1 = split pat body- split_sp1 = split pat_sp body_sp- splitFront1 = splitFront pat body- splitEnd1 = splitEnd pat body+ split1 = split Drop pat body+ split_sp1 = split Drop pat_sp body_sp+ splitFront1 = split Front pat body+ splitEnd1 = split End pat body errFn fn1 = fn1 (Pattern B.empty) body b = toByteString -- break delim not found pat_nf = Pattern ":"- break_nf = break pat_nf body+ break_nf = break Drop pat_nf body