Skip to content

Commit

Permalink
improvement (openrewrite#5037)
Browse files Browse the repository at this point in the history
Co-authored-by: lingenj <[email protected]>
  • Loading branch information
BelmoMusta and jevanlingen authored Feb 19, 2025
1 parent 9c6fa98 commit 29b8076
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions rewrite-yaml/src/test/java/org/openrewrite/yaml/MergeYamlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2738,4 +2738,86 @@ void insertAfterMergeSequenceMapAddAdditionalObject() {
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/5031")
void preventKeysToBeAppendedToPreviousComment() {
rewriteRun(spec -> spec
.recipe(new MergeYaml(//language=jsonpath
"$",
// language=yaml
"""
foo:
new-key: new-value
""",
false,
null,
null,
null
)),

yaml(// language=yaml
"""
#
foo:
existing-key: existing-value
# A simple comment
bar: bar-value
""",
// language=yaml
"""
#
foo:
existing-key: existing-value
new-key: new-value
# A simple comment
bar: bar-value
"""
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/5031")
void preventKeysToBeAppendedToPreviousCommentIfManyLineBreaks() {
rewriteRun(spec -> spec
.recipe(new MergeYaml(//language=jsonpath
"$",
// language=yaml
"""
foo:
new-key: new-value
""",
false,
null,
null,
null
)),

yaml(// language=yaml
"""
#
foo:
existing-key: existing-value
# A simple comment with trailing line breaks
bar: bar-value
""",
// language=yaml
"""
#
foo:
existing-key: existing-value
new-key: new-value
# A simple comment with trailing line breaks
bar: bar-value
"""
)
);
}
}

0 comments on commit 29b8076

Please sign in to comment.