git.iko.soy/typeable/bloodhound
on master help sign in
Fixing missing Arbitrary instance for NonEmpty
62959bcChris Allen
tests/V5/tests.hs+12
@@ -729,12 +729,24 @@ instance Arbitrary FieldName where
729 shrink = genericShrink
729 shrink = genericShrink
730
730
731
731
732+#if MIN_VERSION_base(4,10,0)
733+-- Test.QuickCheck.Modifiers
734+
735+qcNonEmptyToNonEmpty :: NonEmptyList a -> NonEmpty a
736+qcNonEmptyToNonEmpty (NonEmpty (a : xs)) = (a :| xs)
737+qcNonEmptyToNonEmpty (NonEmpty []) = error "NonEmpty was empty!"
738+
739+instance Arbitrary a => Arbitrary (NonEmpty a) where
740+ arbitrary = qcNonEmptyToNonEmpty <$> arbitrary
741+#endif
742+
732instance Arbitrary RegexpFlags where
743instance Arbitrary RegexpFlags where
733 arbitrary = oneof [ pure AllRegexpFlags
744 arbitrary = oneof [ pure AllRegexpFlags
734 , pure NoRegexpFlags
745 , pure NoRegexpFlags
735 , SomeRegexpFlags <$> genUniqueFlags
746 , SomeRegexpFlags <$> genUniqueFlags
736 ]
747 ]
737 where genUniqueFlags = NE.fromList . nub <$> listOf1 arbitrary
748 where genUniqueFlags = NE.fromList . nub <$> listOf1 arbitrary
749+
738 shrink = genericShrink
750 shrink = genericShrink
739
751
740
752