packages feed

property-matchers 0.3.0.0 → 0.4.0.0

raw patch · 4 files changed

+57/−13 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- PropertyMatchers: allTrue :: Foldable f => f (Prop a) -> Prop a
+ PropertyMatchers: anyOf :: HasCallStack => Getting [a] s a -> PT a s
+ PropertyMatchers: checkAll :: Foldable f => f (Prop a) -> Prop a

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for property-matchers +## 0.4+* Fix `allOf1` which would fail on a non-empty input, instead of the opposite+* Add `anyOf`+* Rename `allTrue` to `checkAll`++ ## 0.3 * Add `fails` function, for asserting that an exception is thrown * Replace `propful` with `alignExact`@@ -27,6 +33,7 @@ * Rename kth to atIndex * Change error message formatting for predicate failure + ## predicate-transformers 0.17.0.0 -- 2024-10-13 * Rename multiple functions to shorter names with the intent that predicate-transformers be imported qualified.   In particular `also` renamed to `and`, `otherHand` renamed to `or`, etc.@@ -36,26 +43,32 @@ * Delete `Exceptional` class, folding it into the newly renamed `Boolish`. * Delete `predJust`, `predLeft`, and `predRight` in favor of `match` uses. + ## predicate-transformers 0.16.0.0 -- 2024-10-13 * Add predicate failure error messages that include the actual value under test and a message explaining what was expected. * Rename `just`, `left`, and `right` to `predJust`, `predLeft`, `predRight` + ## predicate-transformers 0.15.0.0 -- 2024-08-23 * Change `?` to right associative so that it works with `.`. + ## predicate-transformers 0.14.0.0 -- 2024-08-23 * Add `?` back in as a useful operator to work with `&`; `&` can be used as a predicate applicator, and `?` can be used as a predicate transformer applicator, allowing for a form of infix binary application like `x & f ? y = f x y`. * Add `match` back in as a type-restricted alias for `soleElementOf`. + ## predicate-transformers 0.13.0.0 -- 2024-07-23 * Remove `?` + ## predicate-transformers 0.12.0.0 -- 2024-07-23 * Rename `sole` to `soleElement` * Add `?`, an infix function application operator with lower   precedence than `!`. * Add `satAll = foldr also continue`. + ## predicate-transformers 0.11.0.0 -- 2024-07-21 * Add documentation. * Rename `onlyContains` to `sole`. Add `soleOf`, generalizing over `Fold`s.@@ -64,8 +77,8 @@ * Implement `traceFailFunShow`. * Change `Exceptional`'s method `assess` to make it possible to implement for functional predicates, and delete `traceFailFun`, now redundant. -## predicate-transformers 0.10.0.0 -- 2024-07-21 +## predicate-transformers 0.10.0.0 -- 2024-07-21 * Rename `oneOfTwo` to `otherHand`, for easier reading. * Set `also` and `otherHand` precedences to those of `&&` and `||`   respectively. That makes them work better with the precedence of@@ -79,8 +92,8 @@ * Make `otherHand` stop catching async exceptions. Otherwise a thread   being killed may appear as a predicate failure. -## predicate-transformers 0.9.0.0 -- 2024-07-21 +## predicate-transformers 0.9.0.0 -- 2024-07-21 * Add instance `Predicatory (e -> a)`. This will allow for adding extra   parameters to predicates, making it easier to compose them; maybe   these are called "functional predicates".@@ -89,6 +102,6 @@ * Tupling sugar renamed from `==>` to `:=>`, to allow it to be a pattern synonym. * Minor code style changes. -## predicate-transformers 0.1.0.0 -- 2019-10-05 +## predicate-transformers 0.1.0.0 -- 2019-10-05 * First version. Released on an unsuspecting world.
property-matchers.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4  name: property-matchers-version: 0.3.0.0+version: 0.4.0.0 synopsis: A library for tests, based on transforming and writing properties description:   This package provides ways to write properties for testing such that they compose nicely and are easy to debug.
src/PropertyMatchers.hs view
@@ -42,7 +42,8 @@   , alignLax   , elem   , compose-  , allTrue+  , checkAll+  , anyOf   , allOf1   , pair   , fun@@ -320,10 +321,22 @@ compose pr fa = tabulate (\r -> index pr r $ index fa r)  -- | Test all properties against one value.-allTrue :: (Foldable f) => f (Prop a) -> Prop a-allTrue ps a = foldr (\p r -> p a `and` r) (succeed a) ps-{-# INLINABLE allTrue #-}+checkAll :: (Foldable f) => f (Prop a) -> Prop a+checkAll ps a = foldr (\p r -> p a `and` r) (succeed a) ps+{-# INLINABLE checkAll #-} +-- | Test that a property succeeds against at least one value behind a+-- generalized getter. The corresponding `allOf` is just `traverseOf_`.+--+anyOf+  :: HasCallStack+  => Getting [a] s a+  -> PT a s+anyOf g p vs =+  foldr (\x r -> p x `or` r) (succeed vs) vsList+  where+  Const vsList = g (Const . pure) vs+ -- | Check that a property is true for all values behind a generalized getter --  and that there's at least one value for which it's true. allOf1@@ -331,9 +344,9 @@   => Getting [a] s a   -> PT a s allOf1 g p vs-  | [] <- vsList =+  | [] <- vsList = fail "non-empty for fold" vs+  | otherwise =     foldr (\x r -> p x `and` r) (succeed vs) vsList-  | otherwise = fail "non-empty for fold" vs   where   Const vsList = g (Const . pure) vs 
test/PropertyMatchersSpec.hs view
@@ -39,6 +39,11 @@ andsAndOrs (Error str) = error str andsAndOrs Succeed = P.succeed () +propertyFails :: P.Prop Text -> P.Prop String -> P.Prop (IO a)+propertyFails expectedProp actualProp =+  P.fails @P.PropertyException $ \(P.PropertyFailed _ (PP.renderStrict . PP.layoutCompact -> expected) (anythingToString -> actual)) ->+    expectedProp expected `P.and` actualProp actual+ check :: Testable IO a => Depth -> a -> IO () check d e = smallCheckM d e >>= \case   Nothing -> return ()@@ -58,6 +63,7 @@     P.succeed ()     P.succeed 1     P.succeed (\_ -> 1)+    P.succeed (error "not thrown")    it "fail" $ do     try (P.fail "test string" 42) >>= \case@@ -90,11 +96,17 @@       check 2 $ forAll $ \x y z -> unsafePerformIO $         (==) <$> runWithMsg (And x (Or y z)) <*> runWithMsg (Or (And x y) (And x z)) +  it "fails" $ do+    P.fail "test string" 42+      & P.fails @SomeException P.succeed+    P.fail "test string" 42+      & P.fails @P.PropertyException P.succeed++   it "bool" $ do     True & P.bool-    try (False & P.bool) >>= \case-      Left (PropertyFailed "True" "False") -> return ()-      r -> error $ "unexpected: " <> show r+    propertyFails (P.equals "True") (P.equals "False") $+      False & P.bool     it "equals" $ do@@ -134,3 +146,9 @@           [ P.match _Right :=> P.equals 2           , P.match _Left :=> P.succeed           ]++  describe "allOf1" $ do+    it "singleton" $ do+      Left 2 & P.allOf1 _Left ? P.equals 2+    it "empty" $ propertyFails (P.equals "non-empty for fold") P.succeed $+      Left 2 & P.allOf1 _Right ? P.equals 2