git.iko.soy/typeable/bloodhound
on master help sign in
Cleaned up tests a bit
commit53075095ab9b93c786ec4d1bf38a6a9720c9d017 authorChris Allen <cma@bitemyapp.com> dateThu 8 Feb 2018, 18:51 (9 years ago) parentc64536c
8 files changed+816−756
bloodhound.cabal+3−1 src/Database/Bloodhound/Common/Script.hs+2−4 src/Database/V5/Bloodhound/Internal/Query.hs+2−4 tests/V5/Test/ApproxEq.hs+63 tests/V5/Test/Generators.hs+534 tests/V5/Test/Import.hs+32 tests/V5/Test/JSON.hs+174 tests/V5/tests.hs+6−747
bloodhound.cabal+3−1
@@ -82,7 +82,9 @@ test-suite bloodhound-tests
8282 hs-source-dirs: tests/V1
8383 else
8484 hs-source-dirs: tests/V5
85−
85+ other-modules: Test.ApproxEq
86+ Test.Generators
87+ Test.JSON
8688 build-depends: base,
8789 bloodhound,
8890 bytestring,
src/Database/Bloodhound/Common/Script.hs+2−4
@@ -131,12 +131,10 @@ instance FromJSON ScoreMode where
131131functionScoreFunctionPair :: FunctionScoreFunction -> (Text, Value)
132132functionScoreFunctionPair (FunctionScoreFunctionScript functionScoreScript) =
133133 ("script_score", toJSON functionScoreScript)
134−
135134functionScoreFunctionPair (FunctionScoreFunctionRandom seed) =
136135 ("random_score", omitNulls [ "seed" .= seed ])
137−
138−functionScoreFunctionPair (FunctionScoreFunctionFieldValueFactor fieldValueFactor) =
139− ("field_value_factor", toJSON fieldValueFactor)
136+functionScoreFunctionPair (FunctionScoreFunctionFieldValueFactor fvf) =
137+ ("field_value_factor", toJSON fvf)
140138
141139parseFunctionScoreFunction :: Object -> Parser FunctionScoreFunction
142140parseFunctionScoreFunction o =
src/Database/V5/Bloodhound/Internal/Query.hs+2−4
@@ -13,8 +13,6 @@ import Data.Char (isNumber)
1313import qualified Data.HashMap.Strict as HM
1414import Data.List (nub)
1515import qualified Data.Text as T
16−import qualified Data.Traversable as DT
17−import qualified Data.Vector as V
1816
1917import Database.Bloodhound.Common.Script as X
2018import Database.V5.Bloodhound.Internal.Newtypes
@@ -558,10 +556,10 @@ data ComponentFunctionScoreFunction =
558556 } deriving (Eq, Show)
559557
560558instance ToJSON ComponentFunctionScoreFunction where
561− toJSON (ComponentFunctionScoreFunction filter fn weight) =
559+ toJSON (ComponentFunctionScoreFunction filter' fn weight) =
562560 omitNulls base
563561 where base = functionScoreFunctionPair fn :
564− [ "filter" .= filter
562+ [ "filter" .= filter'
565563 , "weight" .= weight ]
566564
567565instance FromJSON ComponentFunctionScoreFunction where
tests/V5/Test/ApproxEq.hsnew file+63
@@ -0,0 +1,63 @@
1+{-# LANGUAGE DefaultSignatures #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+
4+module Test.ApproxEq where
5+
6+import Database.V5.Bloodhound
7+
8+import Test.Import
9+
10+import qualified Data.List.NonEmpty as NE
11+
12+-- | Typeclass for "equal where it matters". Use this to specify
13+-- less-strict equivalence for things such as lists that can wind up
14+-- in an unpredictable order
15+class ApproxEq a where
16+ (=~) :: a -> a -> Bool
17+
18+ showApproxEq :: a -> String
19+ default showApproxEq :: (Show a) => a -> String
20+ showApproxEq = show
21+
22+(==~) :: (ApproxEq a) => a -> a -> Property
23+a ==~ b = counterexample (showApproxEq a ++ " !=~ " ++ showApproxEq b) (a =~ b)
24+
25+instance ApproxEq NominalDiffTime where (=~) = (==)
26+instance ApproxEq Bool where (=~) = (==)
27+instance ApproxEq Int where (=~) = (==)
28+instance (Eq a, Show a) => ApproxEq (Maybe a) where (=~) = (==)
29+instance ApproxEq Char where
30+ (=~) = (==)
31+
32+instance ApproxEq NodeAttrFilter where (=~) = (==)
33+instance ApproxEq NodeAttrName where (=~) = (==)
34+instance (Eq a, Show a) => ApproxEq (NonEmpty a) where (=~) = (==)
35+instance (ApproxEq l, Show l, ApproxEq r, Show r) => ApproxEq (Either l r) where
36+ Left a =~ Left b = a =~ b
37+ Right a =~ Right b = a =~ b
38+ _ =~ _ = False
39+ showApproxEq (Left x) = "Left " <> showApproxEq x
40+ showApproxEq (Right x) = "Right " <> showApproxEq x
41+instance (ApproxEq a, Show a) => ApproxEq [a] where
42+ as =~ bs = and (zipWith (=~) as bs)
43+instance ApproxEq ReplicaCount where (=~) = (==)
44+instance ApproxEq ReplicaBounds where (=~) = (==)
45+instance ApproxEq Bytes where (=~) = (==)
46+instance ApproxEq AllocationPolicy where (=~) = (==)
47+instance ApproxEq InitialShardCount where (=~) = (==)
48+instance ApproxEq FSType where (=~) = (==)
49+
50+-- | Due to the way nodeattrfilters get serialized here, they may come
51+-- out in a different order, but they are morally equivalent
52+instance ApproxEq UpdatableIndexSetting where
53+ RoutingAllocationInclude a =~ RoutingAllocationInclude b =
54+ NE.sort a =~ NE.sort b
55+ RoutingAllocationExclude a =~ RoutingAllocationExclude b =
56+ NE.sort a =~ NE.sort b
57+ RoutingAllocationRequire a =~ RoutingAllocationRequire b =
58+ NE.sort a =~ NE.sort b
59+ a =~ b = a == b
60+ showApproxEq (RoutingAllocationInclude xs) = show (RoutingAllocationInclude (NE.sort xs))
61+ showApproxEq (RoutingAllocationExclude xs) = show (RoutingAllocationExclude (NE.sort xs))
62+ showApproxEq (RoutingAllocationRequire xs) = show (RoutingAllocationRequire (NE.sort xs))
63+ showApproxEq x = show x
tests/V5/Test/Generators.hsnew file+534
@@ -0,0 +1,534 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3+{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TemplateHaskell #-}
5+
6+module Test.Generators where
7+
8+import Database.V5.Bloodhound
9+
10+import Test.Import
11+
12+import qualified Data.HashMap.Strict as HM
13+import qualified Data.List as L
14+import qualified Data.List.NonEmpty as NE
15+import qualified Data.Map as M
16+import qualified Data.Text as T
17+import qualified Data.Version as Vers
18+import Test.QuickCheck.TH.Generators
19+
20+import Test.ApproxEq
21+
22+instance Arbitrary NominalDiffTime where
23+ arbitrary = fromInteger <$> arbitrary
24+
25+#if !MIN_VERSION_QuickCheck(2,8,0)
26+instance (Arbitrary k, Ord k, Arbitrary v) => Arbitrary (M.Map k v) where
27+ arbitrary = M.fromList <$> arbitrary
28+#endif
29+
30+instance Arbitrary Text where
31+ arbitrary = T.pack <$> arbitrary
32+
33+instance Arbitrary UTCTime where
34+ arbitrary = UTCTime
35+ <$> arbitrary
36+ <*> (fromRational . toRational <$> choose (0::Double, 86400))
37+
38+instance Arbitrary Day where
39+ arbitrary = ModifiedJulianDay <$> (2000 +) <$> arbitrary
40+ shrink = (ModifiedJulianDay <$>) . shrink . toModifiedJulianDay
41+
42+#if !MIN_VERSION_QuickCheck(2,9,0)
43+instance Arbitrary a => Arbitrary (NonEmpty a) where
44+ arbitrary = liftA2 (:|) arbitrary arbitrary
45+#endif
46+
47+arbitraryScore :: Gen Score
48+arbitraryScore = fmap getPositive <$> arbitrary
49+
50+instance (Arbitrary a, Typeable a) => Arbitrary (Hit a) where
51+ arbitrary = Hit <$> arbitrary
52+ <*> arbitrary
53+ <*> arbitrary
54+ <*> arbitraryScore
55+ <*> arbitrary
56+ <*> arbitrary
57+ <*> arbitrary
58+
59+instance Arbitrary HitFields where
60+ arbitrary = pure (HitFields M.empty)
61+ shrink = const []
62+
63+instance (Arbitrary a, Typeable a) => Arbitrary (SearchHits a) where
64+ arbitrary = reduceSize $ do
65+ tot <- getPositive <$> arbitrary
66+ score <- arbitraryScore
67+ hs <- arbitrary
68+ return $ SearchHits tot score hs
69+
70+
71+reduceSize :: Gen a -> Gen a
72+reduceSize f = sized $ \n -> resize (n `div` 2) f
73+
74+arbitraryAlphaNum :: Gen Char
75+arbitraryAlphaNum = oneof [choose ('a', 'z')
76+ ,choose ('A','Z')
77+ , choose ('0', '9')]
78+
79+instance Arbitrary RoutingValue where
80+ arbitrary = RoutingValue . T.pack <$> listOf1 arbitraryAlphaNum
81+
82+instance Arbitrary AliasRouting where
83+ arbitrary = oneof [allAlias
84+ ,one
85+ ,theOther
86+ ,both']
87+ where one = GranularAliasRouting
88+ <$> (Just <$> arbitrary)
89+ <*> pure Nothing
90+ theOther = GranularAliasRouting Nothing
91+ <$> (Just <$> arbitrary)
92+ both' = GranularAliasRouting
93+ <$> (Just <$> arbitrary)
94+ <*> (Just <$> arbitrary)
95+ allAlias = AllAliasRouting <$> arbitrary
96+
97+
98+
99+instance Arbitrary FieldName where
100+ arbitrary =
101+ FieldName
102+ . T.pack
103+ <$> listOf1 arbitraryAlphaNum
104+
105+
106+#if MIN_VERSION_base(4,10,0)
107+-- Test.QuickCheck.Modifiers
108+
109+qcNonEmptyToNonEmpty :: NonEmptyList a -> NonEmpty a
110+qcNonEmptyToNonEmpty (NonEmpty (a : xs)) = (a :| xs)
111+qcNonEmptyToNonEmpty (NonEmpty []) = error "NonEmpty was empty!"
112+
113+instance Arbitrary a => Arbitrary (NonEmpty a) where
114+ arbitrary =
115+ qcNonEmptyToNonEmpty
116+ <$> arbitrary
117+#endif
118+instance Arbitrary ScriptFields where
119+ arbitrary =
120+ pure $ ScriptFields $
121+ HM.fromList []
122+
123+ shrink = const []
124+
125+instance Arbitrary ScriptParams where
126+ arbitrary =
127+ pure $ ScriptParams $
128+ HM.fromList [ ("a", Number 42)
129+ , ("b", String "forty two")
130+ ]
131+
132+ shrink = const []
133+
134+instance Arbitrary RegexpFlags where
135+ arbitrary = oneof [ pure AllRegexpFlags
136+ , pure NoRegexpFlags
137+ , SomeRegexpFlags <$> genUniqueFlags
138+ ]
139+ where genUniqueFlags =
140+ NE.fromList . L.nub
141+ <$> listOf1 arbitrary
142+
143+instance Arbitrary IndexAliasCreate where
144+ arbitrary =
145+ IndexAliasCreate
146+ <$> arbitrary
147+ <*> reduceSize arbitrary
148+
149+instance Arbitrary Query where
150+ arbitrary =
151+ reduceSize
152+ $ oneof [ TermQuery <$> arbitrary <*> arbitrary
153+ , TermsQuery <$> arbitrary <*> arbitrary
154+ , QueryMatchQuery <$> arbitrary
155+ , QueryMultiMatchQuery <$> arbitrary
156+ , QueryBoolQuery <$> arbitrary
157+ , QueryBoostingQuery <$> arbitrary
158+ , QueryCommonTermsQuery <$> arbitrary
159+ , ConstantScoreQuery <$> arbitrary <*> arbitrary
160+ , QueryDisMaxQuery <$> arbitrary
161+ , QueryFuzzyLikeThisQuery <$> arbitrary
162+ , QueryFuzzyLikeFieldQuery <$> arbitrary
163+ , QueryFuzzyQuery <$> arbitrary
164+ , QueryHasChildQuery <$> arbitrary
165+ , QueryHasParentQuery <$> arbitrary
166+ , IdsQuery <$> arbitrary <*> arbitrary
167+ , QueryIndicesQuery <$> arbitrary
168+ , MatchAllQuery <$> arbitrary
169+ , QueryMoreLikeThisQuery <$> arbitrary
170+ , QueryMoreLikeThisFieldQuery <$> arbitrary
171+ , QueryNestedQuery <$> arbitrary
172+ , QueryPrefixQuery <$> arbitrary
173+ , QueryQueryStringQuery <$> arbitrary
174+ , QuerySimpleQueryStringQuery <$> arbitrary
175+ , QueryRangeQuery <$> arbitrary
176+ , QueryRegexpQuery <$> arbitrary
177+ , QueryTemplateQueryInline <$> arbitrary
178+ ]
179+ -- TODO: Implement shrink
180+ -- shrink = genericShrink
181+
182+instance Arbitrary Filter where
183+ arbitrary =
184+ Filter <$> arbitrary
185+ shrink (Filter q) =
186+ Filter <$> shrink q
187+
188+instance Arbitrary ReplicaBounds where
189+ arbitrary = oneof [ replicasBounded
190+ , replicasLowerBounded
191+ , pure ReplicasUnbounded
192+ ]
193+ where replicasBounded = do
194+ Positive a <- arbitrary
195+ Positive b <- arbitrary
196+ return (ReplicasBounded a b)
197+ replicasLowerBounded = do
198+ Positive a <- arbitrary
199+ return (ReplicasLowerBounded a)
200+
201+instance Arbitrary NodeAttrName where
202+ arbitrary =
203+ NodeAttrName
204+ . T.pack
205+ <$> listOf1 arbitraryAlphaNum
206+
207+
208+instance Arbitrary NodeAttrFilter where
209+ arbitrary = do
210+ n <- arbitrary
211+ s:ss <- listOf1 (listOf1 arbitraryAlphaNum)
212+ let ts = T.pack <$> s :| ss
213+ return (NodeAttrFilter n ts)
214+
215+instance Arbitrary VersionNumber where
216+ arbitrary = mk . fmap getPositive . getNonEmpty <$> arbitrary
217+ where
218+ mk versions = VersionNumber (Vers.Version versions [])
219+
220+instance Arbitrary TemplateQueryKeyValuePairs where
221+ arbitrary = TemplateQueryKeyValuePairs . HM.fromList <$> arbitrary
222+ shrink (TemplateQueryKeyValuePairs x) = map (TemplateQueryKeyValuePairs . HM.fromList) . shrink $ HM.toList x
223+
224+makeArbitrary ''IndexName
225+instance Arbitrary IndexName where arbitrary = arbitraryIndexName
226+makeArbitrary ''MappingName
227+instance Arbitrary MappingName where arbitrary = arbitraryMappingName
228+makeArbitrary ''DocId
229+instance Arbitrary DocId where arbitrary = arbitraryDocId
230+makeArbitrary ''Version
231+instance Arbitrary Version where arbitrary = arbitraryVersion
232+makeArbitrary ''BuildHash
233+instance Arbitrary BuildHash where arbitrary = arbitraryBuildHash
234+makeArbitrary ''IndexAliasRouting
235+instance Arbitrary IndexAliasRouting where arbitrary = arbitraryIndexAliasRouting
236+makeArbitrary ''ShardCount
237+instance Arbitrary ShardCount where arbitrary = arbitraryShardCount
238+makeArbitrary ''ReplicaCount
239+instance Arbitrary ReplicaCount where arbitrary = arbitraryReplicaCount
240+makeArbitrary ''TemplateName
241+instance Arbitrary TemplateName where arbitrary = arbitraryTemplateName
242+makeArbitrary ''TemplatePattern
243+instance Arbitrary TemplatePattern where arbitrary = arbitraryTemplatePattern
244+makeArbitrary ''QueryString
245+instance Arbitrary QueryString where arbitrary = arbitraryQueryString
246+makeArbitrary ''CacheName
247+instance Arbitrary CacheName where arbitrary = arbitraryCacheName
248+makeArbitrary ''CacheKey
249+instance Arbitrary CacheKey where arbitrary = arbitraryCacheKey
250+makeArbitrary ''Existence
251+instance Arbitrary Existence where arbitrary = arbitraryExistence
252+makeArbitrary ''CutoffFrequency
253+instance Arbitrary CutoffFrequency where arbitrary = arbitraryCutoffFrequency
254+makeArbitrary ''Analyzer
255+instance Arbitrary Analyzer where arbitrary = arbitraryAnalyzer
256+makeArbitrary ''MaxExpansions
257+instance Arbitrary MaxExpansions where arbitrary = arbitraryMaxExpansions
258+makeArbitrary ''Lenient
259+instance Arbitrary Lenient where arbitrary = arbitraryLenient
260+makeArbitrary ''Tiebreaker
261+instance Arbitrary Tiebreaker where arbitrary = arbitraryTiebreaker
262+makeArbitrary ''Boost
263+instance Arbitrary Boost where arbitrary = arbitraryBoost
264+makeArbitrary ''BoostTerms
265+instance Arbitrary BoostTerms where arbitrary = arbitraryBoostTerms
266+makeArbitrary ''MinimumMatch
267+instance Arbitrary MinimumMatch where arbitrary = arbitraryMinimumMatch
268+makeArbitrary ''DisableCoord
269+instance Arbitrary DisableCoord where arbitrary = arbitraryDisableCoord
270+makeArbitrary ''IgnoreTermFrequency
271+instance Arbitrary IgnoreTermFrequency where arbitrary = arbitraryIgnoreTermFrequency
272+makeArbitrary ''MinimumTermFrequency
273+instance Arbitrary MinimumTermFrequency where arbitrary = arbitraryMinimumTermFrequency
274+makeArbitrary ''MaxQueryTerms
275+instance Arbitrary MaxQueryTerms where arbitrary = arbitraryMaxQueryTerms
276+makeArbitrary ''Fuzziness
277+instance Arbitrary Fuzziness where arbitrary = arbitraryFuzziness
278+makeArbitrary ''PrefixLength
279+instance Arbitrary PrefixLength where arbitrary = arbitraryPrefixLength
280+makeArbitrary ''TypeName
281+instance Arbitrary TypeName where arbitrary = arbitraryTypeName
282+makeArbitrary ''PercentMatch
283+instance Arbitrary PercentMatch where arbitrary = arbitraryPercentMatch
284+makeArbitrary ''StopWord
285+instance Arbitrary StopWord where arbitrary = arbitraryStopWord
286+makeArbitrary ''QueryPath
287+instance Arbitrary QueryPath where arbitrary = arbitraryQueryPath
288+makeArbitrary ''AllowLeadingWildcard
289+instance Arbitrary AllowLeadingWildcard where arbitrary = arbitraryAllowLeadingWildcard
290+makeArbitrary ''LowercaseExpanded
291+instance Arbitrary LowercaseExpanded where arbitrary = arbitraryLowercaseExpanded
292+makeArbitrary ''EnablePositionIncrements
293+instance Arbitrary EnablePositionIncrements where arbitrary = arbitraryEnablePositionIncrements
294+makeArbitrary ''AnalyzeWildcard
295+instance Arbitrary AnalyzeWildcard where arbitrary = arbitraryAnalyzeWildcard
296+makeArbitrary ''GeneratePhraseQueries
297+instance Arbitrary GeneratePhraseQueries where arbitrary = arbitraryGeneratePhraseQueries
298+makeArbitrary ''Locale
299+instance Arbitrary Locale where arbitrary = arbitraryLocale
300+makeArbitrary ''MaxWordLength
301+instance Arbitrary MaxWordLength where arbitrary = arbitraryMaxWordLength
302+makeArbitrary ''MinWordLength
303+instance Arbitrary MinWordLength where arbitrary = arbitraryMinWordLength
304+makeArbitrary ''PhraseSlop
305+instance Arbitrary PhraseSlop where arbitrary = arbitraryPhraseSlop
306+makeArbitrary ''MinDocFrequency
307+instance Arbitrary MinDocFrequency where arbitrary = arbitraryMinDocFrequency
308+makeArbitrary ''MaxDocFrequency
309+instance Arbitrary MaxDocFrequency where arbitrary = arbitraryMaxDocFrequency
310+makeArbitrary ''Regexp
311+instance Arbitrary Regexp where arbitrary = arbitraryRegexp
312+makeArbitrary ''SimpleQueryStringQuery
313+instance Arbitrary SimpleQueryStringQuery where arbitrary = arbitrarySimpleQueryStringQuery
314+makeArbitrary ''FieldOrFields
315+instance Arbitrary FieldOrFields where arbitrary = arbitraryFieldOrFields
316+makeArbitrary ''SimpleQueryFlag
317+instance Arbitrary SimpleQueryFlag where arbitrary = arbitrarySimpleQueryFlag
318+makeArbitrary ''RegexpQuery
319+instance Arbitrary RegexpQuery where arbitrary = arbitraryRegexpQuery
320+makeArbitrary ''QueryStringQuery
321+instance Arbitrary QueryStringQuery where arbitrary = arbitraryQueryStringQuery
322+makeArbitrary ''RangeQuery
323+instance Arbitrary RangeQuery where arbitrary = arbitraryRangeQuery
324+makeArbitrary ''RangeValue
325+instance Arbitrary RangeValue where arbitrary = arbitraryRangeValue
326+makeArbitrary ''PrefixQuery
327+instance Arbitrary PrefixQuery where arbitrary = arbitraryPrefixQuery
328+makeArbitrary ''NestedQuery
329+instance Arbitrary NestedQuery where arbitrary = arbitraryNestedQuery
330+makeArbitrary ''MoreLikeThisFieldQuery
331+instance Arbitrary MoreLikeThisFieldQuery where arbitrary = arbitraryMoreLikeThisFieldQuery
332+makeArbitrary ''MoreLikeThisQuery
333+instance Arbitrary MoreLikeThisQuery where arbitrary = arbitraryMoreLikeThisQuery
334+makeArbitrary ''IndicesQuery
335+instance Arbitrary IndicesQuery where arbitrary = arbitraryIndicesQuery
336+makeArbitrary ''HasParentQuery
337+instance Arbitrary HasParentQuery where arbitrary = arbitraryHasParentQuery
338+makeArbitrary ''HasChildQuery
339+instance Arbitrary HasChildQuery where arbitrary = arbitraryHasChildQuery
340+makeArbitrary ''FuzzyQuery
341+instance Arbitrary FuzzyQuery where arbitrary = arbitraryFuzzyQuery
342+makeArbitrary ''FuzzyLikeFieldQuery
343+instance Arbitrary FuzzyLikeFieldQuery where arbitrary = arbitraryFuzzyLikeFieldQuery
344+makeArbitrary ''FuzzyLikeThisQuery
345+instance Arbitrary FuzzyLikeThisQuery where arbitrary = arbitraryFuzzyLikeThisQuery
346+makeArbitrary ''DisMaxQuery
347+instance Arbitrary DisMaxQuery where arbitrary = arbitraryDisMaxQuery
348+makeArbitrary ''CommonTermsQuery
349+instance Arbitrary CommonTermsQuery where arbitrary = arbitraryCommonTermsQuery
350+makeArbitrary ''DistanceRange
351+instance Arbitrary DistanceRange where arbitrary = arbitraryDistanceRange
352+makeArbitrary ''MultiMatchQuery
353+instance Arbitrary MultiMatchQuery where arbitrary = arbitraryMultiMatchQuery
354+makeArbitrary ''LessThanD
355+instance Arbitrary LessThanD where arbitrary = arbitraryLessThanD
356+makeArbitrary ''LessThanEqD
357+instance Arbitrary LessThanEqD where arbitrary = arbitraryLessThanEqD
358+makeArbitrary ''GreaterThanD
359+instance Arbitrary GreaterThanD where arbitrary = arbitraryGreaterThanD
360+makeArbitrary ''GreaterThanEqD
361+instance Arbitrary GreaterThanEqD where arbitrary = arbitraryGreaterThanEqD
362+makeArbitrary ''LessThan
363+instance Arbitrary LessThan where arbitrary = arbitraryLessThan
364+makeArbitrary ''LessThanEq
365+instance Arbitrary LessThanEq where arbitrary = arbitraryLessThanEq
366+makeArbitrary ''GreaterThan
367+instance Arbitrary GreaterThan where arbitrary = arbitraryGreaterThan
368+makeArbitrary ''GreaterThanEq
369+instance Arbitrary GreaterThanEq where arbitrary = arbitraryGreaterThanEq
370+makeArbitrary ''GeoPoint
371+instance Arbitrary GeoPoint where arbitrary = arbitraryGeoPoint
372+makeArbitrary ''NullValue
373+instance Arbitrary NullValue where arbitrary = arbitraryNullValue
374+makeArbitrary ''MinimumMatchHighLow
375+instance Arbitrary MinimumMatchHighLow where arbitrary = arbitraryMinimumMatchHighLow
376+makeArbitrary ''CommonMinimumMatch
377+instance Arbitrary CommonMinimumMatch where arbitrary = arbitraryCommonMinimumMatch
378+makeArbitrary ''BoostingQuery
379+instance Arbitrary BoostingQuery where arbitrary = arbitraryBoostingQuery
380+makeArbitrary ''BoolQuery
381+instance Arbitrary BoolQuery where arbitrary = arbitraryBoolQuery
382+makeArbitrary ''MatchQuery
383+instance Arbitrary MatchQuery where arbitrary = arbitraryMatchQuery
384+makeArbitrary ''MultiMatchQueryType
385+instance Arbitrary MultiMatchQueryType where arbitrary = arbitraryMultiMatchQueryType
386+makeArbitrary ''BooleanOperator
387+instance Arbitrary BooleanOperator where arbitrary = arbitraryBooleanOperator
388+makeArbitrary ''ZeroTermsQuery
389+instance Arbitrary ZeroTermsQuery where arbitrary = arbitraryZeroTermsQuery
390+makeArbitrary ''MatchQueryType
391+instance Arbitrary MatchQueryType where arbitrary = arbitraryMatchQueryType
392+makeArbitrary ''SearchAliasRouting
393+instance Arbitrary SearchAliasRouting where arbitrary = arbitrarySearchAliasRouting
394+makeArbitrary ''ScoreType
395+instance Arbitrary ScoreType where arbitrary = arbitraryScoreType
396+makeArbitrary ''Distance
397+instance Arbitrary Distance where arbitrary = arbitraryDistance
398+makeArbitrary ''DistanceUnit
399+instance Arbitrary DistanceUnit where arbitrary = arbitraryDistanceUnit
400+makeArbitrary ''DistanceType
401+instance Arbitrary DistanceType where arbitrary = arbitraryDistanceType
402+makeArbitrary ''OptimizeBbox
403+instance Arbitrary OptimizeBbox where arbitrary = arbitraryOptimizeBbox
404+makeArbitrary ''GeoBoundingBoxConstraint
405+instance Arbitrary GeoBoundingBoxConstraint where arbitrary = arbitraryGeoBoundingBoxConstraint
406+makeArbitrary ''GeoFilterType
407+instance Arbitrary GeoFilterType where arbitrary = arbitraryGeoFilterType
408+makeArbitrary ''GeoBoundingBox
409+instance Arbitrary GeoBoundingBox where arbitrary = arbitraryGeoBoundingBox
410+makeArbitrary ''LatLon
411+instance Arbitrary LatLon where arbitrary = arbitraryLatLon
412+makeArbitrary ''RangeExecution
413+instance Arbitrary RangeExecution where arbitrary = arbitraryRangeExecution
414+makeArbitrary ''RegexpFlag
415+instance Arbitrary RegexpFlag where arbitrary = arbitraryRegexpFlag
416+makeArbitrary ''BoolMatch
417+instance Arbitrary BoolMatch where arbitrary = arbitraryBoolMatch
418+makeArbitrary ''Term
419+instance Arbitrary Term where arbitrary = arbitraryTerm
420+makeArbitrary ''IndexSettings
421+instance Arbitrary IndexSettings where arbitrary = arbitraryIndexSettings
422+makeArbitrary ''TokenChar
423+instance Arbitrary TokenChar where arbitrary = arbitraryTokenChar
424+makeArbitrary ''Ngram
425+instance Arbitrary Ngram where arbitrary = arbitraryNgram
426+makeArbitrary ''TokenizerDefinition
427+instance Arbitrary TokenizerDefinition where arbitrary = arbitraryTokenizerDefinition
428+makeArbitrary ''TokenFilter
429+instance Arbitrary TokenFilter where arbitrary = arbitraryTokenFilter
430+makeArbitrary ''TokenFilterDefinition
431+instance Arbitrary TokenFilterDefinition where arbitrary = arbitraryTokenFilterDefinition
432+makeArbitrary ''Language
433+instance Arbitrary Language where arbitrary = arbitraryLanguage
434+makeArbitrary ''Shingle
435+instance Arbitrary Shingle where arbitrary = arbitraryShingle
436+makeArbitrary ''AnalyzerDefinition
437+instance Arbitrary AnalyzerDefinition where arbitrary = arbitraryAnalyzerDefinition
438+makeArbitrary ''Analysis
439+instance Arbitrary Analysis where arbitrary = arbitraryAnalysis
440+makeArbitrary ''Tokenizer
441+instance Arbitrary Tokenizer where arbitrary = arbitraryTokenizer
442+makeArbitrary ''UpdatableIndexSetting
443+instance Arbitrary UpdatableIndexSetting where
444+ arbitrary = arbitraryUpdatableIndexSetting
445+makeArbitrary ''Compression
446+instance Arbitrary Compression where arbitrary = arbitraryCompression
447+makeArbitrary ''Bytes
448+instance Arbitrary Bytes where arbitrary = arbitraryBytes
449+makeArbitrary ''AllocationPolicy
450+instance Arbitrary AllocationPolicy where arbitrary = arbitraryAllocationPolicy
451+makeArbitrary ''InitialShardCount
452+instance Arbitrary InitialShardCount where arbitrary = arbitraryInitialShardCount
453+makeArbitrary ''FSType
454+instance Arbitrary FSType where arbitrary = arbitraryFSType
455+makeArbitrary ''CompoundFormat
456+instance Arbitrary CompoundFormat where arbitrary = arbitraryCompoundFormat
457+makeArbitrary ''FsSnapshotRepo
458+instance Arbitrary FsSnapshotRepo where arbitrary = arbitraryFsSnapshotRepo
459+makeArbitrary ''SnapshotRepoName
460+instance Arbitrary SnapshotRepoName where arbitrary = arbitrarySnapshotRepoName
461+makeArbitrary ''TemplateQueryInline
462+instance Arbitrary TemplateQueryInline where arbitrary = arbitraryTemplateQueryInline
463+makeArbitrary ''DirectGeneratorSuggestModeTypes
464+instance Arbitrary DirectGeneratorSuggestModeTypes where arbitrary = arbitraryDirectGeneratorSuggestModeTypes
465+makeArbitrary ''DirectGenerators
466+instance Arbitrary DirectGenerators where arbitrary = arbitraryDirectGenerators
467+makeArbitrary ''PhraseSuggesterCollate
468+instance Arbitrary PhraseSuggesterCollate where arbitrary = arbitraryPhraseSuggesterCollate
469+makeArbitrary ''PhraseSuggesterHighlighter
470+instance Arbitrary PhraseSuggesterHighlighter where arbitrary = arbitraryPhraseSuggesterHighlighter
471+makeArbitrary ''Size
472+instance Arbitrary Size where arbitrary = arbitrarySize
473+makeArbitrary ''PhraseSuggester
474+instance Arbitrary PhraseSuggester where arbitrary = arbitraryPhraseSuggester
475+makeArbitrary ''SuggestType
476+instance Arbitrary SuggestType where arbitrary = arbitrarySuggestType
477+makeArbitrary ''Suggest
478+instance Arbitrary Suggest where arbitrary = arbitrarySuggest
479+
480+makeArbitrary ''FunctionScoreQuery
481+instance Arbitrary FunctionScoreQuery where arbitrary = arbitraryFunctionScoreQuery
482+
483+makeArbitrary ''FunctionScoreFunction
484+instance Arbitrary FunctionScoreFunction where arbitrary = arbitraryFunctionScoreFunction
485+makeArbitrary ''FunctionScoreFunctions
486+instance Arbitrary FunctionScoreFunctions where arbitrary = arbitraryFunctionScoreFunctions
487+makeArbitrary ''ComponentFunctionScoreFunction
488+instance Arbitrary ComponentFunctionScoreFunction where arbitrary = arbitraryComponentFunctionScoreFunction
489+makeArbitrary ''Script
490+instance Arbitrary Script where arbitrary = arbitraryScript
491+makeArbitrary ''ScriptLanguage
492+instance Arbitrary ScriptLanguage where arbitrary = arbitraryScriptLanguage
493+makeArbitrary ''ScriptInline
494+instance Arbitrary ScriptInline where arbitrary = arbitraryScriptInline
495+makeArbitrary ''ScriptId
496+instance Arbitrary ScriptId where arbitrary = arbitraryScriptId
497+makeArbitrary ''ScoreMode
498+instance Arbitrary ScoreMode where arbitrary = arbitraryScoreMode
499+makeArbitrary ''BoostMode
500+instance Arbitrary BoostMode where arbitrary = arbitraryBoostMode
501+makeArbitrary ''Seed
502+instance Arbitrary Seed where arbitrary = arbitrarySeed
503+makeArbitrary ''FieldValueFactor
504+instance Arbitrary FieldValueFactor where arbitrary = arbitraryFieldValueFactor
505+makeArbitrary ''Weight
506+instance Arbitrary Weight where arbitrary = arbitraryWeight
507+makeArbitrary ''Factor
508+instance Arbitrary Factor where arbitrary = arbitraryFactor
509+makeArbitrary ''FactorMissingFieldValue
510+instance Arbitrary FactorMissingFieldValue where arbitrary = arbitraryFactorMissingFieldValue
511+makeArbitrary ''FactorModifier
512+instance Arbitrary FactorModifier where arbitrary = arbitraryFactorModifier
513+
514+newtype UpdatableIndexSetting' =
515+ UpdatableIndexSetting' UpdatableIndexSetting
516+ deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
517+
518+instance Arbitrary UpdatableIndexSetting' where
519+ arbitrary = do
520+ settings <- arbitrary
521+ return $ UpdatableIndexSetting' $ case settings of
522+ RoutingAllocationInclude xs ->
523+ RoutingAllocationInclude (dropDuplicateAttrNames xs)
524+ RoutingAllocationExclude xs ->
525+ RoutingAllocationExclude (dropDuplicateAttrNames xs)
526+ RoutingAllocationRequire xs ->
527+ RoutingAllocationRequire (dropDuplicateAttrNames xs)
528+ x -> x
529+ where
530+ dropDuplicateAttrNames =
531+ NE.fromList . L.nubBy sameAttrName . NE.toList
532+ sameAttrName a b =
533+ nodeAttrFilterName a == nodeAttrFilterName b
534+ -- shrink (UpdatableIndexSetting' x) = map UpdatableIndexSetting' (shrink x)
tests/V5/Test/Import.hsnew file+32
@@ -0,0 +1,32 @@
1+module Test.Import
2+ ( module X
3+ ) where
4+
5+
6+import Control.Applicative as X
7+import Control.Exception as X (evaluate)
8+import Control.Monad as X
9+import Control.Monad.Catch as X
10+import Control.Monad.Reader as X
11+import Data.Aeson as X
12+import Data.Aeson.TH as X
13+import Data.Aeson.Types as X (parseEither)
14+import Data.List.NonEmpty as X (NonEmpty(..))
15+import Data.Monoid as X
16+import Data.Ord as X (comparing)
17+import Data.Proxy as X
18+import Data.Text as X (Text)
19+import Data.Time.Calendar as X (Day(..))
20+import Data.Time.Clock as X
21+import Data.Typeable as X
22+import Database.V5.Bloodhound as X hiding (key)
23+import Lens.Micro as X
24+import Lens.Micro.Aeson as X
25+import Network.HTTP.Client as X hiding (Proxy, fileSize)
26+import System.IO.Temp as X
27+import System.PosixCompat.Files as X
28+import Test.Hspec as X
29+import Test.Hspec.QuickCheck as X (prop)
30+import Test.QuickCheck as X hiding (Result, Success)
31+import Test.QuickCheck.Property.Monoid as X (T (..), eq, prop_Monoid)
32+import Text.Pretty.Simple as X (pPrint)
tests/V5/Test/JSON.hsnew file+174
@@ -0,0 +1,174 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
2+
3+module Test.JSON where
4+
5+import Database.V5.Bloodhound
6+
7+import Data.Aeson
8+import Data.Aeson.Types (parseEither)
9+import qualified Data.ByteString.Lazy.Char8 as BL8
10+import qualified Data.List as L
11+import qualified Data.List.NonEmpty as NE
12+import Data.Monoid
13+import Data.Typeable
14+import Test.Hspec
15+import Test.Hspec.QuickCheck
16+import Test.QuickCheck
17+
18+import Test.ApproxEq
19+import Test.Generators
20+
21+propJSON :: forall a
22+ . ( Arbitrary a
23+ , ToJSON a
24+ , FromJSON a
25+ , Show a
26+ , Eq a
27+ , Typeable a
28+ )
29+ => Proxy a -> Spec
30+propJSON _ = prop testName $ \(a :: a) ->
31+ let jsonStr = "via " <> BL8.unpack (encode a)
32+ in counterexample jsonStr (parseEither parseJSON (toJSON a)
33+ === Right a)
34+ where testName = show ty <> " FromJSON/ToJSON roundtrips"
35+ ty = typeOf (undefined :: a)
36+
37+propApproxJSON :: forall a
38+ . ( Arbitrary a
39+ , ToJSON a
40+ , FromJSON a
41+ , Show a
42+ , ApproxEq a
43+ , Typeable a
44+ )
45+ => Proxy a -> Spec
46+propApproxJSON _ = prop testName $ \(a :: a) ->
47+ let jsonStr = "via " <> BL8.unpack (encode a)
48+ in counterexample jsonStr (parseEither parseJSON (toJSON a)
49+ ==~ Right a)
50+ where testName = show ty <> " FromJSON/ToJSON roundtrips"
51+ ty = typeOf (undefined :: a)
52+
53+spec :: Spec
54+spec = do
55+ describe "Exact isomorphism JSON instances" $ do
56+ propJSON (Proxy :: Proxy Version)
57+ propJSON (Proxy :: Proxy IndexName)
58+ propJSON (Proxy :: Proxy MappingName)
59+ propJSON (Proxy :: Proxy DocId)
60+ propJSON (Proxy :: Proxy IndexAliasRouting)
61+ propJSON (Proxy :: Proxy RoutingValue)
62+ propJSON (Proxy :: Proxy ShardCount)
63+ propJSON (Proxy :: Proxy ReplicaCount)
64+ propJSON (Proxy :: Proxy TemplateName)
65+ propJSON (Proxy :: Proxy TemplatePattern)
66+ propJSON (Proxy :: Proxy QueryString)
67+ propJSON (Proxy :: Proxy FieldName)
68+ propJSON (Proxy :: Proxy Script)
69+ propJSON (Proxy :: Proxy ScriptLanguage)
70+ propJSON (Proxy :: Proxy ScriptInline)
71+ propJSON (Proxy :: Proxy ScriptId)
72+ propJSON (Proxy :: Proxy ScriptParams)
73+ propJSON (Proxy :: Proxy CacheName)
74+ propJSON (Proxy :: Proxy CacheKey)
75+ propJSON (Proxy :: Proxy Existence)
76+ propJSON (Proxy :: Proxy CutoffFrequency)
77+ propJSON (Proxy :: Proxy Analyzer)
78+ propJSON (Proxy :: Proxy MaxExpansions)
79+ propJSON (Proxy :: Proxy Lenient)
80+ propJSON (Proxy :: Proxy Tiebreaker)
81+ propJSON (Proxy :: Proxy Boost)
82+ propJSON (Proxy :: Proxy BoostTerms)
83+ propJSON (Proxy :: Proxy MinimumMatch)
84+ propJSON (Proxy :: Proxy DisableCoord)
85+ propJSON (Proxy :: Proxy IgnoreTermFrequency)
86+ propJSON (Proxy :: Proxy MinimumTermFrequency)
87+ propJSON (Proxy :: Proxy MaxQueryTerms)
88+ propJSON (Proxy :: Proxy Fuzziness)
89+ propJSON (Proxy :: Proxy PrefixLength)
90+ propJSON (Proxy :: Proxy TypeName)
91+ propJSON (Proxy :: Proxy PercentMatch)
92+ propJSON (Proxy :: Proxy StopWord)
93+ propJSON (Proxy :: Proxy QueryPath)
94+ propJSON (Proxy :: Proxy AllowLeadingWildcard)
95+ propJSON (Proxy :: Proxy LowercaseExpanded)
96+ propJSON (Proxy :: Proxy EnablePositionIncrements)
97+ propJSON (Proxy :: Proxy AnalyzeWildcard)
98+ propJSON (Proxy :: Proxy GeneratePhraseQueries)
99+ propJSON (Proxy :: Proxy Locale)
100+ propJSON (Proxy :: Proxy MaxWordLength)
101+ propJSON (Proxy :: Proxy MinWordLength)
102+ propJSON (Proxy :: Proxy PhraseSlop)
103+ propJSON (Proxy :: Proxy MinDocFrequency)
104+ propJSON (Proxy :: Proxy MaxDocFrequency)
105+ propJSON (Proxy :: Proxy Filter)
106+ propJSON (Proxy :: Proxy Query)
107+ propJSON (Proxy :: Proxy SimpleQueryStringQuery)
108+ propJSON (Proxy :: Proxy FieldOrFields)
109+ propJSON (Proxy :: Proxy SimpleQueryFlag)
110+ propJSON (Proxy :: Proxy RegexpQuery)
111+ propJSON (Proxy :: Proxy QueryStringQuery)
112+ propJSON (Proxy :: Proxy RangeQuery)
113+ propJSON (Proxy :: Proxy PrefixQuery)
114+ propJSON (Proxy :: Proxy NestedQuery)
115+ propJSON (Proxy :: Proxy MoreLikeThisFieldQuery)
116+ propJSON (Proxy :: Proxy MoreLikeThisQuery)
117+ propJSON (Proxy :: Proxy IndicesQuery)
118+ propJSON (Proxy :: Proxy HasParentQuery)
119+ propJSON (Proxy :: Proxy HasChildQuery)
120+ propJSON (Proxy :: Proxy FuzzyQuery)
121+ propJSON (Proxy :: Proxy FuzzyLikeFieldQuery)
122+ propJSON (Proxy :: Proxy FuzzyLikeThisQuery)
123+ propJSON (Proxy :: Proxy FunctionScoreQuery)
124+ propJSON (Proxy :: Proxy BoostMode)
125+ propJSON (Proxy :: Proxy ScoreMode)
126+ propJSON (Proxy :: Proxy ComponentFunctionScoreFunction)
127+ propJSON (Proxy :: Proxy FieldValueFactor)
128+ propJSON (Proxy :: Proxy FactorModifier)
129+ propJSON (Proxy :: Proxy DisMaxQuery)
130+ propJSON (Proxy :: Proxy CommonTermsQuery)
131+ propJSON (Proxy :: Proxy CommonMinimumMatch)
132+ propJSON (Proxy :: Proxy BoostingQuery)
133+ propJSON (Proxy :: Proxy BoolQuery)
134+ propJSON (Proxy :: Proxy MatchQuery)
135+ propJSON (Proxy :: Proxy MultiMatchQueryType)
136+ propJSON (Proxy :: Proxy BooleanOperator)
137+ propJSON (Proxy :: Proxy ZeroTermsQuery)
138+ propJSON (Proxy :: Proxy MatchQueryType)
139+ propJSON (Proxy :: Proxy AliasRouting)
140+ propJSON (Proxy :: Proxy IndexAliasCreate)
141+ propJSON (Proxy :: Proxy SearchAliasRouting)
142+ propJSON (Proxy :: Proxy ScoreType)
143+ propJSON (Proxy :: Proxy Distance)
144+ propJSON (Proxy :: Proxy DistanceUnit)
145+ propJSON (Proxy :: Proxy DistanceType)
146+ propJSON (Proxy :: Proxy OptimizeBbox)
147+ propJSON (Proxy :: Proxy GeoBoundingBoxConstraint)
148+ propJSON (Proxy :: Proxy GeoFilterType)
149+ propJSON (Proxy :: Proxy GeoBoundingBox)
150+ propJSON (Proxy :: Proxy LatLon)
151+ propJSON (Proxy :: Proxy RangeExecution)
152+ prop "RegexpFlags FromJSON/ToJSON roundtrips, removing dups " $ \rfs ->
153+ let expected = case rfs of
154+ SomeRegexpFlags fs -> SomeRegexpFlags (NE.fromList (L.nub (NE.toList fs)))
155+ x -> x
156+ in parseEither parseJSON (toJSON rfs) === Right expected
157+ propJSON (Proxy :: Proxy BoolMatch)
158+ propJSON (Proxy :: Proxy Term)
159+ propJSON (Proxy :: Proxy MultiMatchQuery)
160+ propJSON (Proxy :: Proxy IndexSettings)
161+ propJSON (Proxy :: Proxy CompoundFormat)
162+ propJSON (Proxy :: Proxy TemplateQueryInline)
163+ propJSON (Proxy :: Proxy Suggest)
164+ propJSON (Proxy :: Proxy DirectGenerators)
165+ propJSON (Proxy :: Proxy DirectGeneratorSuggestModeTypes)
166+
167+ describe "Approximate isomorphism JSON instances" $ do
168+ propApproxJSON (Proxy :: Proxy UpdatableIndexSetting')
169+ propApproxJSON (Proxy :: Proxy ReplicaCount)
170+ propApproxJSON (Proxy :: Proxy ReplicaBounds)
171+ propApproxJSON (Proxy :: Proxy Bytes)
172+ propApproxJSON (Proxy :: Proxy AllocationPolicy)
173+ propApproxJSON (Proxy :: Proxy InitialShardCount)
174+ propApproxJSON (Proxy :: Proxy FSType)
tests/V5/tests.hs+6−747
@@ -18,51 +18,30 @@
1818#endif
1919module Main where
2020
21−import Control.Applicative
21+import Test.Import
22+
2223import Control.Error hiding (Script)
23−import Control.Exception (evaluate)
24−import Control.Monad
25−import Control.Monad.Catch
26−import Control.Monad.Reader
27−import Data.Aeson
28−import Data.Aeson.TH
29−import Data.Aeson.Types (parseEither)
30−import qualified Data.ByteString.Lazy.Char8 as BL8
3124import qualified Data.HashMap.Strict as HM
3225import Data.List (nub)
3326import qualified Data.List as L
3427import Data.List.NonEmpty (NonEmpty (..))
3528import qualified Data.List.NonEmpty as NE
3629import qualified Data.Map.Strict as M
37−import Data.Monoid
38−import Data.Ord (comparing)
39−import Data.Proxy
4030import Data.Text (Text)
4131import qualified Data.Text as T
4232import Data.Time.Calendar (Day (..), fromGregorian)
43−import Data.Time.Clock (NominalDiffTime, UTCTime (..),
33+import Data.Time.Clock (UTCTime (..),
4434 secondsToDiffTime)
45−import Data.Typeable
4635import qualified Data.Vector as V
4736import qualified Data.Version as Vers
48−import Database.V5.Bloodhound
49−import Lens.Micro
50−import Lens.Micro.Aeson
37+import qualified Database.V5.Bloodhound
5138import qualified Lens.Micro.Aeson as LMA
52−import Network.HTTP.Client hiding (Proxy)
5339import qualified Network.HTTP.Types.Method as NHTM
5440import qualified Network.HTTP.Types.Status as NHTS
5541import qualified Network.URI as URI
5642import Prelude hiding (filter)
57−import System.IO.Temp
58−import System.PosixCompat.Files
59−import Test.Hspec
60−import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
6143
62−import Test.Hspec.QuickCheck (prop)
63−import Test.QuickCheck
64−import Test.QuickCheck.TH.Generators
65−-- import Text.Pretty.Simple (pPrint)
44+import qualified Test.JSON as JSON
6645
6746testServer :: Server
6847testServer = Server "http://localhost:9200"
@@ -156,22 +135,6 @@ is v = getServerVersion >>= \x -> return $ x == Just v
156135when' :: Monad m => m Bool -> m () -> m ()
157136when' b f = b >>= \x -> when x f
158137
159−propJSON :: forall a
160− . ( Arbitrary a
161− , ToJSON a
162− , FromJSON a
163− , Show a
164− , Eq a
165− , Typeable a
166− )
167− => Proxy a -> Spec
168−propJSON _ = prop testName $ \(a :: a) ->
169− let jsonStr = "via " <> BL8.unpack (encode a)
170− in counterexample jsonStr (parseEither parseJSON (toJSON a)
171− === Right a)
172− where testName = show ty <> " FromJSON/ToJSON roundtrips"
173− ty = typeOf (undefined :: a)
174−
175138data Location = Location { lat :: Double
176139 , lon :: Double } deriving (Eq, Show)
177140
@@ -451,114 +414,9 @@ instance FromJSON BulkTest where
451414 t <- o .: "name"
452415 BulkTest <$> parseJSON t
453416
454−-- | Typeclass for "equal where it matters". Use this to specify
455−-- less-strict equivalence for things such as lists that can wind up
456−-- in an unpredictable order
457−class ApproxEq a where
458− (=~) :: a -> a -> Bool
459−
460− showApproxEq :: a -> String
461− default showApproxEq :: (Show a) => a -> String
462− showApproxEq = show
463−
464−(==~) :: (ApproxEq a) => a -> a -> Property
465−a ==~ b = counterexample (showApproxEq a ++ " !=~ " ++ showApproxEq b) (a =~ b)
466−
467−propApproxJSON :: forall a
468− . ( Arbitrary a
469− , ToJSON a
470− , FromJSON a
471− , Show a
472− , ApproxEq a
473− , Typeable a
474− )
475− => Proxy a -> Spec
476−propApproxJSON _ = prop testName $ \(a :: a) ->
477− let jsonStr = "via " <> BL8.unpack (encode a)
478− in counterexample jsonStr (parseEither parseJSON (toJSON a)
479− ==~ Right a)
480− where testName = show ty <> " FromJSON/ToJSON roundtrips"
481− ty = typeOf (undefined :: a)
482−
483−instance ApproxEq NominalDiffTime where (=~) = (==)
484−instance ApproxEq Bool where (=~) = (==)
485−instance ApproxEq Int where (=~) = (==)
486−instance (Eq a, Show a) => ApproxEq (Maybe a) where (=~) = (==)
487−instance ApproxEq Char where
488− (=~) = (==)
489−
490−instance ApproxEq NodeAttrFilter where (=~) = (==)
491−instance ApproxEq NodeAttrName where (=~) = (==)
492−instance (Eq a, Show a) => ApproxEq (NonEmpty a) where (=~) = (==)
493−instance (ApproxEq l, Show l, ApproxEq r, Show r) => ApproxEq (Either l r) where
494− Left a =~ Left b = a =~ b
495− Right a =~ Right b = a =~ b
496− _ =~ _ = False
497− showApproxEq (Left x) = "Left " <> showApproxEq x
498− showApproxEq (Right x) = "Right " <> showApproxEq x
499−instance (ApproxEq a, Show a) => ApproxEq [a] where
500− as =~ bs = and (zipWith (=~) as bs)
501−instance ApproxEq ReplicaCount where (=~) = (==)
502−instance ApproxEq ReplicaBounds where (=~) = (==)
503−instance ApproxEq Bytes where (=~) = (==)
504−instance ApproxEq AllocationPolicy where (=~) = (==)
505−instance ApproxEq InitialShardCount where (=~) = (==)
506−instance ApproxEq FSType where (=~) = (==)
507−
508417noDuplicates :: Eq a => [a] -> Bool
509418noDuplicates xs = nub xs == xs
510419
511−instance Arbitrary NominalDiffTime where
512− arbitrary = fromInteger <$> arbitrary
513−
514−#if !MIN_VERSION_QuickCheck(2,8,0)
515−instance (Arbitrary k, Ord k, Arbitrary v) => Arbitrary (M.Map k v) where
516− arbitrary = M.fromList <$> arbitrary
517−#endif
518−
519−instance Arbitrary Text where
520− arbitrary = T.pack <$> arbitrary
521−
522−instance Arbitrary UTCTime where
523− arbitrary = UTCTime
524− <$> arbitrary
525− <*> (fromRational . toRational <$> choose (0::Double, 86400))
526−
527−instance Arbitrary Day where
528− arbitrary = ModifiedJulianDay <$> (2000 +) <$> arbitrary
529− shrink = (ModifiedJulianDay <$>) . shrink . toModifiedJulianDay
530−
531−#if !MIN_VERSION_QuickCheck(2,9,0)
532−instance Arbitrary a => Arbitrary (NonEmpty a) where
533− arbitrary = liftA2 (:|) arbitrary arbitrary
534−#endif
535−
536−arbitraryScore :: Gen Score
537−arbitraryScore = fmap getPositive <$> arbitrary
538−
539−instance (Arbitrary a, Typeable a) => Arbitrary (Hit a) where
540− arbitrary = Hit <$> arbitrary
541− <*> arbitrary
542− <*> arbitrary
543− <*> arbitraryScore
544− <*> arbitrary
545− <*> arbitrary
546− <*> arbitrary
547−
548−instance Arbitrary HitFields where
549− arbitrary = pure (HitFields M.empty)
550− shrink = const []
551−
552−instance (Arbitrary a, Typeable a) => Arbitrary (SearchHits a) where
553− arbitrary = reduceSize $ do
554− tot <- getPositive <$> arbitrary
555− score <- arbitraryScore
556− hs <- arbitrary
557− return $ SearchHits tot score hs
558−
559−
560−reduceSize :: Gen a -> Gen a
561−reduceSize f = sized $ \n -> resize (n `div` 2) f
562420
563421getSource :: EsResult a -> Maybe a
564422getSource = fmap _source . foundResult
@@ -570,487 +428,9 @@ grabFirst r =
570428 (Right Nothing) -> Left (EsError 500 "Source was missing")
571429 (Right (Just x)) -> Right x
572430
573−-------------------------------------------------------------------------------
574−arbitraryAlphaNum :: Gen Char
575−arbitraryAlphaNum = oneof [choose ('a', 'z')
576− ,choose ('A','Z')
577− , choose ('0', '9')]
578−
579−instance Arbitrary RoutingValue where
580− arbitrary = RoutingValue . T.pack <$> listOf1 arbitraryAlphaNum
581−
582−instance Arbitrary AliasRouting where
583− arbitrary = oneof [allAlias
584− ,one
585− ,theOther
586− ,both']
587− where one = GranularAliasRouting
588− <$> (Just <$> arbitrary)
589− <*> pure Nothing
590− theOther = GranularAliasRouting Nothing
591− <$> (Just <$> arbitrary)
592− both' = GranularAliasRouting
593− <$> (Just <$> arbitrary)
594− <*> (Just <$> arbitrary)
595− allAlias = AllAliasRouting <$> arbitrary
596−
597−
598−
599−instance Arbitrary FieldName where
600− arbitrary =
601− FieldName
602− . T.pack
603− <$> listOf1 arbitraryAlphaNum
604−
605−
606−#if MIN_VERSION_base(4,10,0)
607−-- Test.QuickCheck.Modifiers
608−
609−qcNonEmptyToNonEmpty :: NonEmptyList a -> NonEmpty a
610−qcNonEmptyToNonEmpty (NonEmpty (a : xs)) = (a :| xs)
611−qcNonEmptyToNonEmpty (NonEmpty []) = error "NonEmpty was empty!"
612−
613−instance Arbitrary a => Arbitrary (NonEmpty a) where
614− arbitrary =
615− qcNonEmptyToNonEmpty
616− <$> arbitrary
617−#endif
618−instance Arbitrary ScriptFields where
619− arbitrary =
620− pure $ ScriptFields $
621− HM.fromList []
622−
623− shrink = const []
624−
625−instance Arbitrary ScriptParams where
626− arbitrary =
627− pure $ ScriptParams $
628− HM.fromList [ ("a", Number 42)
629− , ("b", String "forty two")
630− ]
631−
632− shrink = const []
633−
634−instance Arbitrary RegexpFlags where
635− arbitrary = oneof [ pure AllRegexpFlags
636− , pure NoRegexpFlags
637− , SomeRegexpFlags <$> genUniqueFlags
638− ]
639− where genUniqueFlags =
640− NE.fromList . nub
641− <$> listOf1 arbitrary
642−
643−instance Arbitrary IndexAliasCreate where
644− arbitrary =
645− IndexAliasCreate
646− <$> arbitrary
647− <*> reduceSize arbitrary
648−
649−instance Arbitrary Query where
650− arbitrary =
651− reduceSize
652− $ oneof [ TermQuery <$> arbitrary <*> arbitrary
653− , TermsQuery <$> arbitrary <*> arbitrary
654− , QueryMatchQuery <$> arbitrary
655− , QueryMultiMatchQuery <$> arbitrary
656− , QueryBoolQuery <$> arbitrary
657− , QueryBoostingQuery <$> arbitrary
658− , QueryCommonTermsQuery <$> arbitrary
659− , ConstantScoreQuery <$> arbitrary <*> arbitrary
660− , QueryDisMaxQuery <$> arbitrary
661− , QueryFuzzyLikeThisQuery <$> arbitrary
662− , QueryFuzzyLikeFieldQuery <$> arbitrary
663− , QueryFuzzyQuery <$> arbitrary
664− , QueryHasChildQuery <$> arbitrary
665− , QueryHasParentQuery <$> arbitrary
666− , IdsQuery <$> arbitrary <*> arbitrary
667− , QueryIndicesQuery <$> arbitrary
668− , MatchAllQuery <$> arbitrary
669− , QueryMoreLikeThisQuery <$> arbitrary
670− , QueryMoreLikeThisFieldQuery <$> arbitrary
671− , QueryNestedQuery <$> arbitrary
672− , QueryPrefixQuery <$> arbitrary
673− , QueryQueryStringQuery <$> arbitrary
674− , QuerySimpleQueryStringQuery <$> arbitrary
675− , QueryRangeQuery <$> arbitrary
676− , QueryRegexpQuery <$> arbitrary
677− , QueryTemplateQueryInline <$> arbitrary
678− ]
679− -- TODO: Implement shrink
680− -- shrink = genericShrink
681−
682−instance Arbitrary Filter where
683− arbitrary =
684− Filter <$> arbitrary
685− shrink (Filter q) =
686− Filter <$> shrink q
687−
688−instance Arbitrary ReplicaBounds where
689− arbitrary = oneof [ replicasBounded
690− , replicasLowerBounded
691− , pure ReplicasUnbounded
692− ]
693− where replicasBounded = do
694− Positive a <- arbitrary
695− Positive b <- arbitrary
696− return (ReplicasBounded a b)
697− replicasLowerBounded = do
698− Positive a <- arbitrary
699− return (ReplicasLowerBounded a)
700−
701−instance Arbitrary NodeAttrName where
702− arbitrary =
703− NodeAttrName
704− . T.pack
705− <$> listOf1 arbitraryAlphaNum
706−
707−
708−instance Arbitrary NodeAttrFilter where
709− arbitrary = do
710− n <- arbitrary
711− s:ss <- listOf1 (listOf1 arbitraryAlphaNum)
712− let ts = T.pack <$> s :| ss
713− return (NodeAttrFilter n ts)
714−
715−instance Arbitrary VersionNumber where
716− arbitrary = mk . fmap getPositive . getNonEmpty <$> arbitrary
717− where
718− mk versions = VersionNumber (Vers.Version versions [])
719−
720−instance Arbitrary TemplateQueryKeyValuePairs where
721− arbitrary = TemplateQueryKeyValuePairs . HM.fromList <$> arbitrary
722− shrink (TemplateQueryKeyValuePairs x) = map (TemplateQueryKeyValuePairs . HM.fromList) . shrink $ HM.toList x
723−
724−makeArbitrary ''IndexName
725−instance Arbitrary IndexName where arbitrary = arbitraryIndexName
726−makeArbitrary ''MappingName
727−instance Arbitrary MappingName where arbitrary = arbitraryMappingName
728−makeArbitrary ''DocId
729−instance Arbitrary DocId where arbitrary = arbitraryDocId
730−makeArbitrary ''Version
731−instance Arbitrary Version where arbitrary = arbitraryVersion
732−makeArbitrary ''BuildHash
733−instance Arbitrary BuildHash where arbitrary = arbitraryBuildHash
734−makeArbitrary ''IndexAliasRouting
735−instance Arbitrary IndexAliasRouting where arbitrary = arbitraryIndexAliasRouting
736−makeArbitrary ''ShardCount
737−instance Arbitrary ShardCount where arbitrary = arbitraryShardCount
738−makeArbitrary ''ReplicaCount
739−instance Arbitrary ReplicaCount where arbitrary = arbitraryReplicaCount
740−makeArbitrary ''TemplateName
741−instance Arbitrary TemplateName where arbitrary = arbitraryTemplateName
742−makeArbitrary ''TemplatePattern
743−instance Arbitrary TemplatePattern where arbitrary = arbitraryTemplatePattern
744−makeArbitrary ''QueryString
745−instance Arbitrary QueryString where arbitrary = arbitraryQueryString
746−makeArbitrary ''CacheName
747−instance Arbitrary CacheName where arbitrary = arbitraryCacheName
748−makeArbitrary ''CacheKey
749−instance Arbitrary CacheKey where arbitrary = arbitraryCacheKey
750−makeArbitrary ''Existence
751−instance Arbitrary Existence where arbitrary = arbitraryExistence
752−makeArbitrary ''CutoffFrequency
753−instance Arbitrary CutoffFrequency where arbitrary = arbitraryCutoffFrequency
754−makeArbitrary ''Analyzer
755−instance Arbitrary Analyzer where arbitrary = arbitraryAnalyzer
756−makeArbitrary ''MaxExpansions
757−instance Arbitrary MaxExpansions where arbitrary = arbitraryMaxExpansions
758−makeArbitrary ''Lenient
759−instance Arbitrary Lenient where arbitrary = arbitraryLenient
760−makeArbitrary ''Tiebreaker
761−instance Arbitrary Tiebreaker where arbitrary = arbitraryTiebreaker
762−makeArbitrary ''Boost
763−instance Arbitrary Boost where arbitrary = arbitraryBoost
764−makeArbitrary ''BoostTerms
765−instance Arbitrary BoostTerms where arbitrary = arbitraryBoostTerms
766−makeArbitrary ''MinimumMatch
767−instance Arbitrary MinimumMatch where arbitrary = arbitraryMinimumMatch
768−makeArbitrary ''DisableCoord
769−instance Arbitrary DisableCoord where arbitrary = arbitraryDisableCoord
770−makeArbitrary ''IgnoreTermFrequency
771−instance Arbitrary IgnoreTermFrequency where arbitrary = arbitraryIgnoreTermFrequency
772−makeArbitrary ''MinimumTermFrequency
773−instance Arbitrary MinimumTermFrequency where arbitrary = arbitraryMinimumTermFrequency
774−makeArbitrary ''MaxQueryTerms
775−instance Arbitrary MaxQueryTerms where arbitrary = arbitraryMaxQueryTerms
776−makeArbitrary ''Fuzziness
777−instance Arbitrary Fuzziness where arbitrary = arbitraryFuzziness
778−makeArbitrary ''PrefixLength
779−instance Arbitrary PrefixLength where arbitrary = arbitraryPrefixLength
780−makeArbitrary ''TypeName
781−instance Arbitrary TypeName where arbitrary = arbitraryTypeName
782−makeArbitrary ''PercentMatch
783−instance Arbitrary PercentMatch where arbitrary = arbitraryPercentMatch
784−makeArbitrary ''StopWord
785−instance Arbitrary StopWord where arbitrary = arbitraryStopWord
786−makeArbitrary ''QueryPath
787−instance Arbitrary QueryPath where arbitrary = arbitraryQueryPath
788−makeArbitrary ''AllowLeadingWildcard
789−instance Arbitrary AllowLeadingWildcard where arbitrary = arbitraryAllowLeadingWildcard
790−makeArbitrary ''LowercaseExpanded
791−instance Arbitrary LowercaseExpanded where arbitrary = arbitraryLowercaseExpanded
792−makeArbitrary ''EnablePositionIncrements
793−instance Arbitrary EnablePositionIncrements where arbitrary = arbitraryEnablePositionIncrements
794−makeArbitrary ''AnalyzeWildcard
795−instance Arbitrary AnalyzeWildcard where arbitrary = arbitraryAnalyzeWildcard
796−makeArbitrary ''GeneratePhraseQueries
797−instance Arbitrary GeneratePhraseQueries where arbitrary = arbitraryGeneratePhraseQueries
798−makeArbitrary ''Locale
799−instance Arbitrary Locale where arbitrary = arbitraryLocale
800−makeArbitrary ''MaxWordLength
801−instance Arbitrary MaxWordLength where arbitrary = arbitraryMaxWordLength
802−makeArbitrary ''MinWordLength
803−instance Arbitrary MinWordLength where arbitrary = arbitraryMinWordLength
804−makeArbitrary ''PhraseSlop
805−instance Arbitrary PhraseSlop where arbitrary = arbitraryPhraseSlop
806−makeArbitrary ''MinDocFrequency
807−instance Arbitrary MinDocFrequency where arbitrary = arbitraryMinDocFrequency
808−makeArbitrary ''MaxDocFrequency
809−instance Arbitrary MaxDocFrequency where arbitrary = arbitraryMaxDocFrequency
810−makeArbitrary ''Regexp
811−instance Arbitrary Regexp where arbitrary = arbitraryRegexp
812−makeArbitrary ''SimpleQueryStringQuery
813−instance Arbitrary SimpleQueryStringQuery where arbitrary = arbitrarySimpleQueryStringQuery
814−makeArbitrary ''FieldOrFields
815−instance Arbitrary FieldOrFields where arbitrary = arbitraryFieldOrFields
816−makeArbitrary ''SimpleQueryFlag
817−instance Arbitrary SimpleQueryFlag where arbitrary = arbitrarySimpleQueryFlag
818−makeArbitrary ''RegexpQuery
819−instance Arbitrary RegexpQuery where arbitrary = arbitraryRegexpQuery
820−makeArbitrary ''QueryStringQuery
821−instance Arbitrary QueryStringQuery where arbitrary = arbitraryQueryStringQuery
822−makeArbitrary ''RangeQuery
823−instance Arbitrary RangeQuery where arbitrary = arbitraryRangeQuery
824−makeArbitrary ''RangeValue
825−instance Arbitrary RangeValue where arbitrary = arbitraryRangeValue
826−makeArbitrary ''PrefixQuery
827−instance Arbitrary PrefixQuery where arbitrary = arbitraryPrefixQuery
828−makeArbitrary ''NestedQuery
829−instance Arbitrary NestedQuery where arbitrary = arbitraryNestedQuery
830−makeArbitrary ''MoreLikeThisFieldQuery
831−instance Arbitrary MoreLikeThisFieldQuery where arbitrary = arbitraryMoreLikeThisFieldQuery
832−makeArbitrary ''MoreLikeThisQuery
833−instance Arbitrary MoreLikeThisQuery where arbitrary = arbitraryMoreLikeThisQuery
834−makeArbitrary ''IndicesQuery
835−instance Arbitrary IndicesQuery where arbitrary = arbitraryIndicesQuery
836−makeArbitrary ''HasParentQuery
837−instance Arbitrary HasParentQuery where arbitrary = arbitraryHasParentQuery
838−makeArbitrary ''HasChildQuery
839−instance Arbitrary HasChildQuery where arbitrary = arbitraryHasChildQuery
840−makeArbitrary ''FuzzyQuery
841−instance Arbitrary FuzzyQuery where arbitrary = arbitraryFuzzyQuery
842−makeArbitrary ''FuzzyLikeFieldQuery
843−instance Arbitrary FuzzyLikeFieldQuery where arbitrary = arbitraryFuzzyLikeFieldQuery
844−makeArbitrary ''FuzzyLikeThisQuery
845−instance Arbitrary FuzzyLikeThisQuery where arbitrary = arbitraryFuzzyLikeThisQuery
846−makeArbitrary ''DisMaxQuery
847−instance Arbitrary DisMaxQuery where arbitrary = arbitraryDisMaxQuery
848−makeArbitrary ''CommonTermsQuery
849−instance Arbitrary CommonTermsQuery where arbitrary = arbitraryCommonTermsQuery
850−makeArbitrary ''DistanceRange
851−instance Arbitrary DistanceRange where arbitrary = arbitraryDistanceRange
852−makeArbitrary ''MultiMatchQuery
853−instance Arbitrary MultiMatchQuery where arbitrary = arbitraryMultiMatchQuery
854−makeArbitrary ''LessThanD
855−instance Arbitrary LessThanD where arbitrary = arbitraryLessThanD
856−makeArbitrary ''LessThanEqD
857−instance Arbitrary LessThanEqD where arbitrary = arbitraryLessThanEqD
858−makeArbitrary ''GreaterThanD
859−instance Arbitrary GreaterThanD where arbitrary = arbitraryGreaterThanD
860−makeArbitrary ''GreaterThanEqD
861−instance Arbitrary GreaterThanEqD where arbitrary = arbitraryGreaterThanEqD
862−makeArbitrary ''LessThan
863−instance Arbitrary LessThan where arbitrary = arbitraryLessThan
864−makeArbitrary ''LessThanEq
865−instance Arbitrary LessThanEq where arbitrary = arbitraryLessThanEq
866−makeArbitrary ''GreaterThan
867−instance Arbitrary GreaterThan where arbitrary = arbitraryGreaterThan
868−makeArbitrary ''GreaterThanEq
869−instance Arbitrary GreaterThanEq where arbitrary = arbitraryGreaterThanEq
870−makeArbitrary ''GeoPoint
871−instance Arbitrary GeoPoint where arbitrary = arbitraryGeoPoint
872−makeArbitrary ''NullValue
873−instance Arbitrary NullValue where arbitrary = arbitraryNullValue
874−makeArbitrary ''MinimumMatchHighLow
875−instance Arbitrary MinimumMatchHighLow where arbitrary = arbitraryMinimumMatchHighLow
876−makeArbitrary ''CommonMinimumMatch
877−instance Arbitrary CommonMinimumMatch where arbitrary = arbitraryCommonMinimumMatch
878−makeArbitrary ''BoostingQuery
879−instance Arbitrary BoostingQuery where arbitrary = arbitraryBoostingQuery
880−makeArbitrary ''BoolQuery
881−instance Arbitrary BoolQuery where arbitrary = arbitraryBoolQuery
882−makeArbitrary ''MatchQuery
883−instance Arbitrary MatchQuery where arbitrary = arbitraryMatchQuery
884−makeArbitrary ''MultiMatchQueryType
885−instance Arbitrary MultiMatchQueryType where arbitrary = arbitraryMultiMatchQueryType
886−makeArbitrary ''BooleanOperator
887−instance Arbitrary BooleanOperator where arbitrary = arbitraryBooleanOperator
888−makeArbitrary ''ZeroTermsQuery
889−instance Arbitrary ZeroTermsQuery where arbitrary = arbitraryZeroTermsQuery
890−makeArbitrary ''MatchQueryType
891−instance Arbitrary MatchQueryType where arbitrary = arbitraryMatchQueryType
892−makeArbitrary ''SearchAliasRouting
893−instance Arbitrary SearchAliasRouting where arbitrary = arbitrarySearchAliasRouting
894−makeArbitrary ''ScoreType
895−instance Arbitrary ScoreType where arbitrary = arbitraryScoreType
896−makeArbitrary ''Distance
897−instance Arbitrary Distance where arbitrary = arbitraryDistance
898−makeArbitrary ''DistanceUnit
899−instance Arbitrary DistanceUnit where arbitrary = arbitraryDistanceUnit
900−makeArbitrary ''DistanceType
901−instance Arbitrary DistanceType where arbitrary = arbitraryDistanceType
902−makeArbitrary ''OptimizeBbox
903−instance Arbitrary OptimizeBbox where arbitrary = arbitraryOptimizeBbox
904−makeArbitrary ''GeoBoundingBoxConstraint
905−instance Arbitrary GeoBoundingBoxConstraint where arbitrary = arbitraryGeoBoundingBoxConstraint
906−makeArbitrary ''GeoFilterType
907−instance Arbitrary GeoFilterType where arbitrary = arbitraryGeoFilterType
908−makeArbitrary ''GeoBoundingBox
909−instance Arbitrary GeoBoundingBox where arbitrary = arbitraryGeoBoundingBox
910−makeArbitrary ''LatLon
911−instance Arbitrary LatLon where arbitrary = arbitraryLatLon
912−makeArbitrary ''RangeExecution
913−instance Arbitrary RangeExecution where arbitrary = arbitraryRangeExecution
914−makeArbitrary ''RegexpFlag
915−instance Arbitrary RegexpFlag where arbitrary = arbitraryRegexpFlag
916−makeArbitrary ''BoolMatch
917−instance Arbitrary BoolMatch where arbitrary = arbitraryBoolMatch
918−makeArbitrary ''Term
919−instance Arbitrary Term where arbitrary = arbitraryTerm
920−makeArbitrary ''IndexSettings
921−instance Arbitrary IndexSettings where arbitrary = arbitraryIndexSettings
922−makeArbitrary ''TokenChar
923−instance Arbitrary TokenChar where arbitrary = arbitraryTokenChar
924−makeArbitrary ''Ngram
925−instance Arbitrary Ngram where arbitrary = arbitraryNgram
926−makeArbitrary ''TokenizerDefinition
927−instance Arbitrary TokenizerDefinition where arbitrary = arbitraryTokenizerDefinition
928−makeArbitrary ''TokenFilter
929−instance Arbitrary TokenFilter where arbitrary = arbitraryTokenFilter
930−makeArbitrary ''TokenFilterDefinition
931−instance Arbitrary TokenFilterDefinition where arbitrary = arbitraryTokenFilterDefinition
932−makeArbitrary ''Language
933−instance Arbitrary Language where arbitrary = arbitraryLanguage
934−makeArbitrary ''Shingle
935−instance Arbitrary Shingle where arbitrary = arbitraryShingle
936−makeArbitrary ''AnalyzerDefinition
937−instance Arbitrary AnalyzerDefinition where arbitrary = arbitraryAnalyzerDefinition
938−makeArbitrary ''Analysis
939−instance Arbitrary Analysis where arbitrary = arbitraryAnalysis
940−makeArbitrary ''Tokenizer
941−instance Arbitrary Tokenizer where arbitrary = arbitraryTokenizer
942−makeArbitrary ''UpdatableIndexSetting
943−instance Arbitrary UpdatableIndexSetting where
944− arbitrary = arbitraryUpdatableIndexSetting
945−makeArbitrary ''Compression
946−instance Arbitrary Compression where arbitrary = arbitraryCompression
947−makeArbitrary ''Bytes
948−instance Arbitrary Bytes where arbitrary = arbitraryBytes
949−makeArbitrary ''AllocationPolicy
950−instance Arbitrary AllocationPolicy where arbitrary = arbitraryAllocationPolicy
951−makeArbitrary ''InitialShardCount
952−instance Arbitrary InitialShardCount where arbitrary = arbitraryInitialShardCount
953−makeArbitrary ''FSType
954−instance Arbitrary FSType where arbitrary = arbitraryFSType
955−makeArbitrary ''CompoundFormat
956−instance Arbitrary CompoundFormat where arbitrary = arbitraryCompoundFormat
957−makeArbitrary ''FsSnapshotRepo
958−instance Arbitrary FsSnapshotRepo where arbitrary = arbitraryFsSnapshotRepo
959−makeArbitrary ''SnapshotRepoName
960−instance Arbitrary SnapshotRepoName where arbitrary = arbitrarySnapshotRepoName
961−makeArbitrary ''TemplateQueryInline
962−instance Arbitrary TemplateQueryInline where arbitrary = arbitraryTemplateQueryInline
963−makeArbitrary ''DirectGeneratorSuggestModeTypes
964−instance Arbitrary DirectGeneratorSuggestModeTypes where arbitrary = arbitraryDirectGeneratorSuggestModeTypes
965−makeArbitrary ''DirectGenerators
966−instance Arbitrary DirectGenerators where arbitrary = arbitraryDirectGenerators
967−makeArbitrary ''PhraseSuggesterCollate
968−instance Arbitrary PhraseSuggesterCollate where arbitrary = arbitraryPhraseSuggesterCollate
969−makeArbitrary ''PhraseSuggesterHighlighter
970−instance Arbitrary PhraseSuggesterHighlighter where arbitrary = arbitraryPhraseSuggesterHighlighter
971−makeArbitrary ''Size
972−instance Arbitrary Size where arbitrary = arbitrarySize
973−makeArbitrary ''PhraseSuggester
974−instance Arbitrary PhraseSuggester where arbitrary = arbitraryPhraseSuggester
975−makeArbitrary ''SuggestType
976−instance Arbitrary SuggestType where arbitrary = arbitrarySuggestType
977−makeArbitrary ''Suggest
978−instance Arbitrary Suggest where arbitrary = arbitrarySuggest
979−
980−makeArbitrary ''FunctionScoreQuery
981−instance Arbitrary FunctionScoreQuery where arbitrary = arbitraryFunctionScoreQuery
982−
983−makeArbitrary ''FunctionScoreFunction
984−instance Arbitrary FunctionScoreFunction where arbitrary = arbitraryFunctionScoreFunction
985−makeArbitrary ''FunctionScoreFunctions
986−instance Arbitrary FunctionScoreFunctions where arbitrary = arbitraryFunctionScoreFunctions
987−makeArbitrary ''ComponentFunctionScoreFunction
988−instance Arbitrary ComponentFunctionScoreFunction where arbitrary = arbitraryComponentFunctionScoreFunction
989−makeArbitrary ''Script
990−instance Arbitrary Script where arbitrary = arbitraryScript
991−makeArbitrary ''ScriptLanguage
992−instance Arbitrary ScriptLanguage where arbitrary = arbitraryScriptLanguage
993−makeArbitrary ''ScriptInline
994−instance Arbitrary ScriptInline where arbitrary = arbitraryScriptInline
995−makeArbitrary ''ScriptId
996−instance Arbitrary ScriptId where arbitrary = arbitraryScriptId
997−makeArbitrary ''ScoreMode
998−instance Arbitrary ScoreMode where arbitrary = arbitraryScoreMode
999−makeArbitrary ''BoostMode
1000−instance Arbitrary BoostMode where arbitrary = arbitraryBoostMode
1001−makeArbitrary ''Seed
1002−instance Arbitrary Seed where arbitrary = arbitrarySeed
1003−makeArbitrary ''FieldValueFactor
1004−instance Arbitrary FieldValueFactor where arbitrary = arbitraryFieldValueFactor
1005−makeArbitrary ''Weight
1006−instance Arbitrary Weight where arbitrary = arbitraryWeight
1007−makeArbitrary ''Factor
1008−instance Arbitrary Factor where arbitrary = arbitraryFactor
1009−makeArbitrary ''FactorMissingFieldValue
1010−instance Arbitrary FactorMissingFieldValue where arbitrary = arbitraryFactorMissingFieldValue
1011−makeArbitrary ''FactorModifier
1012−instance Arbitrary FactorModifier where arbitrary = arbitraryFactorModifier
1013−
1014−newtype UpdatableIndexSetting' =
1015− UpdatableIndexSetting' UpdatableIndexSetting
1016− deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
1017−
1018−instance Arbitrary UpdatableIndexSetting' where
1019− arbitrary = do
1020− settings <- arbitrary
1021− return $ UpdatableIndexSetting' $ case settings of
1022− RoutingAllocationInclude xs ->
1023− RoutingAllocationInclude (dropDuplicateAttrNames xs)
1024− RoutingAllocationExclude xs ->
1025− RoutingAllocationExclude (dropDuplicateAttrNames xs)
1026− RoutingAllocationRequire xs ->
1027− RoutingAllocationRequire (dropDuplicateAttrNames xs)
1028− x -> x
1029− where
1030− dropDuplicateAttrNames =
1031− NE.fromList . L.nubBy sameAttrName . NE.toList
1032− sameAttrName a b =
1033− nodeAttrFilterName a == nodeAttrFilterName b
1034− -- shrink (UpdatableIndexSetting' x) = map UpdatableIndexSetting' (shrink x)
1035−
1036−-- | Due to the way nodeattrfilters get serialized here, they may come
1037−-- out in a different order, but they are morally equivalent
1038−instance ApproxEq UpdatableIndexSetting where
1039− RoutingAllocationInclude a =~ RoutingAllocationInclude b =
1040− NE.sort a =~ NE.sort b
1041− RoutingAllocationExclude a =~ RoutingAllocationExclude b =
1042− NE.sort a =~ NE.sort b
1043− RoutingAllocationRequire a =~ RoutingAllocationRequire b =
1044− NE.sort a =~ NE.sort b
1045− a =~ b = a == b
1046− showApproxEq (RoutingAllocationInclude xs) = show (RoutingAllocationInclude (NE.sort xs))
1047− showApproxEq (RoutingAllocationExclude xs) = show (RoutingAllocationExclude (NE.sort xs))
1048− showApproxEq (RoutingAllocationRequire xs) = show (RoutingAllocationRequire (NE.sort xs))
1049− showApproxEq x = show x
1050−
1051431main :: IO ()
1052432main = hspec $ do
1053−
433+ JSON.spec
1054434 describe "index create/delete API" $ do
1055435 it "creates and then deletes the requested index" $ withTestEnv $ do
1056436 -- priming state.
@@ -1881,124 +1261,3 @@ main = hspec $ do
18811261 let Just results =
18821262 hitFields (head (hits (searchHits sr)))
18831263 liftIO $ results `shouldBe` (HitFields (M.fromList [("test1", [Number 20000.0])]))
1884−
1885− describe "Exact isomorphism JSON instances" $ do
1886− propJSON (Proxy :: Proxy Version)
1887− propJSON (Proxy :: Proxy IndexName)
1888− propJSON (Proxy :: Proxy MappingName)
1889− propJSON (Proxy :: Proxy DocId)
1890− propJSON (Proxy :: Proxy IndexAliasRouting)
1891− propJSON (Proxy :: Proxy RoutingValue)
1892− propJSON (Proxy :: Proxy ShardCount)
1893− propJSON (Proxy :: Proxy ReplicaCount)
1894− propJSON (Proxy :: Proxy TemplateName)
1895− propJSON (Proxy :: Proxy TemplatePattern)
1896− propJSON (Proxy :: Proxy QueryString)
1897− propJSON (Proxy :: Proxy FieldName)
1898− propJSON (Proxy :: Proxy Script)
1899− propJSON (Proxy :: Proxy ScriptLanguage)
1900− propJSON (Proxy :: Proxy ScriptInline)
1901− propJSON (Proxy :: Proxy ScriptId)
1902− propJSON (Proxy :: Proxy ScriptParams)
1903− propJSON (Proxy :: Proxy CacheName)
1904− propJSON (Proxy :: Proxy CacheKey)
1905− propJSON (Proxy :: Proxy Existence)
1906− propJSON (Proxy :: Proxy CutoffFrequency)
1907− propJSON (Proxy :: Proxy Analyzer)
1908− propJSON (Proxy :: Proxy MaxExpansions)
1909− propJSON (Proxy :: Proxy Lenient)
1910− propJSON (Proxy :: Proxy Tiebreaker)
1911− propJSON (Proxy :: Proxy Boost)
1912− propJSON (Proxy :: Proxy BoostTerms)
1913− propJSON (Proxy :: Proxy MinimumMatch)
1914− propJSON (Proxy :: Proxy DisableCoord)
1915− propJSON (Proxy :: Proxy IgnoreTermFrequency)
1916− propJSON (Proxy :: Proxy MinimumTermFrequency)
1917− propJSON (Proxy :: Proxy MaxQueryTerms)
1918− propJSON (Proxy :: Proxy Fuzziness)
1919− propJSON (Proxy :: Proxy PrefixLength)
1920− propJSON (Proxy :: Proxy TypeName)
1921− propJSON (Proxy :: Proxy PercentMatch)
1922− propJSON (Proxy :: Proxy StopWord)
1923− propJSON (Proxy :: Proxy QueryPath)
1924− propJSON (Proxy :: Proxy AllowLeadingWildcard)
1925− propJSON (Proxy :: Proxy LowercaseExpanded)
1926− propJSON (Proxy :: Proxy EnablePositionIncrements)
1927− propJSON (Proxy :: Proxy AnalyzeWildcard)
1928− propJSON (Proxy :: Proxy GeneratePhraseQueries)
1929− propJSON (Proxy :: Proxy Locale)
1930− propJSON (Proxy :: Proxy MaxWordLength)
1931− propJSON (Proxy :: Proxy MinWordLength)
1932− propJSON (Proxy :: Proxy PhraseSlop)
1933− propJSON (Proxy :: Proxy MinDocFrequency)
1934− propJSON (Proxy :: Proxy MaxDocFrequency)
1935− propJSON (Proxy :: Proxy Filter)
1936− propJSON (Proxy :: Proxy Query)
1937− propJSON (Proxy :: Proxy SimpleQueryStringQuery)
1938− propJSON (Proxy :: Proxy FieldOrFields)
1939− propJSON (Proxy :: Proxy SimpleQueryFlag)
1940− propJSON (Proxy :: Proxy RegexpQuery)
1941− propJSON (Proxy :: Proxy QueryStringQuery)
1942− propJSON (Proxy :: Proxy RangeQuery)
1943− propJSON (Proxy :: Proxy PrefixQuery)
1944− propJSON (Proxy :: Proxy NestedQuery)
1945− propJSON (Proxy :: Proxy MoreLikeThisFieldQuery)
1946− propJSON (Proxy :: Proxy MoreLikeThisQuery)
1947− propJSON (Proxy :: Proxy IndicesQuery)
1948− propJSON (Proxy :: Proxy HasParentQuery)
1949− propJSON (Proxy :: Proxy HasChildQuery)
1950− propJSON (Proxy :: Proxy FuzzyQuery)
1951− propJSON (Proxy :: Proxy FuzzyLikeFieldQuery)
1952− propJSON (Proxy :: Proxy FuzzyLikeThisQuery)
1953− propJSON (Proxy :: Proxy FunctionScoreQuery)
1954− propJSON (Proxy :: Proxy BoostMode)
1955− propJSON (Proxy :: Proxy ScoreMode)
1956− propJSON (Proxy :: Proxy ComponentFunctionScoreFunction)
1957− propJSON (Proxy :: Proxy FieldValueFactor)
1958− propJSON (Proxy :: Proxy FactorModifier)
1959− propJSON (Proxy :: Proxy DisMaxQuery)
1960− propJSON (Proxy :: Proxy CommonTermsQuery)
1961− propJSON (Proxy :: Proxy CommonMinimumMatch)
1962− propJSON (Proxy :: Proxy BoostingQuery)
1963− propJSON (Proxy :: Proxy BoolQuery)
1964− propJSON (Proxy :: Proxy MatchQuery)
1965− propJSON (Proxy :: Proxy MultiMatchQueryType)
1966− propJSON (Proxy :: Proxy BooleanOperator)
1967− propJSON (Proxy :: Proxy ZeroTermsQuery)
1968− propJSON (Proxy :: Proxy MatchQueryType)
1969− propJSON (Proxy :: Proxy AliasRouting)
1970− propJSON (Proxy :: Proxy IndexAliasCreate)
1971− propJSON (Proxy :: Proxy SearchAliasRouting)
1972− propJSON (Proxy :: Proxy ScoreType)
1973− propJSON (Proxy :: Proxy Distance)
1974− propJSON (Proxy :: Proxy DistanceUnit)
1975− propJSON (Proxy :: Proxy DistanceType)
1976− propJSON (Proxy :: Proxy OptimizeBbox)
1977− propJSON (Proxy :: Proxy GeoBoundingBoxConstraint)
1978− propJSON (Proxy :: Proxy GeoFilterType)
1979− propJSON (Proxy :: Proxy GeoBoundingBox)
1980− propJSON (Proxy :: Proxy LatLon)
1981− propJSON (Proxy :: Proxy RangeExecution)
1982− prop "RegexpFlags FromJSON/ToJSON roundtrips, removing dups " $ \rfs ->
1983− let expected = case rfs of
1984− SomeRegexpFlags fs -> SomeRegexpFlags (NE.fromList (nub (NE.toList fs)))
1985− x -> x
1986− in parseEither parseJSON (toJSON rfs) === Right expected
1987− propJSON (Proxy :: Proxy BoolMatch)
1988− propJSON (Proxy :: Proxy Term)
1989− propJSON (Proxy :: Proxy MultiMatchQuery)
1990− propJSON (Proxy :: Proxy IndexSettings)
1991− propJSON (Proxy :: Proxy CompoundFormat)
1992− propJSON (Proxy :: Proxy TemplateQueryInline)
1993− propJSON (Proxy :: Proxy Suggest)
1994− propJSON (Proxy :: Proxy DirectGenerators)
1995− propJSON (Proxy :: Proxy DirectGeneratorSuggestModeTypes)
1996−
1997− describe "Approximate isomorphism JSON instances" $ do
1998− propApproxJSON (Proxy :: Proxy UpdatableIndexSetting')
1999− propApproxJSON (Proxy :: Proxy ReplicaCount)
2000− propApproxJSON (Proxy :: Proxy ReplicaBounds)
2001− propApproxJSON (Proxy :: Proxy Bytes)
2002− propApproxJSON (Proxy :: Proxy AllocationPolicy)
2003− propApproxJSON (Proxy :: Proxy InitialShardCount)
2004− propApproxJSON (Proxy :: Proxy FSType)