@@ -1,6 +1,7 @@
11module Main (main) where
22
33import Control.Exception (SomeException(..), displayException)
4+import Data.Foldable (for_)
45import Data.Word (Word8, Word32, Word64)
56import Streamly.Test.Common (listEquals, checkListEqual, chooseInt)
67import Test.Hspec (Spec, hspec, describe)
@@ -467,6 +468,68 @@ wordBy =
467468 let wrds = words lst
468469 in if wrds == [] && length lst > 0 then [""] else wrds
469470
471+parseManyWordQuotedBy :: H.SpecWith ()
472+parseManyWordQuotedBy =
473+ describe "parseMany wordQuotedBy"
474+ $ for_ testCases
475+ $ \c@(kQ, lQ, rQ, fromLQ, input, expected) -> do
476+ let inpStrm = S.fromList input
477+
478+ esc '\\' = True
479+ esc _ = False
480+
481+ spc ' ' = True
482+ spc _ = False
483+
484+ parser = P.wordQuotedBy kQ esc lQ rQ fromLQ spc FL.toList
485+ result <- H.runIO $ S.toList $ S.parseMany parser inpStrm
486+ H.it (showCase c) $ result `H.shouldBe` expected
487+
488+ where
489+
490+ showCase (kQ, _, _, _, input, expected) =
491+ show kQ ++ ", " ++ input ++ " -> " ++ show expected
492+
493+ testCases =
494+ [ ( True
495+ , (== '\'')
496+ , (== '\'')
497+ , id
498+ , "The quick brown fox"
499+ , ["The", "quick", "brown", "fox"])
500+ , ( True
501+ , (== '\'')
502+ , (== '\'')
503+ , id
504+ , "The' quick brown' fox"
505+ , ["The' quick brown'", "fox"])
506+ , ( False
507+ , (== '\'')
508+ , (== '\'')
509+ , id
510+ , "The' quick brown' fox"
511+ , ["The quick brown", "fox"])
512+ , ( True
513+ , (== '[')
514+ , (== '[')
515+ , \x -> if x == '[' then ']' else error "Not an opening quote."
516+ , "The[ quick brown] fox"
517+ , ["The[ quick brown]", "fox"])
518+ , ( True
519+ , (== '[')
520+ , (== '[')
521+ , \x -> if x == '[' then ']' else error "Not an opening quote."
522+ , "The[ qui[ck] brown] \\ f[ ox]"
523+ , ["The[ qui[ck] brown]", " f[ ox]"])
524+ , ( False
525+ , (== '[')
526+ , (== '[')
527+ , \x -> if x == '[' then ']' else error "Not an opening quote."
528+ , "The[ qui[ck] brown] fox"
529+ , ["The qui[ck] brown", "fox"])
530+ ]
531+
532+
470533-- splitWithPass :: Property
471534-- splitWithPass =
472535-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
@@ -1106,6 +1169,7 @@ main =
11061169 prop ("P.takeP = Prelude.take") takeP
11071170 prop "P.groupBy = Prelude.head . Prelude.groupBy" groupBy
11081171 prop "many (P.wordBy ' ') = words'" wordBy
1172+ parseManyWordQuotedBy
11091173 prop "choice" choice
11101174 -- prop "" splitWithPass
11111175 -- prop "" splitWithFailLeft