2022-03-08 11:22:20 +03:00
|
|
|
module Hasura.RQL.IR.SelectSpec (spec) where
|
|
|
|
|
|
|
|
import Data.Bifoldable
|
2022-04-06 01:08:43 +03:00
|
|
|
import Hasura.Backends.Postgres.RQLGenerator
|
|
|
|
import Hasura.Generator.Common (defaultRange)
|
2022-03-08 11:22:20 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.IR.Select (AnnSelectG (..), bifoldMapAnnSelectG)
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.SQL.Backend
|
2022-03-08 11:22:20 +03:00
|
|
|
import Hedgehog
|
|
|
|
import Hedgehog.Gen (int)
|
|
|
|
import Test.Hspec
|
|
|
|
import Test.Hspec.Hedgehog (hedgehog)
|
|
|
|
|
|
|
|
newtype MyPair (b :: BackendType) r v = MyPair (r, v)
|
|
|
|
deriving stock (Show)
|
|
|
|
deriving newtype (Foldable, Bifoldable)
|
|
|
|
|
|
|
|
genMyPair :: MonadGen m => m r -> m v -> m (MyPair b r v)
|
|
|
|
genMyPair genR genV = do
|
|
|
|
r <- genR
|
|
|
|
v <- genV
|
|
|
|
pure $ MyPair (r, v)
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
|
|
|
describe "bifoldMapAnnSelectG" $ do
|
2022-06-09 19:39:50 +03:00
|
|
|
let singleton :: a -> [a]
|
|
|
|
singleton x = [x]
|
|
|
|
|
2022-03-08 11:22:20 +03:00
|
|
|
it "bifoldMapAnnSelectG (const mempty) == foldMap" $
|
|
|
|
hedgehog $ do
|
|
|
|
annSelectG :: AnnSelectG ('Postgres 'Vanilla) (MyPair ('Postgres 'Vanilla) Int) Int <-
|
|
|
|
forAll $
|
2022-04-06 01:08:43 +03:00
|
|
|
genAnnSelectG (int defaultRange) (genMyPair (int defaultRange) (int defaultRange))
|
2022-03-08 11:22:20 +03:00
|
|
|
bifoldMapAnnSelectG (const []) singleton annSelectG === foldMap singleton annSelectG
|
|
|
|
bifoldMapAnnSelectG singleton (const []) annSelectG === foldMap (foldMap $ bifoldMap singleton (const [])) (_asnFields annSelectG)
|