use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testNullMapKey.
@Test
void testNullMapKey() {
final ConfigurationNode node = CommentedConfigurationNode.root();
final Map<String, String> map = Collections.singletonMap(null, "v");
final List<Object> list = Arrays.asList("e", map);
node.node("foo").raw("bar");
node.node("l").raw(list);
assertThrows(IllegalArgumentException.class, () -> ConfigurateTranslator.instance().translate(node));
}
use of org.spongepowered.configurate.ConfigurationNode 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.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testEmptyNodeToData.
@Test
void testEmptyNodeToData() {
final ConfigurationNode source = BasicConfigurationNode.root();
final DataContainer container = ConfigurateTranslator.instance().translate(source);
assertTrue(container.isEmpty());
}
use of org.spongepowered.configurate.ConfigurationNode 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());
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testRespawnLocationData.
@Test
void testRespawnLocationData() throws IOException {
final Map<ResourceKey, RespawnLocation> m = new HashMap<>();
for (int i = 0; i < 5; i++) {
final ResourceKey key = ResourceKey.sponge("overworld" + i);
final RespawnLocation loc = RespawnLocation.builder().world(key).position(Vector3d.ZERO).build();
m.put(key, loc);
}
final DataContainer container = DataContainer.createNew().set(DataQuery.of("respawn_locations"), m);
final ConfigurationNode node = ConfigurateTranslator.instance().translate(container);
final DataContainer dc = ConfigurateTranslator.instance().translate(node);
assertEquals(container, dc);
}
Aggregations