Skip to content

Commit

Permalink
Merge branch 'master' of github.com:decorators-squad/eo-yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Mar 5, 2020
2 parents ff68f78 + e236491 commit 3f367ab
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 51 deletions.
35 changes: 17 additions & 18 deletions rcfg/settings.xml.asc
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

hQEMA5qETcGag5w6AQf8CQ5LxvwQsn+mh18zd/Ke8a1TmC29FEVaNjlX90L7ptYJ
9WlsIi5UOXpRBRyqGi2oH/1g+/aQu5s522Ou59fJ1sdvSRwr2ljabTwGnayDIPQi
1+xrDdYPqcOb/D5P2Rta144Pws6vatW3o086Fo94l/8OeplsumvnsTyYsmESyAA3
HC1SvslDGikIm4kjuo5HqySsoTwZe9z1c0IFAM7T0LZt4puVl9PxkLUdV1mlCFDb
Ba8eNMz2TFQi/ehGbKpi9OuFzl0KwH1gXCwT2CFUE0GmzDPFDQDPJauYSEWZ5uA9
KeUwEvJxG64Pvzq5O4IVwDV3BkVe4rHCAZWg+AURWNLBDQG5fa0qi/8N8o9kvFCn
8tN3YxnlIeXeSFuHZjop11R5jC/Q2/i8HNwEjZwJIzrftDlC4Iq6AvaOjl4GTAnh
ITzlcPOTaOoDPuCpqJ5g51fwgwQDIgqRfJXlwO9WkzA//6z1DH1STQId7VKagHvt
7z8AcDGqH8zD1XUvR3XW4dBwErUdIL+uak9V9v3R/mdsCb/3XclNbJYG/5bb74Lk
X5GP1dbhKhNDg7sni7Q0rHFNKfhoseVQbozqiq53q9zbHpAn6PNzqMk71dbw+Ydx
nMMLjwwxok3khtr5l0H/iJ+K1jeHK332RhCuHmWAG5oVbxkpk9T9/bQjH8BFnfqN
XRk/y7fK3MzxaX8bIIS0r1rEOOlac+tM0iJYzhB6PvAX/7CCct1usMFDNAKeswBM
RBLmjgM9EVbkKmEelHX9y5dreDRflF40I5/exTdvekex0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G+HLhFZvBpF5XP5xLg9Qm4zp59awYFM
C7G4V8VJ0EcrzxEy/0RyDpXCUoPUnRIBGhbq7nBde16t38/fuZLKw8HtZmpicuNM
qDQ=
=043H
-----END PGP MESSAGE-----
16 changes: 5 additions & 11 deletions src/main/java/com/amihaiemil/eoyaml/AbstractYamlMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@
import java.util.Set;

