mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
🔥 the Mergeable spec.
This commit is contained in:
parent
a26d569099
commit
d863d282b1
@ -237,7 +237,6 @@ test-suite test
|
||||
, Data.Diff.Spec
|
||||
, Data.Functor.Classes.Generic.Spec
|
||||
, Data.Functor.Listable
|
||||
, Data.Mergeable.Spec
|
||||
, Data.Scientific.Spec
|
||||
, Data.Source.Spec
|
||||
, Data.Term.Spec
|
||||
|
@ -1,61 +0,0 @@
|
||||
{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
|
||||
module Data.Mergeable.Spec (spec) where
|
||||
|
||||
import Control.Applicative (Alternative(..))
|
||||
import Data.Functor.Identity
|
||||
import Data.Functor.Listable
|
||||
import Data.Maybe (catMaybes)
|
||||
import Data.Mergeable
|
||||
import Test.Hspec
|
||||
import Test.Hspec.LeanCheck
|
||||
import Test.LeanCheck
|
||||
|
||||
spec :: Spec
|
||||
spec = parallel $ do
|
||||
describe "[]" $ do
|
||||
withAlternativeInstances sequenceAltLaws (tiers :: [Tier String])
|
||||
withAlternativeInstances mergeLaws (tiers :: [Tier String])
|
||||
describe "Maybe" $ do
|
||||
withAlternativeInstances sequenceAltLaws (tiers :: [Tier (Maybe Char)])
|
||||
withAlternativeInstances mergeLaws (tiers :: [Tier (Maybe Char)])
|
||||
describe "Identity" $ do
|
||||
withAlternativeInstances sequenceAltLaws (Identity `mapT` tiers :: [Tier (Identity Char)])
|
||||
withAlternativeInstances mergeLaws (Identity `mapT` tiers :: [Tier (Identity Char)])
|
||||
describe "ListableSyntax" $ do
|
||||
withAlternativeInstances sequenceAltLaws (tiers :: [Tier (ListableSyntax Char)])
|
||||
withAlternativeInstances mergeLaws (tiers :: [Tier (ListableSyntax Char)])
|
||||
|
||||
prop "subsumes catMaybes/Just" $
|
||||
\ a -> sequenceAlt a `shouldBe` pure (catMaybes (a :: [Maybe Char]))
|
||||
|
||||
mergeLaws :: forall f g a. (Mergeable f, Alternative g, Eq (g (f a)), Show (f a), Show (g (f a))) => [Tier (f a)] -> [Tier (Blind (a -> g a))] -> Spec
|
||||
mergeLaws value function = describe "merge" $ do
|
||||
prop "identity" . forAll value $
|
||||
\ a -> merge pure a `shouldNotBe` (empty :: g (f a))
|
||||
|
||||
prop "relationship with sequenceAlt" . forAll (value >< function) $
|
||||
\ (a, f) -> merge (getBlind f) a `shouldBe` sequenceAlt (fmap (getBlind f) a)
|
||||
|
||||
sequenceAltLaws :: forall f g a. (Mergeable f, Alternative g, Eq (g (f a)), Show (f a), Show (g (f a))) => [Tier (f a)] -> [Tier (Blind (a -> g a))] -> Spec
|
||||
sequenceAltLaws value function = describe "sequenceAlt" $ do
|
||||
prop "identity" . forAll value $
|
||||
\ a -> sequenceAlt (pure <$> a) `shouldNotBe` (empty :: g (f a))
|
||||
|
||||
prop "relationship with merge" . forAll (productWith ((Blind .) . fmap . getBlind) function value :: [Tier (Blind (f (g a)))]) $
|
||||
\ a -> sequenceAlt (getBlind a) `shouldBe` merge id (getBlind a)
|
||||
|
||||
|
||||
withAlternativeInstances :: forall f a. (Listable a, Eq (f a), Show (f a)) => (forall g. (Alternative g, Eq (g (f a)), Show (g (f a))) => [Tier (f a)] -> [Tier (Blind (a -> g a))] -> Spec) -> [Tier (f a)] -> Spec
|
||||
withAlternativeInstances laws gen = do
|
||||
describe "[]" $ laws gen (fmap const `mapT` tiers :: [Tier (Blind (a -> [a]))])
|
||||
describe "Maybe" $ laws gen (fmap const `mapT` tiers :: [Tier (Blind (a -> Maybe a))])
|
||||
|
||||
|
||||
newtype Blind a = Blind { getBlind :: a }
|
||||
deriving Functor
|
||||
|
||||
instance Listable a => Listable (Blind a) where
|
||||
tiers = Blind `mapT` tiers
|
||||
|
||||
instance Show (Blind a) where
|
||||
showsPrec _ _ = showString "*"
|
@ -8,7 +8,6 @@ import qualified Analysis.TypeScript.Spec
|
||||
import qualified Assigning.Assignment.Spec
|
||||
import qualified Data.Diff.Spec
|
||||
import qualified Data.Functor.Classes.Generic.Spec
|
||||
import qualified Data.Mergeable.Spec
|
||||
import qualified Data.Scientific.Spec
|
||||
import qualified Data.Source.Spec
|
||||
import qualified Data.Term.Spec
|
||||
@ -36,7 +35,6 @@ main = hspec $ do
|
||||
describe "Assigning.Assignment" Assigning.Assignment.Spec.spec
|
||||
describe "Data.Diff" Data.Diff.Spec.spec
|
||||
describe "Data.Functor.Classes.Generic" Data.Functor.Classes.Generic.Spec.spec
|
||||
describe "Data.Mergeable" Data.Mergeable.Spec.spec
|
||||
describe "Data.Scientific" Data.Scientific.Spec.spec
|
||||
describe "Data.Source" Data.Source.Spec.spec
|
||||
describe "Data.Term" Data.Term.Spec.spec
|
||||
|
Loading…
Reference in New Issue
Block a user