1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Shrink subterms recursively.

This commit is contained in:
Rob Rix 2015-12-11 11:17:20 -05:00
parent 65bd8b19c8
commit d5041aaf5e

View File

@ -27,7 +27,7 @@ instance (Eq a, Eq annotation, Arbitrary a, Arbitrary annotation) => Arbitrary (
arbitrary = arbitraryBounded 4
shrink term@(ArbitraryTerm (annotation, syntax)) = filter (/= term) $ ArbitraryTerm <$> ((,) <$> shrink annotation <*> shrinkSyntax syntax)
where shrinkSyntax (Leaf a) = Leaf <$> shrink a
shrinkSyntax (Indexed i) = (getSyntax <$> i) ++ (Indexed <$> List.subsequences i)
shrinkSyntax (Indexed i) = (getSyntax <$> i) ++ (Indexed <$> (shrink =<< List.subsequences i))
shrinkSyntax (Syntax.Fixed f) = (getSyntax <$> f) ++ (Syntax.Fixed <$> List.subsequences f) ++ (Syntax.Fixed <$> shrink f)
shrinkSyntax (Keyed k) = (getSyntax . snd <$> (Map.toList k)) ++ (Keyed . Map.fromList <$> shrink (Map.toList k))
getSyntax (ArbitraryTerm (_, syntax)) = syntax