use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class DuplicateRemovalVisitorTest method testEqualListCleared.
@Test
void testEqualListCleared() {
final ConfigurationNode parent = BasicConfigurationNode.root(n -> {
n.appendListNode().raw("one");
n.appendListNode().raw("two");
n.appendListNode().act(c -> {
c.node("zombie").raw(false);
c.node("villager").raw(false);
c.node("cat").raw(true);
c.node("ocelot").raw(true);
});
n.appendListNode().raw("blue");
});
final ConfigurationNode child = BasicConfigurationNode.root(n -> {
n.appendListNode().raw("one");
n.appendListNode().raw("two");
n.appendListNode().act(c -> {
c.node("zombie").raw(false);
c.node("villager").raw(false);
c.node("cat").raw(true);
c.node("ocelot").raw(true);
});
n.appendListNode().raw("blue");
});
DuplicateRemovalVisitor.visit(child, parent);
assertTrue(child.empty());
assertNull(child.raw());
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class DuplicateRemovalVisitorTest method testEmptyMapsPreservedInList.
@Test
void testEmptyMapsPreservedInList() {
final ConfigurationNode parent = BasicConfigurationNode.root(n -> {
n.appendListNode().raw("one");
n.appendListNode().raw("two");
n.appendListNode().act(c -> {
c.node("zombie").raw(false);
c.node("villager").raw(false);
c.node("cat").raw(true);
c.node("ocelot").raw(true);
});
n.appendListNode().raw("blue");
});
final ConfigurationNode child = BasicConfigurationNode.root(n -> {
n.appendListNode().raw("one");
n.appendListNode().raw("two");
n.appendListNode().act(c -> {
c.node("zombie").raw(false);
c.node("villager").raw(false);
c.node("cat").raw(true);
c.node("ocelot").raw(true);
});
n.appendListNode().raw("green");
});
DuplicateRemovalVisitor.visit(child, parent);
final ConfigurationNode expected = BasicConfigurationNode.root(n -> {
n.appendListNode().raw("one");
n.appendListNode().raw("two");
n.appendListNode().raw(ImmutableMap.of());
n.appendListNode().raw("green");
});
assertEquals(expected, child);
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class TimingsExport method serializeConfigNode.
private static JsonElement serializeConfigNode(final ConfigurationNode node) {
if (node.isMap()) {
final JsonObject object = new JsonObject();
for (final Entry<Object, ? extends ConfigurationNode> entry : node.childrenMap().entrySet()) {
final String fullPath = TimingsExport.CONFIG_PATH_JOINER.join(entry.getValue().path());
if (fullPath.equals("sponge.sql") || TimingsManager.hiddenConfigs.contains(fullPath)) {
continue;
}
object.add(entry.getKey().toString(), TimingsExport.serializeConfigNode(entry.getValue()));
}
return object;
}
if (node.isList()) {
final JsonArray array = new JsonArray();
for (final ConfigurationNode child : node.childrenList()) {
array.add(TimingsExport.serializeConfigNode(child));
}
return array;
}
return JSONUtil.toJsonElement(node.raw());
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testTypesAreCoerced.
@Test
void testTypesAreCoerced() {
final DataContainer source = DataContainer.createNew();
source.set(DataQuery.of("i'm a short"), (short) 5);
final ConfigurationNode destination = BasicConfigurationNode.root(ConfigurationOptions.defaults().nativeTypes(Collections.singleton(Integer.class)));
ConfigurateTranslator.instance().translateDataToNode(destination, source);
assertEquals(5, destination.node("i'm a short").raw());
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testMapInsideList.
@Test
void testMapInsideList() throws IOException {
final JsonDataFormat json = new JsonDataFormat();
final ConfigurationNode node = CommentedConfigurationNode.root();
final Map<String, String> map = Collections.singletonMap("mkey", "mvalue");
final List<Object> list = Arrays.asList("lelement", map);
node.node("foo").raw("bar");
node.node("l").raw(list);
final DataContainer jc = json.read("{\"foo\":\"bar\",\"l\":[\"lelement\",{\"mkey\":\"mvalue\"}]}");
final DataContainer hc = ConfigurateTranslator.instance().translate(node);
assertEquals(jc.getMap(DataQuery.of()), hc.getMap(DataQuery.of()));
}
Aggregations