git.iko.soy/typeable/bloodhound
on master help sign in
Fixing missing Arbitrary instance for NonEmpty
commit62959bcbfee76f75ee42cbb7dd0ab32d3ae34ef1 authorChris Allen <cma@bitemyapp.com> dateSun 24 Dec 2017, 13:34 (9 years ago) parent5986918
1 file changed+12
tests/V5/tests.hs+12
tests/V5/tests.hs+12
@@ -729,12 +729,24 @@ instance Arbitrary FieldName where
729729 shrink = genericShrink
730730
731731
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+
732743instance Arbitrary RegexpFlags where
733744 arbitrary = oneof [ pure AllRegexpFlags
734745 , pure NoRegexpFlags
735746 , SomeRegexpFlags <$> genUniqueFlags
736747 ]
737748 where genUniqueFlags = NE.fromList . nub <$> listOf1 arbitrary
749+
738750 shrink = genericShrink
739751
740752