From fa15e16722ece1b429a6f45d6f57d77e528fe825 Mon Sep 17 00:00:00 2001 From: defanor Date: Sat, 16 Dec 2017 07:55:35 +0300 Subject: Refactor - Unify the naming - Merge all the classes into one --- test/Test.hs | 53 +++++++++++++++-------------------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/test/Test.hs b/test/Test.hs index ffcae8e..9b92993 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} import GHC.Generics import Generic.Random @@ -11,15 +11,11 @@ import Coalpit data Basic = Basic Int String Double - deriving (Generic, Eq, Show) -instance ArgParser Basic -instance ToArgs Basic + deriving (Generic, Eq, Show, Coalpit) instance Arbitrary Basic where arbitrary = genericArbitraryU data WithLists = WithLists [Int] [String] [Double] - deriving (Generic, Eq, Show) -instance ArgParser WithLists -instance ToArgs WithLists + deriving (Generic, Eq, Show, Coalpit) instance Arbitrary WithLists where arbitrary = genericArbitraryU data Record = Record { maybeInt :: Maybe Int @@ -28,62 +24,47 @@ data Record = Record { maybeInt :: Maybe Int , listOfStrings :: [String] , maybeListOfNumbers :: Maybe [Integer] , otherString :: String - } deriving (Generic, Eq, Show) -instance ArgParser Record -instance ToArgs Record + } deriving (Generic, Eq, Show, Coalpit) instance Arbitrary Record where arbitrary = genericArbitraryU data Sum = Foo Int Bool | Bar | Baz (String, (Double, Integer), Rational) - deriving (Generic, Eq, Show) -instance ArgParser Sum -instance ToArgs Sum + deriving (Generic, Eq, Show, Coalpit) instance Arbitrary Sum where arbitrary = genericArbitraryU data Nested = Nested Record Basic WithLists Sum - deriving (Generic, Eq, Show) -instance ArgParser Nested -instance ToArgs Nested + deriving (Generic, Eq, Show, Coalpit) instance Arbitrary Nested where arbitrary = genericArbitraryU data Polymorphic a b = Polymorphic (Maybe a) [b] (Either a b) deriving (Generic, Eq, Show) -instance (ArgParser a, ArgParser b) => ArgParser (Polymorphic a b) -instance (ToArgs a, ToArgs b) => ToArgs (Polymorphic a b) +instance (Coalpit a, Coalpit b) => Coalpit (Polymorphic a b) instance (Arbitrary a, Arbitrary b) => Arbitrary (Polymorphic a b) where arbitrary = genericArbitraryU data Recursive = RecursiveA | RecursiveB Recursive - deriving (Generic, Eq, Show) -instance ArgParser Recursive -instance ToArgs Recursive + deriving (Generic, Eq, Show, Coalpit) instance Arbitrary Recursive where arbitrary = genericArbitraryU data NestedRecord = NestedRecord { record1 :: Maybe Record , record2 :: Maybe Record , record3 :: Maybe Record - } deriving (Generic, Eq, Show) -instance ArgParser NestedRecord -instance ToArgs NestedRecord + } deriving (Generic, Eq, Show, Coalpit) instance Arbitrary NestedRecord where arbitrary = genericArbitraryU data NestedSum = NestedFoo Record | NestedBar Sum Basic Nested | NestedBaz (Polymorphic Int Double) - deriving (Generic, Eq, Show) -instance ArgParser NestedSum -instance ToArgs NestedSum + deriving (Generic, Eq, Show, Coalpit) instance Arbitrary NestedSum where arbitrary = genericArbitraryU data RecursiveRecordMaybe = RecursiveRecordMaybe { rrm :: Maybe RecursiveRecordMaybe , record :: Maybe Record , guard :: () - } deriving (Generic, Eq, Show) -instance ArgParser RecursiveRecordMaybe -instance ToArgs RecursiveRecordMaybe + } deriving (Generic, Eq, Show, Coalpit) instance Arbitrary RecursiveRecordMaybe where arbitrary = genericArbitraryU data RecursiveRecordMaybe2 = RecursiveRecordMaybe2 @@ -91,25 +72,21 @@ data RecursiveRecordMaybe2 = RecursiveRecordMaybe2 , rrm' :: Maybe RecursiveRecordMaybe2 , record2' :: Maybe Record , guard' :: () - } deriving (Generic, Eq, Show) -instance ArgParser RecursiveRecordMaybe2 -instance ToArgs RecursiveRecordMaybe2 + } deriving (Generic, Eq, Show, Coalpit) instance Arbitrary RecursiveRecordMaybe2 where arbitrary = genericArbitraryU data RecordStrings = RecordStrings { s1 :: String , s2 :: String , s3 :: String - } deriving (Generic, Eq, Show) -instance ArgParser RecordStrings -instance ToArgs RecordStrings + } deriving (Generic, Eq, Show, Coalpit) instance Arbitrary RecordStrings where arbitrary = genericArbitraryU -printAndParse :: (ArgParser a, ToArgs a, Eq a) +printAndParse :: (Coalpit a, Eq a) => Options -> Proxy a -> a -> Bool printAndParse m _ r = Right r == fromArgs m (toArgs m r) -mkTest :: (ArgParser a, ToArgs a, Eq a, Show a, Arbitrary a) +mkTest :: (Coalpit a, Eq a, Show a, Arbitrary a) => Options -> Proxy a -> String -> TestTree mkTest m p n = QC.testProperty n (printAndParse m p) -- cgit v1.2.3