git.iko.soy/typeable/bloodhound
on master help sign in
Switch derive to generics-sop
4170273Oleg Grenrus
bloodhound.cabal+1−1
@@ -72,7 +72,7 @@ test-suite tests
72 unordered-containers >= 0.2.5.0 && <0.3,
72 unordered-containers >= 0.2.5.0 && <0.3,
73 mtl,
73 mtl,
74 quickcheck-properties,
74 quickcheck-properties,
75− derive,
75+ generics-sop,
76 errors,
76 errors,
77 exceptions,
77 exceptions,
78 temporary,
78 temporary,
tests/tests.hs+126−110
@@ -21,7 +21,6 @@ import Control.Monad.Reader
21import Data.Aeson
21import Data.Aeson
22import Data.Aeson.Types (parseEither)
22import Data.Aeson.Types (parseEither)
23import qualified Data.ByteString.Lazy.Char8 as BL8
23import qualified Data.ByteString.Lazy.Char8 as BL8
24−import Data.DeriveTH
25import qualified Data.HashMap.Strict as HM
24import qualified Data.HashMap.Strict as HM
26import Data.List (nub)
25import Data.List (nub)
27import qualified Data.List as L
26import qualified Data.List as L
@@ -54,6 +53,8 @@ import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
54import Test.Hspec.QuickCheck (prop)
53import Test.Hspec.QuickCheck (prop)
55import Test.QuickCheck
54import Test.QuickCheck
56
55
56+import qualified Generics.SOP as SOP
57+import qualified Generics.SOP.GGP as SOP
57
58
58testServer :: Server
59testServer :: Server
59testServer = Server "http://localhost:9200"
60testServer = Server "http://localhost:9200"
@@ -577,7 +578,8 @@ instance ApproxEq BoolMatch
577instance ApproxEq MultiMatchQuery
578instance ApproxEq MultiMatchQuery
578instance ApproxEq IndexSettings
579instance ApproxEq IndexSettings
579instance ApproxEq AllocationPolicy
580instance ApproxEq AllocationPolicy
580−instance ApproxEq Char
581+instance ApproxEq Char where
582+ (=~) = (==)
581instance ApproxEq Vers.Version where
583instance ApproxEq Vers.Version where
582 (=~) = (==)
584 (=~) = (==)
583instance (ApproxEq a, Show a) => ApproxEq [a] where
585instance (ApproxEq a, Show a) => ApproxEq [a] where
@@ -794,114 +796,114 @@ instance Arbitrary VersionNumber where
794 where
796 where
795 mk versions = VersionNumber (Vers.Version versions [])
797 mk versions = VersionNumber (Vers.Version versions [])
796
798
797−$(derive makeArbitrary ''IndexName)
799+instance Arbitrary IndexName where arbitrary = sopArbitrary; shrink = genericShrink
798−$(derive makeArbitrary ''MappingName)
800+instance Arbitrary MappingName where arbitrary = sopArbitrary; shrink = genericShrink
799−$(derive makeArbitrary ''DocId)
801+instance Arbitrary DocId where arbitrary = sopArbitrary; shrink = genericShrink
800−$(derive makeArbitrary ''Version)
802+instance Arbitrary Version where arbitrary = sopArbitrary; shrink = genericShrink
801−$(derive makeArbitrary ''BuildHash)
803+instance Arbitrary BuildHash where arbitrary = sopArbitrary; shrink = genericShrink
802−$(derive makeArbitrary ''IndexAliasRouting)
804+instance Arbitrary IndexAliasRouting where arbitrary = sopArbitrary; shrink = genericShrink
803−$(derive makeArbitrary ''ShardCount)
805+instance Arbitrary ShardCount where arbitrary = sopArbitrary; shrink = genericShrink
804−$(derive makeArbitrary ''ReplicaCount)
806+instance Arbitrary ReplicaCount where arbitrary = sopArbitrary; shrink = genericShrink
805−$(derive makeArbitrary ''TemplateName)
807+instance Arbitrary TemplateName where arbitrary = sopArbitrary; shrink = genericShrink
806−$(derive makeArbitrary ''TemplatePattern)
808+instance Arbitrary TemplatePattern where arbitrary = sopArbitrary; shrink = genericShrink
807−$(derive makeArbitrary ''QueryString)
809+instance Arbitrary QueryString where arbitrary = sopArbitrary; shrink = genericShrink
808−$(derive makeArbitrary ''CacheName)
810+instance Arbitrary CacheName where arbitrary = sopArbitrary; shrink = genericShrink
809−$(derive makeArbitrary ''CacheKey)
811+instance Arbitrary CacheKey where arbitrary = sopArbitrary; shrink = genericShrink
810−$(derive makeArbitrary ''Existence)
812+instance Arbitrary Existence where arbitrary = sopArbitrary; shrink = genericShrink
811−$(derive makeArbitrary ''CutoffFrequency)
813+instance Arbitrary CutoffFrequency where arbitrary = sopArbitrary; shrink = genericShrink
812−$(derive makeArbitrary ''Analyzer)
814+instance Arbitrary Analyzer where arbitrary = sopArbitrary; shrink = genericShrink
813−$(derive makeArbitrary ''MaxExpansions)
815+instance Arbitrary MaxExpansions where arbitrary = sopArbitrary; shrink = genericShrink
814−$(derive makeArbitrary ''Lenient)
816+instance Arbitrary Lenient where arbitrary = sopArbitrary; shrink = genericShrink
815−$(derive makeArbitrary ''Tiebreaker)
817+instance Arbitrary Tiebreaker where arbitrary = sopArbitrary; shrink = genericShrink
816−$(derive makeArbitrary ''Boost)
818+instance Arbitrary Boost where arbitrary = sopArbitrary; shrink = genericShrink
817−$(derive makeArbitrary ''BoostTerms)
819+instance Arbitrary BoostTerms where arbitrary = sopArbitrary; shrink = genericShrink
818−$(derive makeArbitrary ''MinimumMatch)
820+instance Arbitrary MinimumMatch where arbitrary = sopArbitrary; shrink = genericShrink
819−$(derive makeArbitrary ''DisableCoord)
821+instance Arbitrary DisableCoord where arbitrary = sopArbitrary; shrink = genericShrink
820−$(derive makeArbitrary ''IgnoreTermFrequency)
822+instance Arbitrary IgnoreTermFrequency where arbitrary = sopArbitrary; shrink = genericShrink
821−$(derive makeArbitrary ''MinimumTermFrequency)
823+instance Arbitrary MinimumTermFrequency where arbitrary = sopArbitrary; shrink = genericShrink
822−$(derive makeArbitrary ''MaxQueryTerms)
824+instance Arbitrary MaxQueryTerms where arbitrary = sopArbitrary; shrink = genericShrink
823−$(derive makeArbitrary ''Fuzziness)
825+instance Arbitrary Fuzziness where arbitrary = sopArbitrary; shrink = genericShrink
824−$(derive makeArbitrary ''PrefixLength)
826+instance Arbitrary PrefixLength where arbitrary = sopArbitrary; shrink = genericShrink
825−$(derive makeArbitrary ''TypeName)
827+instance Arbitrary TypeName where arbitrary = sopArbitrary; shrink = genericShrink
826−$(derive makeArbitrary ''PercentMatch)
828+instance Arbitrary PercentMatch where arbitrary = sopArbitrary; shrink = genericShrink
827−$(derive makeArbitrary ''StopWord)
829+instance Arbitrary StopWord where arbitrary = sopArbitrary; shrink = genericShrink
828−$(derive makeArbitrary ''QueryPath)
830+instance Arbitrary QueryPath where arbitrary = sopArbitrary; shrink = genericShrink
829−$(derive makeArbitrary ''AllowLeadingWildcard)
831+instance Arbitrary AllowLeadingWildcard where arbitrary = sopArbitrary; shrink = genericShrink
830−$(derive makeArbitrary ''LowercaseExpanded)
832+instance Arbitrary LowercaseExpanded where arbitrary = sopArbitrary; shrink = genericShrink
831−$(derive makeArbitrary ''EnablePositionIncrements)
833+instance Arbitrary EnablePositionIncrements where arbitrary = sopArbitrary; shrink = genericShrink
832−$(derive makeArbitrary ''AnalyzeWildcard)
834+instance Arbitrary AnalyzeWildcard where arbitrary = sopArbitrary; shrink = genericShrink
833−$(derive makeArbitrary ''GeneratePhraseQueries)
835+instance Arbitrary GeneratePhraseQueries where arbitrary = sopArbitrary; shrink = genericShrink
834−$(derive makeArbitrary ''Locale)
836+instance Arbitrary Locale where arbitrary = sopArbitrary; shrink = genericShrink
835−$(derive makeArbitrary ''MaxWordLength)
837+instance Arbitrary MaxWordLength where arbitrary = sopArbitrary; shrink = genericShrink
836−$(derive makeArbitrary ''MinWordLength)
838+instance Arbitrary MinWordLength where arbitrary = sopArbitrary; shrink = genericShrink
837−$(derive makeArbitrary ''PhraseSlop)
839+instance Arbitrary PhraseSlop where arbitrary = sopArbitrary; shrink = genericShrink
838−$(derive makeArbitrary ''MinDocFrequency)
840+instance Arbitrary MinDocFrequency where arbitrary = sopArbitrary; shrink = genericShrink
839−$(derive makeArbitrary ''MaxDocFrequency)
841+instance Arbitrary MaxDocFrequency where arbitrary = sopArbitrary; shrink = genericShrink
840−$(derive makeArbitrary ''Regexp)
842+instance Arbitrary Regexp where arbitrary = sopArbitrary; shrink = genericShrink
841−$(derive makeArbitrary ''SimpleQueryStringQuery)
843+instance Arbitrary SimpleQueryStringQuery where arbitrary = sopArbitrary; shrink = genericShrink
842−$(derive makeArbitrary ''FieldOrFields)
844+instance Arbitrary FieldOrFields where arbitrary = sopArbitrary; shrink = genericShrink
843−$(derive makeArbitrary ''SimpleQueryFlag)
845+instance Arbitrary SimpleQueryFlag where arbitrary = sopArbitrary; shrink = genericShrink
844−$(derive makeArbitrary ''RegexpQuery)
846+instance Arbitrary RegexpQuery where arbitrary = sopArbitrary; shrink = genericShrink
845−$(derive makeArbitrary ''QueryStringQuery)
847+instance Arbitrary QueryStringQuery where arbitrary = sopArbitrary; shrink = genericShrink
846−$(derive makeArbitrary ''RangeQuery)
848+instance Arbitrary RangeQuery where arbitrary = sopArbitrary; shrink = genericShrink
847−$(derive makeArbitrary ''RangeValue)
849+instance Arbitrary RangeValue where arbitrary = sopArbitrary; shrink = genericShrink
848−$(derive makeArbitrary ''PrefixQuery)
850+instance Arbitrary PrefixQuery where arbitrary = sopArbitrary; shrink = genericShrink
849−$(derive makeArbitrary ''NestedQuery)
851+instance Arbitrary NestedQuery where arbitrary = sopArbitrary; shrink = genericShrink
850−$(derive makeArbitrary ''MoreLikeThisFieldQuery)
852+instance Arbitrary MoreLikeThisFieldQuery where arbitrary = sopArbitrary; shrink = genericShrink
851−$(derive makeArbitrary ''MoreLikeThisQuery)
853+instance Arbitrary MoreLikeThisQuery where arbitrary = sopArbitrary; shrink = genericShrink
852−$(derive makeArbitrary ''IndicesQuery)
854+instance Arbitrary IndicesQuery where arbitrary = sopArbitrary; shrink = genericShrink
853−$(derive makeArbitrary ''HasParentQuery)
855+instance Arbitrary HasParentQuery where arbitrary = sopArbitrary; shrink = genericShrink
854−$(derive makeArbitrary ''HasChildQuery)
856+instance Arbitrary HasChildQuery where arbitrary = sopArbitrary; shrink = genericShrink
855−$(derive makeArbitrary ''FuzzyQuery)
857+instance Arbitrary FuzzyQuery where arbitrary = sopArbitrary; shrink = genericShrink
856−$(derive makeArbitrary ''FuzzyLikeFieldQuery)
858+instance Arbitrary FuzzyLikeFieldQuery where arbitrary = sopArbitrary; shrink = genericShrink
857−$(derive makeArbitrary ''FuzzyLikeThisQuery)
859+instance Arbitrary FuzzyLikeThisQuery where arbitrary = sopArbitrary; shrink = genericShrink
858−$(derive makeArbitrary ''FilteredQuery)
860+instance Arbitrary FilteredQuery where arbitrary = sopArbitrary; shrink = genericShrink
859−$(derive makeArbitrary ''DisMaxQuery)
861+instance Arbitrary DisMaxQuery where arbitrary = sopArbitrary; shrink = genericShrink
860−$(derive makeArbitrary ''CommonTermsQuery)
862+instance Arbitrary CommonTermsQuery where arbitrary = sopArbitrary; shrink = genericShrink
861−$(derive makeArbitrary ''DistanceRange)
863+instance Arbitrary DistanceRange where arbitrary = sopArbitrary; shrink = genericShrink
862−$(derive makeArbitrary ''MultiMatchQuery)
864+instance Arbitrary MultiMatchQuery where arbitrary = sopArbitrary; shrink = genericShrink
863−$(derive makeArbitrary ''LessThanD)
865+instance Arbitrary LessThanD where arbitrary = sopArbitrary; shrink = genericShrink
864−$(derive makeArbitrary ''LessThanEqD)
866+instance Arbitrary LessThanEqD where arbitrary = sopArbitrary; shrink = genericShrink
865−$(derive makeArbitrary ''GreaterThanD)
867+instance Arbitrary GreaterThanD where arbitrary = sopArbitrary; shrink = genericShrink
866−$(derive makeArbitrary ''GreaterThanEqD)
868+instance Arbitrary GreaterThanEqD where arbitrary = sopArbitrary; shrink = genericShrink
867−$(derive makeArbitrary ''LessThan)
869+instance Arbitrary LessThan where arbitrary = sopArbitrary; shrink = genericShrink
868−$(derive makeArbitrary ''LessThanEq)
870+instance Arbitrary LessThanEq where arbitrary = sopArbitrary; shrink = genericShrink
869−$(derive makeArbitrary ''GreaterThan)
871+instance Arbitrary GreaterThan where arbitrary = sopArbitrary; shrink = genericShrink
870−$(derive makeArbitrary ''GreaterThanEq)
872+instance Arbitrary GreaterThanEq where arbitrary = sopArbitrary; shrink = genericShrink
871−$(derive makeArbitrary ''GeoPoint)
873+instance Arbitrary GeoPoint where arbitrary = sopArbitrary; shrink = genericShrink
872−$(derive makeArbitrary ''NullValue)
874+instance Arbitrary NullValue where arbitrary = sopArbitrary; shrink = genericShrink
873−$(derive makeArbitrary ''MinimumMatchHighLow)
875+instance Arbitrary MinimumMatchHighLow where arbitrary = sopArbitrary; shrink = genericShrink
874−$(derive makeArbitrary ''CommonMinimumMatch)
876+instance Arbitrary CommonMinimumMatch where arbitrary = sopArbitrary; shrink = genericShrink
875−$(derive makeArbitrary ''BoostingQuery)
877+instance Arbitrary BoostingQuery where arbitrary = sopArbitrary; shrink = genericShrink
876−$(derive makeArbitrary ''BoolQuery)
878+instance Arbitrary BoolQuery where arbitrary = sopArbitrary; shrink = genericShrink
877−$(derive makeArbitrary ''MatchQuery)
879+instance Arbitrary MatchQuery where arbitrary = sopArbitrary; shrink = genericShrink
878−$(derive makeArbitrary ''MultiMatchQueryType)
880+instance Arbitrary MultiMatchQueryType where arbitrary = sopArbitrary; shrink = genericShrink
879−$(derive makeArbitrary ''BooleanOperator)
881+instance Arbitrary BooleanOperator where arbitrary = sopArbitrary; shrink = genericShrink
880−$(derive makeArbitrary ''ZeroTermsQuery)
882+instance Arbitrary ZeroTermsQuery where arbitrary = sopArbitrary; shrink = genericShrink
881−$(derive makeArbitrary ''MatchQueryType)
883+instance Arbitrary MatchQueryType where arbitrary = sopArbitrary; shrink = genericShrink
882−$(derive makeArbitrary ''SearchAliasRouting)
884+instance Arbitrary SearchAliasRouting where arbitrary = sopArbitrary; shrink = genericShrink
883−$(derive makeArbitrary ''ScoreType)
885+instance Arbitrary ScoreType where arbitrary = sopArbitrary; shrink = genericShrink
884−$(derive makeArbitrary ''Distance)
886+instance Arbitrary Distance where arbitrary = sopArbitrary; shrink = genericShrink
885−$(derive makeArbitrary ''DistanceUnit)
887+instance Arbitrary DistanceUnit where arbitrary = sopArbitrary; shrink = genericShrink
886−$(derive makeArbitrary ''DistanceType)
888+instance Arbitrary DistanceType where arbitrary = sopArbitrary; shrink = genericShrink
887−$(derive makeArbitrary ''OptimizeBbox)
889+instance Arbitrary OptimizeBbox where arbitrary = sopArbitrary; shrink = genericShrink
888−$(derive makeArbitrary ''GeoBoundingBoxConstraint)
890+instance Arbitrary GeoBoundingBoxConstraint where arbitrary = sopArbitrary; shrink = genericShrink
889−$(derive makeArbitrary ''GeoFilterType)
891+instance Arbitrary GeoFilterType where arbitrary = sopArbitrary; shrink = genericShrink
890−$(derive makeArbitrary ''GeoBoundingBox)
892+instance Arbitrary GeoBoundingBox where arbitrary = sopArbitrary; shrink = genericShrink
891−$(derive makeArbitrary ''LatLon)
893+instance Arbitrary LatLon where arbitrary = sopArbitrary; shrink = genericShrink
892−$(derive makeArbitrary ''RangeExecution)
894+instance Arbitrary RangeExecution where arbitrary = sopArbitrary; shrink = genericShrink
893−$(derive makeArbitrary ''RegexpFlag)
895+instance Arbitrary RegexpFlag where arbitrary = sopArbitrary; shrink = genericShrink
894−$(derive makeArbitrary ''BoolMatch)
896+instance Arbitrary BoolMatch where arbitrary = sopArbitrary; shrink = genericShrink
895−$(derive makeArbitrary ''Term)
897+instance Arbitrary Term where arbitrary = sopArbitrary; shrink = genericShrink
896−$(derive makeArbitrary ''IndexSettings)
898+instance Arbitrary IndexSettings where arbitrary = sopArbitrary; shrink = genericShrink
897−$(derive makeArbitrary ''UpdatableIndexSetting)
899+instance Arbitrary UpdatableIndexSetting where arbitrary = sopArbitrary; shrink = genericShrink
898−$(derive makeArbitrary ''Bytes)
900+instance Arbitrary Bytes where arbitrary = sopArbitrary; shrink = genericShrink
899−$(derive makeArbitrary ''AllocationPolicy)
901+instance Arbitrary AllocationPolicy where arbitrary = sopArbitrary; shrink = genericShrink
900−$(derive makeArbitrary ''InitialShardCount)
902+instance Arbitrary InitialShardCount where arbitrary = sopArbitrary; shrink = genericShrink
901−$(derive makeArbitrary ''FSType)
903+instance Arbitrary FSType where arbitrary = sopArbitrary; shrink = genericShrink
902−$(derive makeArbitrary ''CompoundFormat)
904+instance Arbitrary CompoundFormat where arbitrary = sopArbitrary; shrink = genericShrink
903−$(derive makeArbitrary ''FsSnapshotRepo)
905+instance Arbitrary FsSnapshotRepo where arbitrary = sopArbitrary; shrink = genericShrink
904−$(derive makeArbitrary ''SnapshotRepoName)
906+instance Arbitrary SnapshotRepoName where arbitrary = sopArbitrary; shrink = genericShrink
905
907
906newtype UpdatableIndexSetting' = UpdatableIndexSetting' UpdatableIndexSetting
908newtype UpdatableIndexSetting' = UpdatableIndexSetting' UpdatableIndexSetting
907 deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
909 deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
@@ -1841,3 +1843,17 @@ main = hspec $ do
1841 propJSON (Proxy :: Proxy InitialShardCount)
1843 propJSON (Proxy :: Proxy InitialShardCount)
1842 propJSON (Proxy :: Proxy FSType)
1844 propJSON (Proxy :: Proxy FSType)
1843 propJSON (Proxy :: Proxy CompoundFormat)
1845 propJSON (Proxy :: Proxy CompoundFormat)
1846+
1847+-- Temporary solution for lacking of generic derivation of Arbitrary
1848+-- We use generics-sop, as it's much more concise than directly using GHC.Generics
1849+--
1850+-- This will be unneeded after https://github.com/nick8325/quickcheck/pull/112
1851+-- is merged and released
1852+sopArbitrary :: forall a. (Generic a, SOP.GTo a, SOP.All SOP.SListI (SOP.GCode a), SOP.All2 Arbitrary (SOP.GCode a)) => Gen a
1853+sopArbitrary = fmap SOP.gto sopArbitrary'
1854+
1855+sopArbitrary' :: forall xss. (SOP.All SOP.SListI xss, SOP.All2 Arbitrary xss) => Gen (SOP.SOP SOP.I xss)
1856+sopArbitrary' = oneof (map SOP.hsequence $ SOP.apInjs_POP $ SOP.hcpure p arbitrary)
1857+ where
1858+ p :: Proxy Arbitrary
1859+ p = Proxy