update jinja2 per CVE-2024-34064
[cabal.git] / Cabal-tests / tests / UnitTests / Distribution / Utils / NubList.hs
blob61e25eec39befd013f0fc4b2d54a7da316f71418
1 -- to suppress WARNING in "Distribution.Compat.Prelude.Internal"
2 {-# OPTIONS_GHC -fno-warn-deprecations #-}
3 module UnitTests.Distribution.Utils.NubList
4 ( tests
5 ) where
7 import Prelude ()
8 import Distribution.Compat.Prelude.Internal
10 import Distribution.Utils.NubList
11 import Test.Tasty
12 import Test.Tasty.HUnit
13 import Test.Tasty.QuickCheck
15 tests :: [TestTree]
16 tests =
17 [ testCase "NubList retains ordering example" testOrdering
18 , testCase "NubList removes duplicates example" testDeDupe
19 , testProperty "NubList retains ordering" prop_Ordering
20 , testProperty "NubList removes duplicates" prop_DeDupe
21 , testProperty "fromNubList . toNubList = nub" prop_Nub
22 , testProperty "Monoid NubList Identity" prop_Identity
23 , testProperty "Monoid NubList Associativity" prop_Associativity
24 -- NubListR
25 , testProperty "NubListR removes duplicates from the right" prop_DeDupeR
28 someIntList :: [Int]
29 -- This list must not have duplicate entries.
30 someIntList = [ 1, 3, 4, 2, 0, 7, 6, 5, 9, -1 ]
32 testOrdering :: Assertion
33 testOrdering =
34 assertBool "Maintains element ordering:" $
35 fromNubList (toNubList someIntList) == someIntList
37 testDeDupe :: Assertion
38 testDeDupe =
39 assertBool "De-duplicates a list:" $
40 fromNubList (toNubList (someIntList ++ someIntList)) == someIntList
42 -- ---------------------------------------------------------------------------
43 -- QuickCheck properties for NubList
45 prop_Ordering :: [Int] -> Property
46 prop_Ordering xs =
47 mempty <> toNubList xs' === toNubList xs' <> mempty
48 where
49 xs' = nub xs
51 prop_DeDupe :: [Int] -> Property
52 prop_DeDupe xs =
53 fromNubList (toNubList (xs' ++ xs)) === xs' -- Note, we append primeless xs
54 where
55 xs' = nub xs
57 prop_DeDupeR :: [Int] -> Property
58 prop_DeDupeR xs =
59 fromNubListR (toNubListR (xs ++ xs')) === xs' -- Note, we prepend primeless xs
60 where
61 xs' = nub xs
63 prop_Nub :: [Int] -> Property
64 prop_Nub xs = rhs === lhs
65 where
66 rhs = fromNubList (toNubList xs)
67 lhs = nub xs
69 prop_Identity :: [Int] -> Bool
70 prop_Identity xs =
71 mempty `mappend` toNubList xs == toNubList xs `mappend` mempty
73 prop_Associativity :: [Int] -> [Int] -> [Int] -> Bool
74 prop_Associativity xs ys zs =
75 (toNubList xs `mappend` toNubList ys) `mappend` toNubList zs
76 == toNubList xs `mappend` (toNubList ys `mappend` toNubList zs)