1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 05:41:54 +03:00
semantic/test/Data/Functor/Classes/Ord/Generic/Spec.hs

30 lines
863 B
Haskell
Raw Normal View History

module Data.Functor.Classes.Ord.Generic.Spec where
import Data.Functor.Classes.Ord.Generic
import Data.Functor.Listable
import GHC.Generics
import Test.Hspec
import Test.Hspec.LeanCheck
spec :: Spec
spec = parallel $ do
describe "genericLiftCompare" $ do
prop "equivalent to derived compare for product types" $
\ a b -> genericLiftCompare compare a b `shouldBe` compare a (b :: Product Int)
prop "equivalent to derived compare for sum types" $
\ a b -> genericLiftCompare compare a b `shouldBe` compare a (b :: Sum Int)
data Product a = Product a a a
deriving (Eq, Generic1, Ord, Show)
instance Listable a => Listable (Product a) where
tiers = cons3 Product
data Sum a = Sum1 a | Sum2 a | Sum3 a
deriving (Eq, Generic1, Ord, Show)
instance Listable a => Listable (Sum a) where
tiers = cons1 Sum1 \/ cons1 Sum2 \/ cons1 Sum3