git.iko.soy/typeable/bloodhound
on master help sign in
Fix quickcheck failure due to ambiguous parse
d93e0d5Michael Xavier
tests/tests.hs+32−7
@@ -143,8 +143,8 @@ is v = getServerVersion >>= \x -> return $ x == Just v
143when' :: Monad m => m Bool -> m () -> m ()
143when' :: Monad m => m Bool -> m () -> m ()
144when' b f = b >>= \x -> when x f
144when' b f = b >>= \x -> when x f
145
145
146−(==~) :: (ApproxEq a, Show a) => a -> a -> Property
146+(==~) :: (ApproxEq a) => a -> a -> Property
147−a ==~ b = counterexample (show a ++ " !=~ " ++ show b) (a =~ b)
147+a ==~ b = counterexample (showApproxEq a ++ " !=~ " ++ showApproxEq b) (a =~ b)
148
148
149propJSON :: forall a. (Arbitrary a, ToJSON a, FromJSON a, Show a, ApproxEq a, Typeable a) => Proxy a -> Spec
149propJSON :: forall a. (Arbitrary a, ToJSON a, FromJSON a, Show a, ApproxEq a, Typeable a) => Proxy a -> Spec
150propJSON _ = prop testName $ \(a :: a) ->
150propJSON _ = prop testName $ \(a :: a) ->
@@ -451,14 +451,18 @@ class ApproxEq a where
451 default (=~) :: (Generic a, GApproxEq (Rep a)) => a -> a -> Bool
451 default (=~) :: (Generic a, GApproxEq (Rep a)) => a -> a -> Bool
452 a =~ b = gApproxEq (G.from a) (G.from b)
452 a =~ b = gApproxEq (G.from a) (G.from b)
453
453
454+ showApproxEq :: a -> String
455+ default showApproxEq :: (Show a) => a -> String
456+ showApproxEq = show
457+
454instance ApproxEq NominalDiffTime where (=~) = (==)
458instance ApproxEq NominalDiffTime where (=~) = (==)
455instance ApproxEq UTCTime where (=~) = (==)
459instance ApproxEq UTCTime where (=~) = (==)
456instance ApproxEq Text where (=~) = (==)
460instance ApproxEq Text where (=~) = (==)
457instance ApproxEq Bool where (=~) = (==)
461instance ApproxEq Bool where (=~) = (==)
458instance ApproxEq Int where (=~) = (==)
462instance ApproxEq Int where (=~) = (==)
459instance ApproxEq Double where (=~) = (==)
463instance ApproxEq Double where (=~) = (==)
460−instance ApproxEq a => ApproxEq (NonEmpty a)
464+instance (ApproxEq a, Show a) => ApproxEq (NonEmpty a)
461−instance ApproxEq a => ApproxEq (Maybe a)
465+instance (ApproxEq a, Show a) => ApproxEq (Maybe a)
462instance ApproxEq GeoPoint
466instance ApproxEq GeoPoint
463instance ApproxEq Regexp
467instance ApproxEq Regexp
464instance ApproxEq RangeValue
468instance ApproxEq RangeValue
@@ -575,12 +579,14 @@ instance ApproxEq AllocationPolicy
575instance ApproxEq Char
579instance ApproxEq Char
576instance ApproxEq Vers.Version where
580instance ApproxEq Vers.Version where
577 (=~) = (==)
581 (=~) = (==)
578−instance ApproxEq a => ApproxEq [a] where
582+instance (ApproxEq a, Show a) => ApproxEq [a] where
579 as =~ bs = and (zipWith (=~) as bs)
583 as =~ bs = and (zipWith (=~) as bs)
580−instance (ApproxEq l, ApproxEq r) => ApproxEq (Either l r) where
584+instance (ApproxEq l, Show l, ApproxEq r, Show r) => ApproxEq (Either l r) where
581 Left a =~ Left b = a =~ b
585 Left a =~ Left b = a =~ b
582 Right a =~ Right b = a =~ b
586 Right a =~ Right b = a =~ b
583 _ =~ _ = False
587 _ =~ _ = False
588+ showApproxEq (Left x) = "Left " <> showApproxEq x
589+ showApproxEq (Right x) = "Right " <> showApproxEq x
584instance ApproxEq NodeAttrFilter
590instance ApproxEq NodeAttrFilter
585instance ApproxEq NodeAttrName
591instance ApproxEq NodeAttrName
586instance ApproxEq BuildHash
592instance ApproxEq BuildHash
@@ -595,6 +601,10 @@ instance ApproxEq UpdatableIndexSetting where
595 RoutingAllocationRequire a =~ RoutingAllocationRequire b =
601 RoutingAllocationRequire a =~ RoutingAllocationRequire b =
596 NE.sort a =~ NE.sort b
602 NE.sort a =~ NE.sort b
597 a =~ b = a == b
603 a =~ b = a == b
604+ showApproxEq (RoutingAllocationInclude xs) = show (RoutingAllocationInclude (NE.sort xs))
605+ showApproxEq (RoutingAllocationExclude xs) = show (RoutingAllocationExclude (NE.sort xs))
606+ showApproxEq (RoutingAllocationRequire xs) = show (RoutingAllocationRequire (NE.sort xs))
607+ showApproxEq x = show x
598
608
599
609
600noDuplicates :: Eq a => [a] -> Bool
610noDuplicates :: Eq a => [a] -> Bool
@@ -892,6 +902,21 @@ $(derive makeArbitrary ''CompoundFormat)
892$(derive makeArbitrary ''FsSnapshotRepo)
902$(derive makeArbitrary ''FsSnapshotRepo)
893$(derive makeArbitrary ''SnapshotRepoName)
903$(derive makeArbitrary ''SnapshotRepoName)
894
904
905+newtype UpdatableIndexSetting' = UpdatableIndexSetting' UpdatableIndexSetting
906+ deriving (Show, Eq, ToJSON, FromJSON, ApproxEq)
907+
908+instance Arbitrary UpdatableIndexSetting' where
909+ arbitrary = do
910+ settings <- arbitrary
911+ return $ UpdatableIndexSetting' $ case settings of
912+ RoutingAllocationInclude xs -> RoutingAllocationInclude (dropDuplicateAttrNames xs)
913+ RoutingAllocationExclude xs -> RoutingAllocationExclude (dropDuplicateAttrNames xs)
914+ RoutingAllocationRequire xs -> RoutingAllocationRequire (dropDuplicateAttrNames xs)
915+ x -> x
916+ where
917+ dropDuplicateAttrNames = NE.fromList . L.nubBy sameAttrName . NE.toList
918+ sameAttrName a b = nodeAttrFilterName a == nodeAttrFilterName b
919+
895main :: IO ()
920main :: IO ()
896main = hspec $ do
921main = hspec $ do
897
922
@@ -1808,7 +1833,7 @@ main = hspec $ do
1808 propJSON (Proxy :: Proxy Term)
1833 propJSON (Proxy :: Proxy Term)
1809 propJSON (Proxy :: Proxy MultiMatchQuery)
1834 propJSON (Proxy :: Proxy MultiMatchQuery)
1810 propJSON (Proxy :: Proxy IndexSettings)
1835 propJSON (Proxy :: Proxy IndexSettings)
1811− propJSON (Proxy :: Proxy UpdatableIndexSetting)
1836+ propJSON (Proxy :: Proxy UpdatableIndexSetting')
1812 propJSON (Proxy :: Proxy ReplicaBounds)
1837 propJSON (Proxy :: Proxy ReplicaBounds)
1813 propJSON (Proxy :: Proxy Bytes)
1838 propJSON (Proxy :: Proxy Bytes)
1814 propJSON (Proxy :: Proxy AllocationPolicy)
1839 propJSON (Proxy :: Proxy AllocationPolicy)