@@ -7,9 +7,11 @@
77{-# LANGUAGE OverloadedStrings #-}
88{-# LANGUAGE RecordWildCards #-}
99{-# LANGUAGE ScopedTypeVariables #-}
10−{-# LANGUAGE TemplateHaskell #-}
1110{-# LANGUAGE TypeOperators #-}
1211{-# OPTIONS_GHC -fno-warn-orphans #-}
12+#if __GLASGOW_HASKELL__ < 800
13+{-# OPTIONS_GHC -fcontext-stack=100 #-}
14+#endif
1315module Main where
1416
1517import Control.Applicative
@@ -21,7 +23,6 @@ import Control.Monad.Reader
2123import Data.Aeson
2224import Data.Aeson.Types (parseEither)
2325import qualified Data.ByteString.Lazy.Char8 as BL8
24−import Data.DeriveTH
2526import qualified Data.HashMap.Strict as HM
2627import Data.List (nub)
2728import qualified Data.List as L
@@ -54,6 +55,8 @@ import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
5455import Test.Hspec.QuickCheck (prop)
5556import Test.QuickCheck
5657
58+import qualified Generics.SOP as SOP
59+import qualified Generics.SOP.GGP as SOP
5760
5861testServer :: Server
5962testServer = Server "http://localhost:9200"
@@ -589,7 +592,8 @@ instance ApproxEq BoolMatch
589592instance ApproxEq MultiMatchQuery
590593instance ApproxEq IndexSettings
591594instance ApproxEq AllocationPolicy
592−instance ApproxEq Char where (=~) = (==)
595+instance ApproxEq Char where
596+ (=~) = (==)
593597instance ApproxEq Vers.Version where
594598 (=~) = (==)
595599instance (ApproxEq a, Show a) => ApproxEq [a] where
@@ -787,113 +791,113 @@ instance Arbitrary VersionNumber where
787791 where
788792 mk versions = VersionNumber (Vers.Version versions [])
789793
790−$(derive makeArbitrary ''IndexName)
791−$(derive makeArbitrary ''MappingName)
792−$(derive makeArbitrary ''DocId)
793−$(derive makeArbitrary ''Version)
794−$(derive makeArbitrary ''BuildHash)
795−$(derive makeArbitrary ''IndexAliasRouting)
796−$(derive makeArbitrary ''ShardCount)
797−$(derive makeArbitrary ''ReplicaCount)
798−$(derive makeArbitrary ''TemplateName)
799−$(derive makeArbitrary ''TemplatePattern)
800−$(derive makeArbitrary ''QueryString)
801−$(derive makeArbitrary ''CacheName)
802−$(derive makeArbitrary ''CacheKey)
803−$(derive makeArbitrary ''Existence)
804−$(derive makeArbitrary ''CutoffFrequency)
805−$(derive makeArbitrary ''Analyzer)
806−$(derive makeArbitrary ''MaxExpansions)
807−$(derive makeArbitrary ''Lenient)
808−$(derive makeArbitrary ''Tiebreaker)
809−$(derive makeArbitrary ''Boost)
810−$(derive makeArbitrary ''BoostTerms)
811−$(derive makeArbitrary ''MinimumMatch)
812−$(derive makeArbitrary ''DisableCoord)
813−$(derive makeArbitrary ''IgnoreTermFrequency)
814−$(derive makeArbitrary ''MinimumTermFrequency)
815−$(derive makeArbitrary ''MaxQueryTerms)
816−$(derive makeArbitrary ''Fuzziness)
817−$(derive makeArbitrary ''PrefixLength)
818−$(derive makeArbitrary ''TypeName)
819−$(derive makeArbitrary ''PercentMatch)
820−$(derive makeArbitrary ''StopWord)
821−$(derive makeArbitrary ''QueryPath)
822−$(derive makeArbitrary ''AllowLeadingWildcard)
823−$(derive makeArbitrary ''LowercaseExpanded)
824−$(derive makeArbitrary ''EnablePositionIncrements)
825−$(derive makeArbitrary ''AnalyzeWildcard)
826−$(derive makeArbitrary ''GeneratePhraseQueries)
827−$(derive makeArbitrary ''Locale)
828−$(derive makeArbitrary ''MaxWordLength)
829−$(derive makeArbitrary ''MinWordLength)
830−$(derive makeArbitrary ''PhraseSlop)
831−$(derive makeArbitrary ''MinDocFrequency)
832−$(derive makeArbitrary ''MaxDocFrequency)
833−$(derive makeArbitrary ''Regexp)
834−$(derive makeArbitrary ''SimpleQueryStringQuery)
835−$(derive makeArbitrary ''FieldOrFields)
836−$(derive makeArbitrary ''SimpleQueryFlag)
837−$(derive makeArbitrary ''RegexpQuery)
838−$(derive makeArbitrary ''QueryStringQuery)
839−$(derive makeArbitrary ''RangeQuery)
840−$(derive makeArbitrary ''RangeValue)
841−$(derive makeArbitrary ''PrefixQuery)
842−$(derive makeArbitrary ''NestedQuery)
843−$(derive makeArbitrary ''MoreLikeThisFieldQuery)
844−$(derive makeArbitrary ''MoreLikeThisQuery)
845−$(derive makeArbitrary ''IndicesQuery)
846−$(derive makeArbitrary ''HasParentQuery)
847−$(derive makeArbitrary ''HasChildQuery)
848−$(derive makeArbitrary ''FuzzyQuery)
849−$(derive makeArbitrary ''FuzzyLikeFieldQuery)
850−$(derive makeArbitrary ''FuzzyLikeThisQuery)
851−$(derive makeArbitrary ''DisMaxQuery)
852−$(derive makeArbitrary ''CommonTermsQuery)
853−$(derive makeArbitrary ''DistanceRange)
854−$(derive makeArbitrary ''MultiMatchQuery)
855−$(derive makeArbitrary ''LessThanD)
856−$(derive makeArbitrary ''LessThanEqD)
857−$(derive makeArbitrary ''GreaterThanD)
858−$(derive makeArbitrary ''GreaterThanEqD)
859−$(derive makeArbitrary ''LessThan)
860−$(derive makeArbitrary ''LessThanEq)
861−$(derive makeArbitrary ''GreaterThan)
862−$(derive makeArbitrary ''GreaterThanEq)
863−$(derive makeArbitrary ''GeoPoint)
864−$(derive makeArbitrary ''NullValue)
865−$(derive makeArbitrary ''MinimumMatchHighLow)
866−$(derive makeArbitrary ''CommonMinimumMatch)
867−$(derive makeArbitrary ''BoostingQuery)
868−$(derive makeArbitrary ''BoolQuery)
869−$(derive makeArbitrary ''MatchQuery)
870−$(derive makeArbitrary ''MultiMatchQueryType)
871−$(derive makeArbitrary ''BooleanOperator)
872−$(derive makeArbitrary ''ZeroTermsQuery)
873−$(derive makeArbitrary ''MatchQueryType)
874−$(derive makeArbitrary ''SearchAliasRouting)
875−$(derive makeArbitrary ''ScoreType)
876−$(derive makeArbitrary ''Distance)
877−$(derive makeArbitrary ''DistanceUnit)
878−$(derive makeArbitrary ''DistanceType)
879−$(derive makeArbitrary ''OptimizeBbox)
880−$(derive makeArbitrary ''GeoBoundingBoxConstraint)
881−$(derive makeArbitrary ''GeoFilterType)
882−$(derive makeArbitrary ''GeoBoundingBox)
883−$(derive makeArbitrary ''LatLon)
884−$(derive makeArbitrary ''RangeExecution)
885−$(derive makeArbitrary ''RegexpFlag)
886−$(derive makeArbitrary ''BoolMatch)
887−$(derive makeArbitrary ''Term)
888−$(derive makeArbitrary ''IndexSettings)
889−$(derive makeArbitrary ''UpdatableIndexSetting)
890−$(derive makeArbitrary ''Bytes)
891−$(derive makeArbitrary ''AllocationPolicy)
892−$(derive makeArbitrary ''InitialShardCount)
893−$(derive makeArbitrary ''FSType)
894−$(derive makeArbitrary ''CompoundFormat)
895−$(derive makeArbitrary ''FsSnapshotRepo)
896−$(derive makeArbitrary ''SnapshotRepoName)
794+instance Arbitrary IndexName where arbitrary = sopArbitrary; shrink = genericShrink
795+instance Arbitrary MappingName where arbitrary = sopArbitrary; shrink = genericShrink
796+instance Arbitrary DocId where arbitrary = sopArbitrary; shrink = genericShrink
797+instance Arbitrary Version where arbitrary = sopArbitrary; shrink = genericShrink
798+instance Arbitrary BuildHash where arbitrary = sopArbitrary; shrink = genericShrink
799+instance Arbitrary IndexAliasRouting where arbitrary = sopArbitrary; shrink = genericShrink
800+instance Arbitrary ShardCount where arbitrary = sopArbitrary; shrink = genericShrink
801+instance Arbitrary ReplicaCount where arbitrary = sopArbitrary; shrink = genericShrink
802+instance Arbitrary TemplateName where arbitrary = sopArbitrary; shrink = genericShrink
803+instance Arbitrary TemplatePattern where arbitrary = sopArbitrary; shrink = genericShrink
804+instance Arbitrary QueryString where arbitrary = sopArbitrary; shrink = genericShrink
805+instance Arbitrary CacheName where arbitrary = sopArbitrary; shrink = genericShrink
806+instance Arbitrary CacheKey where arbitrary = sopArbitrary; shrink = genericShrink
807+instance Arbitrary Existence where arbitrary = sopArbitrary; shrink = genericShrink
808+instance Arbitrary CutoffFrequency where arbitrary = sopArbitrary; shrink = genericShrink
809+instance Arbitrary Analyzer where arbitrary = sopArbitrary; shrink = genericShrink
810+instance Arbitrary MaxExpansions where arbitrary = sopArbitrary; shrink = genericShrink
811+instance Arbitrary Lenient where arbitrary = sopArbitrary; shrink = genericShrink
812+instance Arbitrary Tiebreaker where arbitrary = sopArbitrary; shrink = genericShrink
813+instance Arbitrary Boost where arbitrary = sopArbitrary; shrink = genericShrink
814+instance Arbitrary BoostTerms where arbitrary = sopArbitrary; shrink = genericShrink
815+instance Arbitrary MinimumMatch where arbitrary = sopArbitrary; shrink = genericShrink
816+instance Arbitrary DisableCoord where arbitrary = sopArbitrary; shrink = genericShrink
817+instance Arbitrary IgnoreTermFrequency where arbitrary = sopArbitrary; shrink = genericShrink
818+instance Arbitrary MinimumTermFrequency where arbitrary = sopArbitrary; shrink = genericShrink
819+instance Arbitrary MaxQueryTerms where arbitrary = sopArbitrary; shrink = genericShrink
820+instance Arbitrary Fuzziness where arbitrary = sopArbitrary; shrink = genericShrink
821+instance Arbitrary PrefixLength where arbitrary = sopArbitrary; shrink = genericShrink
822+instance Arbitrary TypeName where arbitrary = sopArbitrary; shrink = genericShrink
823+instance Arbitrary PercentMatch where arbitrary = sopArbitrary; shrink = genericShrink
824+instance Arbitrary StopWord where arbitrary = sopArbitrary; shrink = genericShrink
825+instance Arbitrary QueryPath where arbitrary = sopArbitrary; shrink = genericShrink
826+instance Arbitrary AllowLeadingWildcard where arbitrary = sopArbitrary; shrink = genericShrink
827+instance Arbitrary LowercaseExpanded where arbitrary = sopArbitrary; shrink = genericShrink
828+instance Arbitrary EnablePositionIncrements where arbitrary = sopArbitrary; shrink = genericShrink
829+instance Arbitrary AnalyzeWildcard where arbitrary = sopArbitrary; shrink = genericShrink
830+instance Arbitrary GeneratePhraseQueries where arbitrary = sopArbitrary; shrink = genericShrink
831+instance Arbitrary Locale where arbitrary = sopArbitrary; shrink = genericShrink
832+instance Arbitrary MaxWordLength where arbitrary = sopArbitrary; shrink = genericShrink
833+instance Arbitrary MinWordLength where arbitrary = sopArbitrary; shrink = genericShrink
834+instance Arbitrary PhraseSlop where arbitrary = sopArbitrary; shrink = genericShrink
835+instance Arbitrary MinDocFrequency where arbitrary = sopArbitrary; shrink = genericShrink
836+instance Arbitrary MaxDocFrequency where arbitrary = sopArbitrary; shrink = genericShrink
837+instance Arbitrary Regexp where arbitrary = sopArbitrary; shrink = genericShrink
838+instance Arbitrary SimpleQueryStringQuery where arbitrary = sopArbitrary; shrink = genericShrink
839+instance Arbitrary FieldOrFields where arbitrary = sopArbitrary; shrink = genericShrink
840+instance Arbitrary SimpleQueryFlag where arbitrary = sopArbitrary; shrink = genericShrink
841+instance Arbitrary RegexpQuery where arbitrary = sopArbitrary; shrink = genericShrink
842+instance Arbitrary QueryStringQuery where arbitrary = sopArbitrary; shrink = genericShrink
843+instance Arbitrary RangeQuery where arbitrary = sopArbitrary; shrink = genericShrink
844+instance Arbitrary RangeValue where arbitrary = sopArbitrary; shrink = genericShrink
845+instance Arbitrary PrefixQuery where arbitrary = sopArbitrary; shrink = genericShrink
846+instance Arbitrary NestedQuery where arbitrary = sopArbitrary; shrink = genericShrink
847+instance Arbitrary MoreLikeThisFieldQuery where arbitrary = sopArbitrary; shrink = genericShrink
848+instance Arbitrary MoreLikeThisQuery where arbitrary = sopArbitrary; shrink = genericShrink
849+instance Arbitrary IndicesQuery where arbitrary = sopArbitrary; shrink = genericShrink
850+instance Arbitrary HasParentQuery where arbitrary = sopArbitrary; shrink = genericShrink
851+instance Arbitrary HasChildQuery where arbitrary = sopArbitrary; shrink = genericShrink
852+instance Arbitrary FuzzyQuery where arbitrary = sopArbitrary; shrink = genericShrink
853+instance Arbitrary FuzzyLikeFieldQuery where arbitrary = sopArbitrary; shrink = genericShrink
854+instance Arbitrary FuzzyLikeThisQuery where arbitrary = sopArbitrary; shrink = genericShrink
855+instance Arbitrary DisMaxQuery where arbitrary = sopArbitrary; shrink = genericShrink
856+instance Arbitrary CommonTermsQuery where arbitrary = sopArbitrary; shrink = genericShrink
857+instance Arbitrary DistanceRange where arbitrary = sopArbitrary; shrink = genericShrink
858+instance Arbitrary MultiMatchQuery where arbitrary = sopArbitrary; shrink = genericShrink
859+instance Arbitrary LessThanD where arbitrary = sopArbitrary; shrink = genericShrink
860+instance Arbitrary LessThanEqD where arbitrary = sopArbitrary; shrink = genericShrink
861+instance Arbitrary GreaterThanD where arbitrary = sopArbitrary; shrink = genericShrink
862+instance Arbitrary GreaterThanEqD where arbitrary = sopArbitrary; shrink = genericShrink
863+instance Arbitrary LessThan where arbitrary = sopArbitrary; shrink = genericShrink
864+instance Arbitrary LessThanEq where arbitrary = sopArbitrary; shrink = genericShrink
865+instance Arbitrary GreaterThan where arbitrary = sopArbitrary; shrink = genericShrink
866+instance Arbitrary GreaterThanEq where arbitrary = sopArbitrary; shrink = genericShrink
867+instance Arbitrary GeoPoint where arbitrary = sopArbitrary; shrink = genericShrink
868+instance Arbitrary NullValue where arbitrary = sopArbitrary; shrink = genericShrink
869+instance Arbitrary MinimumMatchHighLow where arbitrary = sopArbitrary; shrink = genericShrink
870+instance Arbitrary CommonMinimumMatch where arbitrary = sopArbitrary; shrink = genericShrink
871+instance Arbitrary BoostingQuery where arbitrary = sopArbitrary; shrink = genericShrink
872+instance Arbitrary BoolQuery where arbitrary = sopArbitrary; shrink = genericShrink
873+instance Arbitrary MatchQuery where arbitrary = sopArbitrary; shrink = genericShrink
874+instance Arbitrary MultiMatchQueryType where arbitrary = sopArbitrary; shrink = genericShrink
875+instance Arbitrary BooleanOperator where arbitrary = sopArbitrary; shrink = genericShrink
876+instance Arbitrary ZeroTermsQuery where arbitrary = sopArbitrary; shrink = genericShrink
877+instance Arbitrary MatchQueryType where arbitrary = sopArbitrary; shrink = genericShrink
878+instance Arbitrary SearchAliasRouting where arbitrary = sopArbitrary; shrink = genericShrink
879+instance Arbitrary ScoreType where arbitrary = sopArbitrary; shrink = genericShrink
880+instance Arbitrary Distance where arbitrary = sopArbitrary; shrink = genericShrink
881+instance Arbitrary DistanceUnit where arbitrary = sopArbitrary; shrink = genericShrink
882+instance Arbitrary DistanceType where arbitrary = sopArbitrary; shrink = genericShrink
883+instance Arbitrary OptimizeBbox where arbitrary = sopArbitrary; shrink = genericShrink
884+instance Arbitrary GeoBoundingBoxConstraint where arbitrary = sopArbitrary; shrink = genericShrink
885+instance Arbitrary GeoFilterType where arbitrary = sopArbitrary; shrink = genericShrink
886+instance Arbitrary GeoBoundingBox where arbitrary = sopArbitrary; shrink = genericShrink
887+instance Arbitrary LatLon where arbitrary = sopArbitrary; shrink = genericShrink
888+instance Arbitrary RangeExecution where arbitrary = sopArbitrary; shrink = genericShrink
889+instance Arbitrary RegexpFlag where arbitrary = sopArbitrary; shrink = genericShrink
890+instance Arbitrary BoolMatch where arbitrary = sopArbitrary; shrink = genericShrink
891+instance Arbitrary Term where arbitrary = sopArbitrary; shrink = genericShrink
892+instance Arbitrary IndexSettings where arbitrary = sopArbitrary; shrink = genericShrink
893+instance Arbitrary UpdatableIndexSetting where arbitrary = sopArbitrary; shrink = genericShrink
894+instance Arbitrary Bytes where arbitrary = sopArbitrary; shrink = genericShrink
895+instance Arbitrary AllocationPolicy where arbitrary = sopArbitrary; shrink = genericShrink
896+instance Arbitrary InitialShardCount where arbitrary = sopArbitrary; shrink = genericShrink
897+instance Arbitrary FSType where arbitrary = sopArbitrary; shrink = genericShrink
898+instance Arbitrary CompoundFormat where arbitrary = sopArbitrary; shrink = genericShrink
899+instance Arbitrary FsSnapshotRepo where arbitrary = sopArbitrary; shrink = genericShrink
900+instance Arbitrary SnapshotRepoName where arbitrary = sopArbitrary; shrink = genericShrink
897901
898902newtype UpdatableIndexSetting' = UpdatableIndexSetting' UpdatableIndexSetting
899903 deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
@@ -1617,3 +1621,17 @@ main = hspec $ do
16171621 propJSON (Proxy :: Proxy InitialShardCount)
16181622 propJSON (Proxy :: Proxy FSType)
16191623 propJSON (Proxy :: Proxy CompoundFormat)
1624+
1625+-- Temporary solution for lacking of generic derivation of Arbitrary
1626+-- We use generics-sop, as it's much more concise than directly using GHC.Generics
1627+--
1628+-- This will be unneeded after https://github.com/nick8325/quickcheck/pull/112
1629+-- is merged and released
1630+sopArbitrary :: forall a. (Generic a, SOP.GTo a, SOP.All SOP.SListI (SOP.GCode a), SOP.All2 Arbitrary (SOP.GCode a)) => Gen a
1631+sopArbitrary = fmap SOP.gto sopArbitrary'
1632+
1633+sopArbitrary' :: forall xss. (SOP.All SOP.SListI xss, SOP.All2 Arbitrary xss) => Gen (SOP.SOP SOP.I xss)
1634+sopArbitrary' = SOP.hsequence =<< elements (SOP.apInjs_POP $ SOP.hcpure p arbitrary)
1635+ where
1636+ p :: Proxy Arbitrary
1637+ p = Proxy