1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Shrink Fixed subterms recursively.

This commit is contained in:
Rob Rix 2015-12-11 11:17:51 -05:00
parent 39cfe5f96f
commit e1161b46db

View File

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