From 01f817a77e5cfd349785d466e1f43c291cdc08fd Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 15 Mar 2016 11:17:47 -0400 Subject: [PATCH] Move the other arbitrary instances into ArbitraryTerm. --- test/AlignmentSpec.hs | 21 +-------------------- test/ArbitraryTerm.hs | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/test/AlignmentSpec.hs b/test/AlignmentSpec.hs index 2027618e4..f7df8e64d 100644 --- a/test/AlignmentSpec.hs +++ b/test/AlignmentSpec.hs @@ -6,7 +6,7 @@ import Test.QuickCheck hiding (Fixed) import Data.Text.Arbitrary () import Alignment -import ArbitraryTerm () +import ArbitraryTerm (arbitraryLeaf) import Control.Arrow import Control.Comonad.Cofree import Control.Monad.Free hiding (unfold) @@ -26,25 +26,6 @@ import qualified Source import SplitDiff import Syntax -instance Arbitrary a => Arbitrary (Both a) where - arbitrary = pure (curry Both) <*> arbitrary <*> arbitrary - -instance Arbitrary a => Arbitrary (Line a) where - arbitrary = oneof [ Line <$> arbitrary, Closed <$> arbitrary ] - -instance Arbitrary a => Arbitrary (Patch a) where - arbitrary = oneof [ - Insert <$> arbitrary, - Delete <$> arbitrary, - Replace <$> arbitrary <*> arbitrary ] - -instance Arbitrary a => Arbitrary (Source a) where - arbitrary = Source.fromList <$> arbitrary - -arbitraryLeaf :: Gen (Source Char, Info, Syntax (Source Char) f) -arbitraryLeaf = toTuple <$> arbitrary - where toTuple string = (string, Info (Range 0 $ length string) mempty, Leaf string) - spec :: Spec spec = parallel $ do describe "splitDiffByLines" $ do diff --git a/test/ArbitraryTerm.hs b/test/ArbitraryTerm.hs index e4c65c362..b835c4afa 100644 --- a/test/ArbitraryTerm.hs +++ b/test/ArbitraryTerm.hs @@ -1,16 +1,22 @@ module ArbitraryTerm where import Category -import Syntax -import Term import Control.Comonad.Cofree import Control.Monad +import Data.Functor.Both import qualified Data.OrderedMap as Map import qualified Data.List as List import qualified Data.Set as Set -import GHC.Generics -import Test.QuickCheck hiding (Fixed) import Data.Text.Arbitrary () +import Diff +import Line +import Patch +import Range +import Source hiding ((++)) +import Syntax +import GHC.Generics +import Term +import Test.QuickCheck hiding (Fixed) newtype ArbitraryTerm a annotation = ArbitraryTerm (annotation, Syntax a (ArbitraryTerm a annotation)) deriving (Show, Eq, Generic) @@ -46,3 +52,22 @@ instance Categorizable CategorySet where instance Arbitrary CategorySet where arbitrary = elements [ A, B, C, D ] + +instance Arbitrary a => Arbitrary (Both a) where + arbitrary = pure (curry Both) <*> arbitrary <*> arbitrary + +instance Arbitrary a => Arbitrary (Line a) where + arbitrary = oneof [ Line <$> arbitrary, Closed <$> arbitrary ] + +instance Arbitrary a => Arbitrary (Patch a) where + arbitrary = oneof [ + Insert <$> arbitrary, + Delete <$> arbitrary, + Replace <$> arbitrary <*> arbitrary ] + +instance Arbitrary a => Arbitrary (Source a) where + arbitrary = Source.fromList <$> arbitrary + +arbitraryLeaf :: Gen (Source Char, Info, Syntax (Source Char) f) +arbitraryLeaf = toTuple <$> arbitrary + where toTuple string = (string, Info (Range 0 $ length string) mempty, Leaf string)