-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #468 from decorators-squad/463
#463 print ScalarComment
- Loading branch information
Showing
3 changed files
with
126 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,6 @@ | |
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 4.2.0 | ||
* @todo #457:60min Continue modifying the printing logic for scalar comments: | ||
* The above and inline comments should be printed properly. | ||
*/ | ||
public final class YamlMappingCommentsPrintTest { | ||
|
||
|
@@ -240,6 +238,86 @@ public void readsScalarComments() throws IOException { | |
); | ||
} | ||
|
||
/** | ||
* A read YamlMapping should print itself together with the | ||
* read scalar . | ||
* @throws Exception If something goes wrong. | ||
*/ | ||
@Test | ||
public void printsReadYamlMappingWithScalarComments() throws Exception { | ||
final YamlMapping read = Yaml.createYamlInput( | ||
new File("src/test/resources/scalarCommentsInMapping.yml") | ||
).readYamlMapping(); | ||
System.out.println(read); | ||
MatcherAssert.assertThat( | ||
read.toString(), | ||
Matchers.equalTo( | ||
this.readExpected("scalarCommentsInMapping.yml") | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* We can print a built scalar with 2 comments. | ||
*/ | ||
@Test | ||
public void printsBuiltScalarWithTwoComments() { | ||
final Scalar scalar = Yaml.createYamlScalarBuilder() | ||
.addLine("simple") | ||
.buildPlainScalar("comment on top\nline2", "comment"); | ||
System.out.println(scalar); | ||
MatcherAssert.assertThat( | ||
scalar.toString(), | ||
Matchers.equalTo( | ||
"---" + System.lineSeparator() | ||
+ "# comment on top" + System.lineSeparator() | ||
+ "# line2" + System.lineSeparator() | ||
+ "simple # comment" + System.lineSeparator() | ||
+ "..." | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* We can print a built scalar an inline comment. | ||
*/ | ||
@Test | ||
public void printsBuiltScalarWithInline() { | ||
final Scalar scalar = Yaml.createYamlScalarBuilder() | ||
.addLine("simple") | ||
.buildPlainScalar("comment"); | ||
System.out.println(scalar); | ||
MatcherAssert.assertThat( | ||
scalar.toString(), | ||
Matchers.equalTo( | ||
"---" + System.lineSeparator() | ||
+ "simple # comment" + System.lineSeparator() | ||
+ "..." | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* We can print a built scalar with comment above. | ||
*/ | ||
@Test | ||
public void printsBuiltScalarWithAboveComment() { | ||
final Scalar scalar = Yaml.createYamlScalarBuilder() | ||
.addLine("simple") | ||
.buildPlainScalar("comment on top\nline2", ""); | ||
System.out.println(scalar); | ||
MatcherAssert.assertThat( | ||
scalar.toString(), | ||
Matchers.equalTo( | ||
"---" + System.lineSeparator() | ||
+ "# comment on top" + System.lineSeparator() | ||
+ "# line2" + System.lineSeparator() | ||
+ "simple" + System.lineSeparator() | ||
+ "..." | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Read a test resource file's contents. | ||
* @param fileName File to read. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters