1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Formulate a merge law.

This commit is contained in:
Rob Rix 2016-07-26 13:03:13 -04:00
parent 475c97190c
commit df4621622a

View File

@ -16,6 +16,11 @@ spec = parallel $ do
describe "Identity" $ sequenceAltLaws (Identity <$> arbitrary :: Gen (Identity Char))
describe "Syntax" $ sequenceAltLaws (sized (syntaxOfSize (const arbitrary)) :: Gen (Syntax Char Char))
mergeLaws :: (Mergeable f, Alternative g, Eq (g (f a)), Show (f a), Show (g (f a))) => Gen (f a) -> Gen (Blind (a -> g a)) -> Spec
mergeLaws value function = describe "merge" $ do
prop "relationship with sequenceAlt" . forAll ((,) <$> value <*> function) $
\ (a, f) -> merge (getBlind f) a `shouldBe` sequenceAlt (fmap (getBlind f) a)
sequenceAltLaws :: forall f a. (Arbitrary a, CoArbitrary a, Mergeable f, Eq (f a), Show (f a)) => Gen (f a) -> Spec
sequenceAltLaws gen = do
describe "Maybe" $ sequenceAltLaws' gen (arbitrary :: Gen (Blind (a -> Maybe a)))