{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Test.Util.WithEq (
    Id (..)
  , WithEq (..)
  ) where

import           Data.Function (on)
import           GHC.Generics (Generic)

newtype Id = Id Word
  deriving stock   (Int -> Id -> ShowS
[Id] -> ShowS
Id -> String
(Int -> Id -> ShowS)
-> (Id -> String) -> ([Id] -> ShowS) -> Show Id
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Id -> ShowS
showsPrec :: Int -> Id -> ShowS
$cshow :: Id -> String
show :: Id -> String
$cshowList :: [Id] -> ShowS
showList :: [Id] -> ShowS
Show, (forall x. Id -> Rep Id x)
-> (forall x. Rep Id x -> Id) -> Generic Id
forall x. Rep Id x -> Id
forall x. Id -> Rep Id x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Id -> Rep Id x
from :: forall x. Id -> Rep Id x
$cto :: forall x. Rep Id x -> Id
to :: forall x. Rep Id x -> Id
Generic)
  deriving newtype (Id -> Id -> Bool
(Id -> Id -> Bool) -> (Id -> Id -> Bool) -> Eq Id
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Id -> Id -> Bool
== :: Id -> Id -> Bool
$c/= :: Id -> Id -> Bool
/= :: Id -> Id -> Bool
Eq, Eq Id
Eq Id =>
(Id -> Id -> Ordering)
-> (Id -> Id -> Bool)
-> (Id -> Id -> Bool)
-> (Id -> Id -> Bool)
-> (Id -> Id -> Bool)
-> (Id -> Id -> Id)
-> (Id -> Id -> Id)
-> Ord Id
Id -> Id -> Bool
Id -> Id -> Ordering
Id -> Id -> Id
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Id -> Id -> Ordering
compare :: Id -> Id -> Ordering
$c< :: Id -> Id -> Bool
< :: Id -> Id -> Bool
$c<= :: Id -> Id -> Bool
<= :: Id -> Id -> Bool
$c> :: Id -> Id -> Bool
> :: Id -> Id -> Bool
$c>= :: Id -> Id -> Bool
>= :: Id -> Id -> Bool
$cmax :: Id -> Id -> Id
max :: Id -> Id -> Id
$cmin :: Id -> Id -> Id
min :: Id -> Id -> Id
Ord, Int -> Id
Id -> Int
Id -> [Id]
Id -> Id
Id -> Id -> [Id]
Id -> Id -> Id -> [Id]
(Id -> Id)
-> (Id -> Id)
-> (Int -> Id)
-> (Id -> Int)
-> (Id -> [Id])
-> (Id -> Id -> [Id])
-> (Id -> Id -> [Id])
-> (Id -> Id -> Id -> [Id])
-> Enum Id
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Id -> Id
succ :: Id -> Id
$cpred :: Id -> Id
pred :: Id -> Id
$ctoEnum :: Int -> Id
toEnum :: Int -> Id
$cfromEnum :: Id -> Int
fromEnum :: Id -> Int
$cenumFrom :: Id -> [Id]
enumFrom :: Id -> [Id]
$cenumFromThen :: Id -> Id -> [Id]
enumFromThen :: Id -> Id -> [Id]
$cenumFromTo :: Id -> Id -> [Id]
enumFromTo :: Id -> Id -> [Id]
$cenumFromThenTo :: Id -> Id -> Id -> [Id]
enumFromThenTo :: Id -> Id -> Id -> [Id]
Enum, Id
Id -> Id -> Bounded Id
forall a. a -> a -> Bounded a
$cminBound :: Id
minBound :: Id
$cmaxBound :: Id
maxBound :: Id
Bounded, Integer -> Id
Id -> Id
Id -> Id -> Id
(Id -> Id -> Id)
-> (Id -> Id -> Id)
-> (Id -> Id -> Id)
-> (Id -> Id)
-> (Id -> Id)
-> (Id -> Id)
-> (Integer -> Id)
-> Num Id
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: Id -> Id -> Id
+ :: Id -> Id -> Id
$c- :: Id -> Id -> Id
- :: Id -> Id -> Id
$c* :: Id -> Id -> Id
* :: Id -> Id -> Id
$cnegate :: Id -> Id
negate :: Id -> Id
$cabs :: Id -> Id
abs :: Id -> Id
$csignum :: Id -> Id
signum :: Id -> Id
$cfromInteger :: Integer -> Id
fromInteger :: Integer -> Id
Num)

-- | Use this type to add an `Eq` instance for types that don't have one or
-- for which one doesn't make sense, but an `Eq` instance is needed for
-- testing purposes.
--
-- E.g., `ImmutableDB.Iterator` needs an `Eq` instance in the q-s-m tests
data WithEq a = WithEq
    { forall a. WithEq a -> Id
getId    :: Id
    , forall a. WithEq a -> a
unWithEq :: a
    }
  deriving (Int -> WithEq a -> ShowS
[WithEq a] -> ShowS
WithEq a -> String
(Int -> WithEq a -> ShowS)
-> (WithEq a -> String) -> ([WithEq a] -> ShowS) -> Show (WithEq a)
forall a. Show a => Int -> WithEq a -> ShowS
forall a. Show a => [WithEq a] -> ShowS
forall a. Show a => WithEq a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> WithEq a -> ShowS
showsPrec :: Int -> WithEq a -> ShowS
$cshow :: forall a. Show a => WithEq a -> String
show :: WithEq a -> String
$cshowList :: forall a. Show a => [WithEq a] -> ShowS
showList :: [WithEq a] -> ShowS
Show, (forall x. WithEq a -> Rep (WithEq a) x)
-> (forall x. Rep (WithEq a) x -> WithEq a) -> Generic (WithEq a)
forall x. Rep (WithEq a) x -> WithEq a
forall x. WithEq a -> Rep (WithEq a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (WithEq a) x -> WithEq a
forall a x. WithEq a -> Rep (WithEq a) x
$cfrom :: forall a x. WithEq a -> Rep (WithEq a) x
from :: forall x. WithEq a -> Rep (WithEq a) x
$cto :: forall a x. Rep (WithEq a) x -> WithEq a
to :: forall x. Rep (WithEq a) x -> WithEq a
Generic)

instance Eq (WithEq a) where
  == :: WithEq a -> WithEq a -> Bool
(==) = Id -> Id -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Id -> Id -> Bool)
-> (WithEq a -> Id) -> WithEq a -> WithEq a -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` WithEq a -> Id
forall a. WithEq a -> Id
getId