/**
* AbstractYamlMapping implementing methods which should be the same across
* AbstractYamlMapping implementing methods which should be the same across
* all final implementations of YamlMapping.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 1.0.0
*/
abstract class AbstractYamlMapping implements YamlMapping{

/**
* Return the keys' set of this mapping.
* @return Set of YamlNode keys.
*/
abstract Set<YamlNode> keys();
abstract class AbstractYamlMapping implements YamlMapping {

@Override
public int hashCode() {
Expand Down Expand Up @@ -78,15 +72,15 @@ public boolean equals(final Object other) {

/**
* Compare this Mapping to another node.<br><br>
*
*
* A Mapping is always considered greater than a Scalar or a Sequence.<br>
*
*
* If o is a Mapping, their integer lengths are compared - the one with
* the greater length is considered greater. If the lengths are equal,
* then the 2 Mappings are equal if all elements are equal (K==K and V==V).
* If the elements are not identical, the comparison of the first unequal
* elements is returned.
*
*
* @param other The other AbstractNode.
* @checkstyle NestedIfDepth (100 lines)
* @checkstyle ExecutableStatementCount (100 lines)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ private YamlNode nodeValue(final YamlNode key, final boolean map) {
value = new ReadYamlSequence(
this.lines.nested(colonLine)
);
}
}
}
}
}
return value;
}

@Override
Set<YamlNode> keys() {
public Set<YamlNode> keys() {
final Set<YamlNode> keys = new HashSet<>();
for (final YamlLine line : this.lines) {
final String trimmed = line.trimmed();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public String indent(final int indentation) {
print.append(value.toString()).append("\n");
} else {
print
.append("\n")
.append("\n")
.append(value.indent(indentation + 2))
.append("\n");
}
Expand All @@ -157,7 +157,7 @@ public String indent(final int indentation) {
}

@Override
Set<YamlNode> keys() {
public Set<YamlNode> keys() {
final Set<YamlNode> keys = new HashSet<>();
keys.addAll(this.mappings.keySet());
return keys;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/eoyaml/StrictYamlMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public String indent(final int indentation) {
}

@Override
Set<YamlNode> keys() {
public Set<YamlNode> keys() {
return this.decorated.keys();
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/amihaiemil/eoyaml/YamlMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/
package com.amihaiemil.eoyaml;

import java.util.Set;

/**
* A Yaml mapping.
* @author Mihai Andronache (amihaiemil@gmail.com)
Expand Down Expand Up @@ -82,4 +84,10 @@ public interface YamlMapping extends YamlNode {
* to a scalar.
*/
String string(final YamlNode key);

/**
* Return the keys' set of this mapping.
* @return Set of YamlNode keys.
*/
Set<YamlNode> keys();
}
40 changes: 36 additions & 4 deletions src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -65,7 +66,38 @@ public void returnsYamlMappingWithStringKey(){
second.string("fifth"), Matchers.equalTo("values")
);
}


/**
* ReadYamlMapping can return its keys.
*/
@Test
public void returnsKeys(){
final List<YamlLine> lines = new ArrayList<>();
lines.add(new RtYamlLine("first: somethingElse", 0));
lines.add(new RtYamlLine("second: ", 1));
lines.add(new RtYamlLine(" fourth: some", 2));
lines.add(new RtYamlLine(" fifth: values", 3));
lines.add(new RtYamlLine("third: something", 4));
final YamlMapping map = new ReadYamlMapping(new RtYamlLines(lines));
final Set<YamlNode> keys = map.keys();
MatcherAssert.assertThat(
keys, Matchers.not(Matchers.emptyIterable())
);
MatcherAssert.assertThat(keys.size(), Matchers.equalTo(3));
MatcherAssert.assertThat(
keys.contains(new Scalar("first")),
Matchers.is(Boolean.TRUE)
);
MatcherAssert.assertThat(
keys.contains(new Scalar("second")),
Matchers.is(Boolean.TRUE)
);
MatcherAssert.assertThat(
keys.contains(new Scalar("third")),
Matchers.is(Boolean.TRUE)
);
}

/**
* ReadYamlMapping can return the YamlMapping mapped to a
* YamlMapping key.
Expand Down Expand Up @@ -112,7 +144,7 @@ public void returnsYamlSequenceWithStringKey(){
second, Matchers.instanceOf(YamlSequence.class)
);
}

/**
* ReadYamlMapping can return the YamlMapping mapped to a
* YamlMapping key.
Expand All @@ -133,7 +165,7 @@ public void returnsStringWithYamlMappingKey(){
MatcherAssert.assertThat(value, Matchers.notNullValue());
MatcherAssert.assertThat(value, Matchers.equalTo("value"));
}

/**
* ReadYamlMapping can return the String mapped to a
* String key.
Expand All @@ -153,7 +185,7 @@ public void returnsStringWithStringKey(){
third, Matchers.equalTo("something")
);
}

/**
* An empty ReadYamlMapping can be printed.
* @throws Exception if something goes wrong
Expand Down
39 changes: 28 additions & 11 deletions src/test/java/com/amihaiemil/eoyaml/RtYamlMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,30 @@ public void fetchesChildren() {
mappings.put(new Scalar("key1"), Mockito.mock(YamlNode.class));
mappings.put(new Scalar("key2"), Mockito.mock(YamlNode.class));
mappings.put(new Scalar("key3"), Mockito.mock(YamlNode.class));
RtYamlMapping map = new RtYamlMapping(mappings);
YamlMapping map = new RtYamlMapping(mappings);
MatcherAssert.assertThat(
map.children(), Matchers.not(Matchers.emptyIterable())
);
MatcherAssert.assertThat(map.children().size(), Matchers.equalTo(3));
}

/**
* RtYamlMapping can fetch its keys.
*/
@Test
public void fetchesKeys() {
Map<YamlNode, YamlNode> mappings = new HashMap<>();
mappings.put(new Scalar("key1"), Mockito.mock(YamlNode.class));
mappings.put(new Scalar("key2"), Mockito.mock(YamlNode.class));
mappings.put(new Scalar("key3"), Mockito.mock(YamlNode.class));
YamlMapping map = new RtYamlMapping(mappings);
MatcherAssert.assertThat(
map.keys(), Matchers.not(Matchers.emptyIterable())
);
MatcherAssert.assertThat(map.keys().size(), Matchers.equalTo(3));

}

/**
* RtYamlMapping is ordered by keys.
*/
Expand Down Expand Up @@ -105,7 +122,7 @@ public void returnsYamlScalarAsString() {
mappings.put(key, new Scalar(value));
mappings.put(new Scalar("key1"), Mockito.mock(YamlMapping.class));
RtYamlMapping map = new RtYamlMapping(mappings);

MatcherAssert.assertThat(
map.string("key2"), Matchers.equalTo(value)
);
Expand All @@ -123,7 +140,7 @@ public void returnsYamlMapping() {
mappings.put(new Scalar("key3"), Mockito.mock(YamlSequence.class));
mappings.put(new Scalar("key1"), Mockito.mock(YamlMapping.class));
RtYamlMapping map = new RtYamlMapping(mappings);

MatcherAssert.assertThat(
map.yamlMapping("key1"), Matchers.notNullValue()
);
Expand Down Expand Up @@ -165,9 +182,9 @@ public void returnsNullOnMissingKey() {
map.yamlSequence("key1"), Matchers.nullValue()
);
}

/**
* RtYamlMapping can compare itself to a Scalar.
* RtYamlMapping can compare itself to a Scalar.
*/
@Test
public void comparesToScalar() {
Expand Down Expand Up @@ -195,7 +212,7 @@ public void comparesToSequence() {
Matchers.greaterThan(0)
);
}

/**
* RtYamlMapping can compare itself to a Mapping.
*/
Expand All @@ -218,7 +235,7 @@ public void comparesToMapping() {
othermappings.put(new Scalar("dev"), firstmap);
othermappings.put(new Scalar("tester"), secondmap);
YamlMapping fourthmap = new RtYamlMapping(othermappings);

MatcherAssert.assertThat(
firstmap.compareTo(firstmap), Matchers.equalTo(0)
);
Expand Down Expand Up @@ -261,7 +278,7 @@ public void prettyPrintsSimpleYaml() throws Exception {
String expected = this.readTestResource("simpleMapping.yml");
MatcherAssert.assertThat(yaml.toString(), Matchers.equalTo(expected));
}

/**
* A complex YamlMapping can be pretty printed.
* @throws Exception if something goes wrong
Expand Down Expand Up @@ -299,11 +316,11 @@ public void prettyPrintsComplexYaml() throws Exception {
* @throws Exception if something goes wrong
*/
@Test
public void printsEmptyYaml() throws Exception {
public void printsEmptyYaml() throws Exception {
YamlMapping yaml = Yaml.createYamlMappingBuilder().build();
MatcherAssert.assertThat(yaml.toString(), Matchers.isEmptyString());
}

/**
* Read a test resource file's contents.
* @param fileName File to read.
Expand All @@ -317,7 +334,7 @@ private String readTestResource(final String fileName)
IOUtils.toByteArray(
new FileInputStream(
new File("src/test/resources/" + fileName)
)
)
)
);
}
Expand Down
18 changes: 17 additions & 1 deletion src/test/java/com/amihaiemil/eoyaml/StrictYamlMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,23 @@ public void fetchesChildren() {
);
MatcherAssert.assertThat(map.children().size(), Matchers.equalTo(3));
}


/**
* StrictYamlMapping can fetch its keys.
*/
@Test
public void fetchesKeys() {
Map<YamlNode, YamlNode> mappings = new HashMap<>();
mappings.put(new Scalar("key1"), Mockito.mock(YamlNode.class));
mappings.put(new Scalar("key2"), Mockito.mock(YamlNode.class));
mappings.put(new Scalar("key3"), Mockito.mock(YamlNode.class));
YamlMapping map = new StrictYamlMapping(new RtYamlMapping(mappings));
MatcherAssert.assertThat(
map.keys(), Matchers.not(Matchers.emptyIterable())
);
MatcherAssert.assertThat(map.keys().size(), Matchers.equalTo(3));
}

/**
* StringYamlMapping can throw YamlNodeNotFoundException
* when the demanded YamlMapping is not found.
Expand Down

0 comments on commit 3f367ab

Please sign in to comment.