use of org.spongepowered.api.data.persistence.DataView in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testNodeToData.
@Test
void testNodeToData() {
final ConfigurationNode node = BasicConfigurationNode.root();
node.node("foo", "int").raw(1);
node.node("foo", "double").raw(10.0D);
node.node("foo", "long").raw(Long.MAX_VALUE);
final List<String> stringList = Lists.newArrayList();
for (int i = 0; i < 100; i++) {
stringList.add("String" + i);
}
node.node("foo", "stringList").raw(stringList);
final List<SimpleData> dataList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
dataList.add(new SimpleData(i, 10.0 + i, "String" + i, Collections.emptyList()));
}
node.node("foo", "nested", "Data").raw(dataList);
final DataContainer manual = DataContainer.createNew();
manual.set(DataQuery.of("foo", "int"), 1).set(DataQuery.of("foo", "double"), 10.0D).set(DataQuery.of("foo", "long"), Long.MAX_VALUE).set(DataQuery.of("foo", "stringList"), stringList).set(DataQuery.of("foo", "nested", "Data"), dataList);
final DataView container = ConfigurateTranslator.instance().translate(node);
assertEquals(manual, container);
ConfigurateTranslator.instance().translate(container);
// assertEquals(node, translated); // TODO Test is broken, depends on quite a bit of init
}
use of org.spongepowered.api.data.persistence.DataView in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testNonRootNodeToData.
@Test
void testNonRootNodeToData() {
final ConfigurationNode root = CommentedConfigurationNode.root(n -> {
n.node("test").act(c -> {
c.node("child").raw("hello");
c.node("other").raw("world");
});
});
final DataView view = ConfigurateTranslator.instance().translate(root.node("test"));
assertEquals("hello", view.getString(DataQuery.of("child")).get());
assertEquals("world", view.getString(DataQuery.of("other")).get());
ConfigurateTranslator.instance().translateDataToNode(root.node("test2"), view);
assertEquals(root.node("test").raw(), root.node("test2").raw());
}
Aggregations