1module Data.List.CompatSpec (main, spec) where
2
3import           Test.Hspec
4import           Data.List.Compat
5
6data Asymmetric = A | B deriving Show
7
8instance Eq Asymmetric where
9  A == _ = True
10  B == _ = False
11
12main :: IO ()
13main = hspec spec
14
15spec :: Spec
16spec = do
17  describe "dropWhileEnd" $ do
18    it "drops the largest suffix of a list in which a predicate holds for all elements" $ do
19      dropWhileEnd (== ' ') "foo "    `shouldBe` "foo"
20      dropWhileEnd (== ' ') "foo bar" `shouldBe` "foo bar"
21  describe "isSubsequenceOf" $ do
22    it "returns True if the first list is a subsequence of the second list" $ do
23      isSubsequenceOf "GHC" "The Glorious Haskell Compiler" `shouldBe` True
24      isSubsequenceOf "JHC" "The Glorious Haskell Compiler" `shouldBe` False
25  describe "nub" $
26    it "preserves the order of arguments to (==)" $
27      nub [A, B] `shouldBe` [A]
28  describe "nubBy" $
29    it "preserves the order of arguments to the equality function" $
30      nubBy (<) "12" `shouldBe` "1"
31  describe "sortOn" $ do
32    it "sorts a list by comparing the results of a key function applied to each element" $ do
33      sortOn (>='b') "cba" `shouldBe` "acb"
34  describe "uncons" $ do
35    it "decomposes a list into its head and tail" $ do
36      uncons ""   `shouldBe` Nothing
37      uncons "12" `shouldBe` Just ('1', "2")
38  describe "union" $
39    it "nubs arguments in the same order as (==)" $ do
40      union [A] [A, B] `shouldBe` [A]
41  describe "unionBy" $
42    it "nubs arguments in the same order as nubBy's equality function" $ do
43      unionBy (<) "1" "21" `shouldBe` "11"
44