rewrite
rewrite copied to clipboard
Yaml `new DeleteKey("$.*")` leads to two cycles if followed by `new MergeYaml`
This test fails with the
Expected recipe to complete in 1 cycle, but took 2 cycles. Each individual recipe would pass its own equivalent test, so this is a minimal subset required to fail the test.
Also this test no longer fails if the JSON matcher passed to
DeleteKeyis$.xrather than$.*. So there is clearly something different about how DeleteKey operates when asked to remove all root entries rather than the only root entry.
class CycleTest implements RewriteTest {
@Test
void testCycles() {
rewriteRun(
spec -> spec.recipe(
new CompositeRecipe(
List.of(
new DeleteKey("$.*"),
new MergeYaml("$", "foo: bar", null, "test.yml", null)
)
)
),
yaml(
"""
x: y
""",
"""
foo: bar
""",
spec -> spec.path("test.yml")
)
);
}
}
I think I remember having to allow this recipe to use two cycles in many tests. As this is a pretty frequently used recipe, it would be great if we could fix this.