mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Implement shrinking over ArbitraryTerm.
This commit is contained in:
parent
7dd4631053
commit
8d0272bdac
@ -24,6 +24,12 @@ unTerm arbitraryTerm = unfold unpack arbitraryTerm
|
||||
|
||||
instance (Arbitrary a, Arbitrary annotation) => Arbitrary (ArbitraryTerm a annotation) where
|
||||
arbitrary = arbitraryBounded 4
|
||||
shrink (ArbitraryTerm (annotation, syntax)) = ArbitraryTerm <$> ((,) <$> shrink annotation <*> shrinkSyntax syntax)
|
||||
where shrinkSyntax (Leaf a) = Leaf <$> shrink a
|
||||
shrinkSyntax (Indexed i) = (getSyntax <$> i) ++ (Indexed <$> shrink i)
|
||||
shrinkSyntax (Syntax.Fixed f) = (getSyntax <$> f) ++ (Syntax.Fixed <$> shrink f)
|
||||
shrinkSyntax (Keyed k) = (getSyntax . snd <$> (Map.toList k)) ++ (Keyed . Map.fromList <$> shrink (Map.toList k))
|
||||
getSyntax (ArbitraryTerm (_, syntax)) = syntax
|
||||
|
||||
arbitraryBounded :: (Arbitrary a, Arbitrary annotation) => Int -> Gen (ArbitraryTerm a annotation)
|
||||
arbitraryBounded k = ArbitraryTerm <$> ((,) <$> arbitrary <*> oneof [
|
||||
|
Loading…
Reference in New Issue
Block a user