Skip to content

Instantly share code, notes, and snippets.

@L7R7
Last active January 9, 2023 15:46
Show Gist options
  • Select an option

  • Save L7R7/b3be60a1b4138b7aa0f9f2719e299f86 to your computer and use it in GitHub Desktop.

Select an option

Save L7R7/b3be60a1b4138b7aa0f9f2719e299f86 to your computer and use it in GitHub Desktop.
minimal demo of a contramap-like combinator to modify the outer resource of a spec which would make it possible to combine several specs into one large spec
{-# LANGUAGE DataKinds #-}
import Test.Syd
data Outers = Outers
{ foo :: Int,
bar :: String
}
fullSpec :: TestDef (Outers : otherOuters) ()
fullSpec = do
contramapOuter foo fooSpec
contramapOuter bar barSpec
fooSpec :: TestDef (Int : otherOuters) ()
fooSpec = itWithOuter "foo" $ \i -> i `shouldBe` 3
barSpec :: TestDef (String : otherOuters) ()
barSpec = itWithOuter "bar" $ \s -> s `shouldBe` "s"
-- is there something like that? Is it even possible to implement?
contramapOuter ::
(outer -> newOuter) ->
TestDef (newOuter : otherOuters) () ->
TestDef (outer : otherOuters) ()
contramapOuter = _
@L7R7
Copy link
Author

L7R7 commented Jan 9, 2023

It works with beforeAllWith:

contramapOuter :: (previousOuter -> newOuter)
  -> TestDefM (newOuter : previousOuter : otherOuters) inner result
  -> TestDefM (previousOuter : otherOuters) inner result
contramapOuter f = beforeAllWith (pure . f)

https://twitter.com/kerckhove_ts/status/1612470104113184770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment