git.iko.soy/typeable/bloodhound
on master help sign in
Switch derive to generics-sop

Until https://github.com/nick8325/quickcheck/pull/112 is merged and released

commit41702738051c86ac3ba3e15ff8a4924b31fd55d9 authorOleg Grenrus <oleg.grenrus@iki.fi> dateFri 18 Nov 2016, 12:19 (10 years ago) parent0ee54ec
2 files changed+127−111
bloodhound.cabal+1−1 tests/tests.hs+126−110
bloodhound.cabal+1−1
@@ -72,7 +72,7 @@ test-suite tests
7272 unordered-containers >= 0.2.5.0 && <0.3,
7373 mtl,
7474 quickcheck-properties,
75− derive,
75+ generics-sop,
7676 errors,
7777 exceptions,
7878 temporary,
tests/tests.hs+126−110
@@ -21,7 +21,6 @@ import Control.Monad.Reader
2121import Data.Aeson
2222import Data.Aeson.Types (parseEither)
2323import qualified Data.ByteString.Lazy.Char8 as BL8
24−import Data.DeriveTH
2524import qualified Data.HashMap.Strict as HM
2625import Data.List (nub)
2726import qualified Data.List as L
@@ -54,6 +53,8 @@ import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
5453import Test.Hspec.QuickCheck (prop)
5554import Test.QuickCheck
5655
56+import qualified Generics.SOP as SOP
57+import qualified Generics.SOP.GGP as SOP
5758
5859testServer :: Server
5960testServer = Server "http://localhost:9200"
@@ -577,7 +578,8 @@ instance ApproxEq BoolMatch
577578instance ApproxEq MultiMatchQuery
578579instance ApproxEq IndexSettings
579580instance ApproxEq AllocationPolicy
580−instance ApproxEq Char
581+instance ApproxEq Char where
582+ (=~) = (==)
581583instance ApproxEq Vers.Version where
582584 (=~) = (==)
583585instance (ApproxEq a, Show a) => ApproxEq [a] where
@@ -794,114 +796,114 @@ instance Arbitrary VersionNumber where
794796 where
795797 mk versions = VersionNumber (Vers.Version versions [])
796798
797−$(derive makeArbitrary ''IndexName)
798−$(derive makeArbitrary ''MappingName)
799−$(derive makeArbitrary ''DocId)
800−$(derive makeArbitrary ''Version)
801−$(derive makeArbitrary ''BuildHash)
802−$(derive makeArbitrary ''IndexAliasRouting)
803−$(derive makeArbitrary ''ShardCount)
804−$(derive makeArbitrary ''ReplicaCount)
805−$(derive makeArbitrary ''TemplateName)
806−$(derive makeArbitrary ''TemplatePattern)
807−$(derive makeArbitrary ''QueryString)
808−$(derive makeArbitrary ''CacheName)
809−$(derive makeArbitrary ''CacheKey)
810−$(derive makeArbitrary ''Existence)
811−$(derive makeArbitrary ''CutoffFrequency)
812−$(derive makeArbitrary ''Analyzer)
813−$(derive makeArbitrary ''MaxExpansions)
814−$(derive makeArbitrary ''Lenient)
815−$(derive makeArbitrary ''Tiebreaker)
816−$(derive makeArbitrary ''Boost)
817−$(derive makeArbitrary ''BoostTerms)
818−$(derive makeArbitrary ''MinimumMatch)
819−$(derive makeArbitrary ''DisableCoord)
820−$(derive makeArbitrary ''IgnoreTermFrequency)
821−$(derive makeArbitrary ''MinimumTermFrequency)
822−$(derive makeArbitrary ''MaxQueryTerms)
823−$(derive makeArbitrary ''Fuzziness)
824−$(derive makeArbitrary ''PrefixLength)
825−$(derive makeArbitrary ''TypeName)
826−$(derive makeArbitrary ''PercentMatch)
827−$(derive makeArbitrary ''StopWord)
828−$(derive makeArbitrary ''QueryPath)
829−$(derive makeArbitrary ''AllowLeadingWildcard)
830−$(derive makeArbitrary ''LowercaseExpanded)
831−$(derive makeArbitrary ''EnablePositionIncrements)
832−$(derive makeArbitrary ''AnalyzeWildcard)
833−$(derive makeArbitrary ''GeneratePhraseQueries)
834−$(derive makeArbitrary ''Locale)
835−$(derive makeArbitrary ''MaxWordLength)
836−$(derive makeArbitrary ''MinWordLength)
837−$(derive makeArbitrary ''PhraseSlop)
838−$(derive makeArbitrary ''MinDocFrequency)
839−$(derive makeArbitrary ''MaxDocFrequency)
840−$(derive makeArbitrary ''Regexp)
841−$(derive makeArbitrary ''SimpleQueryStringQuery)
842−$(derive makeArbitrary ''FieldOrFields)
843−$(derive makeArbitrary ''SimpleQueryFlag)
844−$(derive makeArbitrary ''RegexpQuery)
845−$(derive makeArbitrary ''QueryStringQuery)
846−$(derive makeArbitrary ''RangeQuery)
847−$(derive makeArbitrary ''RangeValue)
848−$(derive makeArbitrary ''PrefixQuery)
849−$(derive makeArbitrary ''NestedQuery)
850−$(derive makeArbitrary ''MoreLikeThisFieldQuery)
851−$(derive makeArbitrary ''MoreLikeThisQuery)
852−$(derive makeArbitrary ''IndicesQuery)
853−$(derive makeArbitrary ''HasParentQuery)
854−$(derive makeArbitrary ''HasChildQuery)
855−$(derive makeArbitrary ''FuzzyQuery)
856−$(derive makeArbitrary ''FuzzyLikeFieldQuery)
857−$(derive makeArbitrary ''FuzzyLikeThisQuery)
858−$(derive makeArbitrary ''FilteredQuery)
859−$(derive makeArbitrary ''DisMaxQuery)
860−$(derive makeArbitrary ''CommonTermsQuery)
861−$(derive makeArbitrary ''DistanceRange)
862−$(derive makeArbitrary ''MultiMatchQuery)
863−$(derive makeArbitrary ''LessThanD)
864−$(derive makeArbitrary ''LessThanEqD)
865−$(derive makeArbitrary ''GreaterThanD)
866−$(derive makeArbitrary ''GreaterThanEqD)
867−$(derive makeArbitrary ''LessThan)
868−$(derive makeArbitrary ''LessThanEq)
869−$(derive makeArbitrary ''GreaterThan)
870−$(derive makeArbitrary ''GreaterThanEq)
871−$(derive makeArbitrary ''GeoPoint)
872−$(derive makeArbitrary ''NullValue)
873−$(derive makeArbitrary ''MinimumMatchHighLow)
874−$(derive makeArbitrary ''CommonMinimumMatch)
875−$(derive makeArbitrary ''BoostingQuery)
876−$(derive makeArbitrary ''BoolQuery)
877−$(derive makeArbitrary ''MatchQuery)
878−$(derive makeArbitrary ''MultiMatchQueryType)
879−$(derive makeArbitrary ''BooleanOperator)
880−$(derive makeArbitrary ''ZeroTermsQuery)
881−$(derive makeArbitrary ''MatchQueryType)
882−$(derive makeArbitrary ''SearchAliasRouting)
883−$(derive makeArbitrary ''ScoreType)
884−$(derive makeArbitrary ''Distance)
885−$(derive makeArbitrary ''DistanceUnit)
886−$(derive makeArbitrary ''DistanceType)
887−$(derive makeArbitrary ''OptimizeBbox)
888−$(derive makeArbitrary ''GeoBoundingBoxConstraint)
889−$(derive makeArbitrary ''GeoFilterType)
890−$(derive makeArbitrary ''GeoBoundingBox)
891−$(derive makeArbitrary ''LatLon)
892−$(derive makeArbitrary ''RangeExecution)
893−$(derive makeArbitrary ''RegexpFlag)
894−$(derive makeArbitrary ''BoolMatch)
895−$(derive makeArbitrary ''Term)
896−$(derive makeArbitrary ''IndexSettings)
897−$(derive makeArbitrary ''UpdatableIndexSetting)
898−$(derive makeArbitrary ''Bytes)
899−$(derive makeArbitrary ''AllocationPolicy)
900−$(derive makeArbitrary ''InitialShardCount)
901−$(derive makeArbitrary ''FSType)
902−$(derive makeArbitrary ''CompoundFormat)
903−$(derive makeArbitrary ''FsSnapshotRepo)
904−$(derive makeArbitrary ''SnapshotRepoName)
799+instance Arbitrary IndexName where arbitrary = sopArbitrary; shrink = genericShrink
800+instance Arbitrary MappingName where arbitrary = sopArbitrary; shrink = genericShrink
801+instance Arbitrary DocId where arbitrary = sopArbitrary; shrink = genericShrink
802+instance Arbitrary Version where arbitrary = sopArbitrary; shrink = genericShrink
803+instance Arbitrary BuildHash where arbitrary = sopArbitrary; shrink = genericShrink
804+instance Arbitrary IndexAliasRouting where arbitrary = sopArbitrary; shrink = genericShrink
805+instance Arbitrary ShardCount where arbitrary = sopArbitrary; shrink = genericShrink
806+instance Arbitrary ReplicaCount where arbitrary = sopArbitrary; shrink = genericShrink
807+instance Arbitrary TemplateName where arbitrary = sopArbitrary; shrink = genericShrink
808+instance Arbitrary TemplatePattern where arbitrary = sopArbitrary; shrink = genericShrink
809+instance Arbitrary QueryString where arbitrary = sopArbitrary; shrink = genericShrink
810+instance Arbitrary CacheName where arbitrary = sopArbitrary; shrink = genericShrink
811+instance Arbitrary CacheKey where arbitrary = sopArbitrary; shrink = genericShrink
812+instance Arbitrary Existence where arbitrary = sopArbitrary; shrink = genericShrink
813+instance Arbitrary CutoffFrequency where arbitrary = sopArbitrary; shrink = genericShrink
814+instance Arbitrary Analyzer where arbitrary = sopArbitrary; shrink = genericShrink
815+instance Arbitrary MaxExpansions where arbitrary = sopArbitrary; shrink = genericShrink
816+instance Arbitrary Lenient where arbitrary = sopArbitrary; shrink = genericShrink
817+instance Arbitrary Tiebreaker where arbitrary = sopArbitrary; shrink = genericShrink
818+instance Arbitrary Boost where arbitrary = sopArbitrary; shrink = genericShrink
819+instance Arbitrary BoostTerms where arbitrary = sopArbitrary; shrink = genericShrink
820+instance Arbitrary MinimumMatch where arbitrary = sopArbitrary; shrink = genericShrink
821+instance Arbitrary DisableCoord where arbitrary = sopArbitrary; shrink = genericShrink
822+instance Arbitrary IgnoreTermFrequency where arbitrary = sopArbitrary; shrink = genericShrink
823+instance Arbitrary MinimumTermFrequency where arbitrary = sopArbitrary; shrink = genericShrink
824+instance Arbitrary MaxQueryTerms where arbitrary = sopArbitrary; shrink = genericShrink
825+instance Arbitrary Fuzziness where arbitrary = sopArbitrary; shrink = genericShrink
826+instance Arbitrary PrefixLength where arbitrary = sopArbitrary; shrink = genericShrink
827+instance Arbitrary TypeName where arbitrary = sopArbitrary; shrink = genericShrink
828+instance Arbitrary PercentMatch where arbitrary = sopArbitrary; shrink = genericShrink
829+instance Arbitrary StopWord where arbitrary = sopArbitrary; shrink = genericShrink
830+instance Arbitrary QueryPath where arbitrary = sopArbitrary; shrink = genericShrink
831+instance Arbitrary AllowLeadingWildcard where arbitrary = sopArbitrary; shrink = genericShrink
832+instance Arbitrary LowercaseExpanded where arbitrary = sopArbitrary; shrink = genericShrink
833+instance Arbitrary EnablePositionIncrements where arbitrary = sopArbitrary; shrink = genericShrink
834+instance Arbitrary AnalyzeWildcard where arbitrary = sopArbitrary; shrink = genericShrink
835+instance Arbitrary GeneratePhraseQueries where arbitrary = sopArbitrary; shrink = genericShrink
836+instance Arbitrary Locale where arbitrary = sopArbitrary; shrink = genericShrink
837+instance Arbitrary MaxWordLength where arbitrary = sopArbitrary; shrink = genericShrink
838+instance Arbitrary MinWordLength where arbitrary = sopArbitrary; shrink = genericShrink
839+instance Arbitrary PhraseSlop where arbitrary = sopArbitrary; shrink = genericShrink
840+instance Arbitrary MinDocFrequency where arbitrary = sopArbitrary; shrink = genericShrink
841+instance Arbitrary MaxDocFrequency where arbitrary = sopArbitrary; shrink = genericShrink
842+instance Arbitrary Regexp where arbitrary = sopArbitrary; shrink = genericShrink
843+instance Arbitrary SimpleQueryStringQuery where arbitrary = sopArbitrary; shrink = genericShrink
844+instance Arbitrary FieldOrFields where arbitrary = sopArbitrary; shrink = genericShrink
845+instance Arbitrary SimpleQueryFlag where arbitrary = sopArbitrary; shrink = genericShrink
846+instance Arbitrary RegexpQuery where arbitrary = sopArbitrary; shrink = genericShrink
847+instance Arbitrary QueryStringQuery where arbitrary = sopArbitrary; shrink = genericShrink
848+instance Arbitrary RangeQuery where arbitrary = sopArbitrary; shrink = genericShrink
849+instance Arbitrary RangeValue where arbitrary = sopArbitrary; shrink = genericShrink
850+instance Arbitrary PrefixQuery where arbitrary = sopArbitrary; shrink = genericShrink
851+instance Arbitrary NestedQuery where arbitrary = sopArbitrary; shrink = genericShrink
852+instance Arbitrary MoreLikeThisFieldQuery where arbitrary = sopArbitrary; shrink = genericShrink
853+instance Arbitrary MoreLikeThisQuery where arbitrary = sopArbitrary; shrink = genericShrink
854+instance Arbitrary IndicesQuery where arbitrary = sopArbitrary; shrink = genericShrink
855+instance Arbitrary HasParentQuery where arbitrary = sopArbitrary; shrink = genericShrink
856+instance Arbitrary HasChildQuery where arbitrary = sopArbitrary; shrink = genericShrink
857+instance Arbitrary FuzzyQuery where arbitrary = sopArbitrary; shrink = genericShrink
858+instance Arbitrary FuzzyLikeFieldQuery where arbitrary = sopArbitrary; shrink = genericShrink
859+instance Arbitrary FuzzyLikeThisQuery where arbitrary = sopArbitrary; shrink = genericShrink
860+instance Arbitrary FilteredQuery where arbitrary = sopArbitrary; shrink = genericShrink
861+instance Arbitrary DisMaxQuery where arbitrary = sopArbitrary; shrink = genericShrink
862+instance Arbitrary CommonTermsQuery where arbitrary = sopArbitrary; shrink = genericShrink
863+instance Arbitrary DistanceRange where arbitrary = sopArbitrary; shrink = genericShrink
864+instance Arbitrary MultiMatchQuery where arbitrary = sopArbitrary; shrink = genericShrink
865+instance Arbitrary LessThanD where arbitrary = sopArbitrary; shrink = genericShrink
866+instance Arbitrary LessThanEqD where arbitrary = sopArbitrary; shrink = genericShrink
867+instance Arbitrary GreaterThanD where arbitrary = sopArbitrary; shrink = genericShrink
868+instance Arbitrary GreaterThanEqD where arbitrary = sopArbitrary; shrink = genericShrink
869+instance Arbitrary LessThan where arbitrary = sopArbitrary; shrink = genericShrink
870+instance Arbitrary LessThanEq where arbitrary = sopArbitrary; shrink = genericShrink
871+instance Arbitrary GreaterThan where arbitrary = sopArbitrary; shrink = genericShrink
872+instance Arbitrary GreaterThanEq where arbitrary = sopArbitrary; shrink = genericShrink
873+instance Arbitrary GeoPoint where arbitrary = sopArbitrary; shrink = genericShrink
874+instance Arbitrary NullValue where arbitrary = sopArbitrary; shrink = genericShrink
875+instance Arbitrary MinimumMatchHighLow where arbitrary = sopArbitrary; shrink = genericShrink
876+instance Arbitrary CommonMinimumMatch where arbitrary = sopArbitrary; shrink = genericShrink
877+instance Arbitrary BoostingQuery where arbitrary = sopArbitrary; shrink = genericShrink
878+instance Arbitrary BoolQuery where arbitrary = sopArbitrary; shrink = genericShrink
879+instance Arbitrary MatchQuery where arbitrary = sopArbitrary; shrink = genericShrink
880+instance Arbitrary MultiMatchQueryType where arbitrary = sopArbitrary; shrink = genericShrink
881+instance Arbitrary BooleanOperator where arbitrary = sopArbitrary; shrink = genericShrink
882+instance Arbitrary ZeroTermsQuery where arbitrary = sopArbitrary; shrink = genericShrink
883+instance Arbitrary MatchQueryType where arbitrary = sopArbitrary; shrink = genericShrink
884+instance Arbitrary SearchAliasRouting where arbitrary = sopArbitrary; shrink = genericShrink
885+instance Arbitrary ScoreType where arbitrary = sopArbitrary; shrink = genericShrink
886+instance Arbitrary Distance where arbitrary = sopArbitrary; shrink = genericShrink
887+instance Arbitrary DistanceUnit where arbitrary = sopArbitrary; shrink = genericShrink
888+instance Arbitrary DistanceType where arbitrary = sopArbitrary; shrink = genericShrink
889+instance Arbitrary OptimizeBbox where arbitrary = sopArbitrary; shrink = genericShrink
890+instance Arbitrary GeoBoundingBoxConstraint where arbitrary = sopArbitrary; shrink = genericShrink
891+instance Arbitrary GeoFilterType where arbitrary = sopArbitrary; shrink = genericShrink
892+instance Arbitrary GeoBoundingBox where arbitrary = sopArbitrary; shrink = genericShrink
893+instance Arbitrary LatLon where arbitrary = sopArbitrary; shrink = genericShrink
894+instance Arbitrary RangeExecution where arbitrary = sopArbitrary; shrink = genericShrink
895+instance Arbitrary RegexpFlag where arbitrary = sopArbitrary; shrink = genericShrink
896+instance Arbitrary BoolMatch where arbitrary = sopArbitrary; shrink = genericShrink
897+instance Arbitrary Term where arbitrary = sopArbitrary; shrink = genericShrink
898+instance Arbitrary IndexSettings where arbitrary = sopArbitrary; shrink = genericShrink
899+instance Arbitrary UpdatableIndexSetting where arbitrary = sopArbitrary; shrink = genericShrink
900+instance Arbitrary Bytes where arbitrary = sopArbitrary; shrink = genericShrink
901+instance Arbitrary AllocationPolicy where arbitrary = sopArbitrary; shrink = genericShrink
902+instance Arbitrary InitialShardCount where arbitrary = sopArbitrary; shrink = genericShrink
903+instance Arbitrary FSType where arbitrary = sopArbitrary; shrink = genericShrink
904+instance Arbitrary CompoundFormat where arbitrary = sopArbitrary; shrink = genericShrink
905+instance Arbitrary FsSnapshotRepo where arbitrary = sopArbitrary; shrink = genericShrink
906+instance Arbitrary SnapshotRepoName where arbitrary = sopArbitrary; shrink = genericShrink
905907
906908newtype UpdatableIndexSetting' = UpdatableIndexSetting' UpdatableIndexSetting
907909 deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
@@ -1841,3 +1843,17 @@ main = hspec $ do
18411843 propJSON (Proxy :: Proxy InitialShardCount)
18421844 propJSON (Proxy :: Proxy FSType)
18431845 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