Skip to content

Commit

Permalink
sandwich: add shouldBeSet
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Jul 30, 2024
1 parent 9b6d1da commit f4e3bfb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sandwich/src/Test/Sandwich/Expectations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Test.Sandwich.Expectations where
import Control.Monad.IO.Class
import Control.Monad.IO.Unlift
import qualified Data.List as L
import qualified Data.Set as Set
import Data.String.Interpolate
import qualified Data.Text as T
import GHC.Stack
Expand Down Expand Up @@ -94,6 +95,12 @@ shouldNotContain haystack needle = case needle `L.isInfixOf` haystack of
True -> expectationFailure [i|Expected #{show haystack} not to contain #{show needle}|]
False -> return ()

-- | Asserts that the given lists are equal as sets.
shouldBeSet :: (HasCallStack, MonadIO m, Ord a, Show a) => [a] -> [a] -> m ()
shouldBeSet haystack needle = case Set.fromList needle == Set.fromList haystack of
True -> return ()
False -> expectationFailure [i|Expected #{show haystack} to equal as a set #{show needle}|]

-- | Asserts that the given list contains an item matching a predicate.
shouldNotContainPredicate :: (HasCallStack, MonadIO m, Show a) => [a] -> (a -> Bool) -> m ()
shouldNotContainPredicate haystack p = case L.find p haystack of
Expand Down

0 comments on commit f4e3bfb

Please sign in to comment.