module Test.Hspec.Expectations.Matcher (matchList) where import Prelude hiding (showList) import Data.List matchList :: (Show a, Eq a) => [a] -> [a] -> Maybe String [a] xs matchList :: forall a. (Show a, Eq a) => [a] -> [a] -> Maybe String `matchList` [a] ys | forall (t :: * -> *) a. Foldable t => t a -> Bool null [a] extra Bool -> Bool -> Bool && forall (t :: * -> *) a. Foldable t => t a -> Bool null [a] missing = forall a. Maybe a Nothing | Bool otherwise = forall a. a -> Maybe a Just (ShowS err String "") where extra :: [a] extra = [a] xs forall a. Eq a => [a] -> [a] -> [a] \\ [a] ys missing :: [a] missing = [a] ys forall a. Eq a => [a] -> [a] -> [a] \\ [a] xs msgAndList :: String -> [a] -> ShowS msgAndList String msg [a] zs = String -> ShowS showString String msg forall b c a. (b -> c) -> (a -> b) -> a -> c . forall a. Show a => [a] -> ShowS showList [a] zs forall b c a. (b -> c) -> (a -> b) -> a -> c . String -> ShowS showString String "\n" optMsgList :: String -> [a] -> ShowS optMsgList String msg [a] zs = if forall (t :: * -> *) a. Foldable t => t a -> Bool null [a] zs then forall a. a -> a id else forall {a}. Show a => String -> [a] -> ShowS msgAndList String msg [a] zs err :: ShowS err :: ShowS err = String -> ShowS showString String "Actual list is not a permutation of expected list!\n" forall b c a. (b -> c) -> (a -> b) -> a -> c . forall {a}. Show a => String -> [a] -> ShowS msgAndList String " expected elements: " [a] ys forall b c a. (b -> c) -> (a -> b) -> a -> c . forall {a}. Show a => String -> [a] -> ShowS msgAndList String " actual elements: " [a] xs forall b c a. (b -> c) -> (a -> b) -> a -> c . forall {a}. Show a => String -> [a] -> ShowS optMsgList String " missing elements: " [a] missing forall b c a. (b -> c) -> (a -> b) -> a -> c . forall {a}. Show a => String -> [a] -> ShowS optMsgList String " extra elements: " [a] extra showList :: Show a => [a] -> ShowS showList :: forall a. Show a => [a] -> ShowS showList [a] xs = Char -> ShowS showChar Char '[' forall b c a. (b -> c) -> (a -> b) -> a -> c . forall (t :: * -> *) a b. Foldable t => (a -> b -> b) -> b -> t a -> b foldr forall b c a. (b -> c) -> (a -> b) -> a -> c (.) (Char -> ShowS showChar Char ']') (forall a. a -> [a] -> [a] intersperse (String -> ShowS showString String ", ") forall a b. (a -> b) -> a -> b $ forall a b. (a -> b) -> [a] -> [b] map forall a. Show a => a -> ShowS shows [a] xs)