graphql-engine/server/src-test/Control/Monad/MemoizeSpec.hs
Samir Talwar f48c882521 server: Share tests between CircularT and MemoizeT.
This abstracts `CircularT`'s test cases to work against "any" memoizer, and then runs them against `MemoizeT` as well.

Surprisingly (or not), this works without issue; `MemoizeT` passes all tests with a couple of extra instances.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5780
GitOrigin-RevId: 461880caf9220dc3f52d622a22e8b8bcd594e404
2022-09-08 19:38:49 +00:00

23 lines
856 B
Haskell

{-# LANGUAGE UndecidableInstances #-}
module Control.Monad.MemoizeSpec (spec) where
import Control.Monad.MemoizationSpecDefinition
import Control.Monad.Memoize
import Hasura.Prelude
import Test.Hspec
-- We need to add a couple of extra parameters, 'k' and 'v', to align with the
-- shape of a memoizer as understood by 'Memoizer'.
newtype MemoizeWithExtraParamsT k v m a = MemoizeWithExtraParamsT {unMemoizeWithExtraParamsT :: MemoizeT m a}
deriving newtype (Functor, Applicative, Monad, MonadTrans)
instance Memoizer MemoizeWithExtraParamsT where
runMemoizer = runMemoizeT . unMemoizeWithExtraParamsT
memoize name key = MemoizeWithExtraParamsT . memoizeOn name key . unMemoizeWithExtraParamsT
deriving newtype instance MonadState s m => MonadState s (MemoizeWithExtraParamsT k v m)
spec :: Spec
spec = memoizationSpec @MemoizeWithExtraParamsT