-
-
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 #520 from coder-hugo/feature/fix-parsing-of-entrie…
…s-with-colons #517 The key of an entry must be followed by a space
- Loading branch information
Showing
9 changed files
with
113 additions
and
43 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
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
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
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 |
---|---|---|
|
@@ -27,16 +27,16 @@ | |
*/ | ||
package com.amihaiemil.eoyaml; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* Unit tests for {@link ReadYamlSequence}. | ||
* @author Mihai Andronache ([email protected]) | ||
|
@@ -484,4 +484,18 @@ public void printsEmptyYaml() throws Exception { | |
); | ||
MatcherAssert.assertThat(sequence.toString(), Matchers.isEmptyString()); | ||
} | ||
|
||
@Test | ||
public void dontReturnMappingForScalarWithColon() { | ||
final List<YamlLine> lines = new ArrayList<>(); | ||
lines.add(new RtYamlLine("- scalar:with-colon", 0)); | ||
final YamlSequence sequence = new ReadYamlSequence( | ||
new AllYamlLines(lines) | ||
); | ||
|
||
MatcherAssert.assertThat(sequence.values(), Matchers.hasSize(1)); | ||
YamlNode sequenceItem = sequence.values().iterator().next(); | ||
MatcherAssert.assertThat(sequenceItem.type(), Matchers.equalTo(Node.SCALAR)); | ||
MatcherAssert.assertThat(sequenceItem.asScalar().value(), Matchers.equalTo("scalar:with-colon")); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -27,17 +27,21 @@ | |
*/ | ||
package com.amihaiemil.eoyaml; | ||
|
||
import java.io.*; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
/** | ||
* Unit tests for {@link RtYamlInput}. | ||
* @author Mihai Andronache ([email protected]) | ||
|
@@ -977,6 +981,43 @@ public void supportsSpringPropertyRef() throws IOException { | |
MatcherAssert.assertThat(pretty, Matchers.equalTo(fileContents)); | ||
} | ||
|
||
@Test | ||
public void shouldReadKeysProperly() throws IOException { | ||
final String filename = "issue_517_values_with_colons.yml"; | ||
|
||
final YamlMapping read = new RtYamlInput( | ||
new FileInputStream("src/test/resources/" + filename) | ||
).readYamlMapping(); | ||
|
||
MatcherAssert.assertThat(read.type(), Matchers.equalTo(Node.MAPPING)); | ||
MatcherAssert.assertThat( | ||
read.asMapping().keys(), | ||
Matchers.hasSize(2)); | ||
|
||
final YamlNode topLevelMapping = read.asMapping().value("a_mapping"); | ||
MatcherAssert.assertThat( | ||
topLevelMapping.type(), | ||
Matchers.equalTo(Node.MAPPING)); | ||
MatcherAssert.assertThat( | ||
topLevelMapping.asMapping().value("a_scalar").type(), | ||
Matchers.equalTo(Node.SCALAR)); | ||
MatcherAssert.assertThat( | ||
topLevelMapping.asMapping().value("a_scalar").asScalar().value(), | ||
Matchers.equalTo("value:with-colon")); | ||
|
||
YamlNode topLevelSequence = read.asMapping().value("a_sequence"); | ||
MatcherAssert.assertThat( | ||
topLevelSequence.type(), | ||
Matchers.equalTo(Node.SEQUENCE)); | ||
MatcherAssert.assertThat(topLevelSequence.asSequence().values(), | ||
Matchers.hasSize(1)); | ||
YamlNode sequenceItem = topLevelSequence.asSequence().values().iterator().next(); | ||
MatcherAssert.assertThat(sequenceItem.type(), | ||
Matchers.equalTo(Node.SCALAR)); | ||
MatcherAssert.assertThat(sequenceItem.asScalar().value(), | ||
Matchers.equalTo("value:with-colon")); | ||
} | ||
|
||
/** | ||
* 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
a_mapping: | ||
a_scalar: value:with-colon | ||
|
||
a_sequence: | ||
- value:with-colon |