regex-applicative 0.3.2 → 0.3.2.1
raw patch · 4 files changed
+60/−3 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGES.md +6/−0
- Text/Regex/Applicative/Common.hs +3/−2
- regex-applicative.cabal +3/−1
- tests/StateQueue.hs +48/−0
CHANGES.md view
@@ -1,6 +1,12 @@ Changes ======= +0.3.2.1+-------++* Use strict left fold in decimal/hexadecimal+* Include a missing test module in the sdist tarball+ 0.3.2 -----
Text/Regex/Applicative/Common.hs view
@@ -11,6 +11,7 @@ ) where import Data.Char+import Data.List (foldl') import Text.Regex.Applicative @@ -33,8 +34,8 @@ -- | Parse decimal number without sign. decimal :: Num a => RE Char a-decimal = foldl (\d i -> d*10 + i) 0 <$> some digit+decimal = foldl' (\d i -> d*10 + i) 0 <$> some digit -- | Parse decimal number without sign. hexadecimal :: Num a => RE Char a-hexadecimal = foldl (\d i -> d*16 + i) 0 <$> some hexDigit+hexadecimal = foldl' (\d i -> d*16 + i) 0 <$> some hexDigit
regex-applicative.cabal view
@@ -1,5 +1,5 @@ Name: regex-applicative-Version: 0.3.2+Version: 0.3.2.1 Synopsis: Regex-based parsing with applicative interface Description: regex-applicative is a Haskell library for parsing using regular expressions.@@ -43,6 +43,8 @@ tests main-is: test.hs+ other-modules:+ StateQueue GHC-Options: -threaded Default-language: Haskell2010 Build-depends: base < 5,
+ tests/StateQueue.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables #-}+module StateQueue where++import Test.Tasty+import Test.Tasty.SmallCheck+import Test.SmallCheck.Series+import Control.Applicative+import Text.Regex.Applicative.StateQueue as SQ++fromElems :: [(a, Maybe Int)] -> StateQueue a+fromElems = foldl f SQ.empty+ where+ f sq (x, mbKey) = maybe insert insertUnique mbKey x sq++size :: StateQueue a -> Int+size = length . getElements++instance (Monad m, Serial m a) => Serial m (StateQueue a) where+ series = fromElems <$> series++stateQueueTests = testGroup "StateQueue"+ [ testProperty "Insertion increments the # of elements" $+ \sq (i :: Int) -> size (insert i sq) == size sq + 1+ , testProperty "insertUnique increments the # of elements by 0 or 1" $+ \sq (i :: Int) ->+ let d = size (insertUnique i i sq) - size sq+ in d == 0 || d == 1+ , testProperty "insertUnique is idempotent" $+ \sq (i :: Int) ->+ let f = insertUnique i i+ in f sq == (f . f) sq+ , testProperty "insert doesn't affect insertUnique" $+ \(i :: Int) -> exists $ \sq ->+ let sq' = insert i sq+ in insertUnique i i sq' /= sq'+ , testProperty "insertUnique only cares about keys, not values" $+ \sq i j ->+ let sq' = insertUnique i i sq+ in insertUnique i j sq' == sq'+ , testProperty "insert puts in the back" $+ \sq (i :: Int) ->+ let sq' = insert i sq+ in last (getElements sq') == i+ , testProperty "insertUnique puts in the back" $+ \sq i ->+ let sq' = insertUnique i i sq+ in sq' /= sq ==> last (getElements sq') == i+ ]