@@ -1,8 +1,11 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
13module QC.Combinator where
24
35import Control.Applicative
6+import Data.Maybe (fromJust, isJust)
47import Data.Word (Word8)
5−import QC.Common (Repack, parseBS, repackBS)
8+import QC.Common (Repack, parseBS, repackBS, toLazyBS)
69import Test.Framework (Test)
710import Test.Framework.Providers.QuickCheck2 (testProperty)
811import Test.QuickCheck
@@ -22,6 +25,13 @@ count (Positive (Small n)) rs s =
2225 (length <$> parseBS (C.count n (P.string s)) input) == Just n
2326 where input = repackBS rs (B.concat (replicate (n+1) s))
2427
28+lookAhead :: NonEmptyList Word8 -> Bool
29+lookAhead (NonEmpty xs) =
30+ let ys = B.pack xs
31+ withLookAheadThenConsume = (\x y -> (x, y)) <$> C.lookAhead (P.string ys) <*> P.string ys
32+ mr = parseBS withLookAheadThenConsume $ toLazyBS ys
33+ in isJust mr && fst (fromJust mr) == snd (fromJust mr)
34+
2535match :: Int -> NonNegative Int -> NonNegative Int -> Repack -> Bool
2636match n (NonNegative x) (NonNegative y) rs =
2737 parseBS (P.match parser) (repackBS rs input) == Just (input, n)
@@ -35,5 +45,6 @@ tests :: [Test]
3545tests = [
3646 testProperty "choice" choice
3747 , testProperty "count" count
48+ , testProperty "lookAhead" lookAhead
3849 , testProperty "match" match
3950 ]